|
Thanks, but what I have discovered is that if the Vista flag for the CFileDialog is set false, then the dialog will fail (not display and immediately return IDCANCEL) with a "bad filename" in the CommDlgExtendedError. It does not like just a directory in the lpstrFile if the Vista flag is false.
So unless there's another idea floating about, I am stuck! I have to use the old style dialog for now.
UPDATE(s): To help anyone who struggles with this:
I was not able (at first) to use the new style dialogs (vista=true) because OnInitDialog and OnInitDone are NOT supported anymore for CFileDialog. Our code did depend on this. But I found a post that suggested using OnFolderChange() instead. My tests indicate that it indeed is called before the user gets control (which was the reason for the OnInit stuff). So you might give that a try.
UPDATE2: The Superman's response is true, but I now know what the problem is: you have to have *.* or some more specific find option if you wish to set vista flag false and use lpstrFile. So, if I set the vista flag false, and use a string like "C:\\temp\\*.*" as lpstrFile, then the initial directory (C:\temp)is picked out of the full path.
Note that using the vista flag is cool as you get a preview, but in our case we have to do our own previews using a dialog template, which also is not supported after vista. So now, by using vista false, i get the OnInits, initial directory, and templates which means I can get my project done
Thanks for the help.
modified on Friday, November 5, 2010 3:55 PM
|
|
|
|
|
|
You may use the strtol[^] function.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
oops, I removed the message before seeing a reply was given.
I found a way anyhow, checking the ascii code
const char * pcField = sFileNumber.c_str();
int a = int(*pcField);
if (a >= 48 && a <= 57)
|
|
|
|
|
bad, bad programming.
Watched code never compiles.
|
|
|
|
|
ok, ok. I'll use isdigit(). I know my solution is not good looking, but, can I ask why is it bad programming?
|
|
|
|
|
Maybe not that bad. Ugly, neverthless.
Anyway you're just checking the first character of the string. Is this OK (i.e. the string will always contain at most 1 digit)?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
err... no, it may contain more than one digit. I see what you mean, it could be a character-string started by a number... Highly improbable in my application, but I should check it anyway, shouldn't I?
|
|
|
|
|
Simplest:
bool IsDigits(const std::string& str)
{
return str.empty() ? false : str.find_first_not_of("0123456789") == str.npos;
}
More efficient:
bool IsDigits(const std::string& str)
{
return str.empty() ? false : std::find_if_not(str.begin(), str.end(), isdigit) == str.end();
}
cheers,
AR
Edit: changed function name to IsDigits and added second version.
ReEdit: added empty string handling.
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
modified on Thursday, November 4, 2010 1:40 PM
|
|
|
|
|
better to use "isdigit" and related similar functions ("isalpha", "isspace", etc...)
|
|
|
|
|
hi i m using CFileDialog to open the file.
but there is one problem,
CString filter( "Text Files(*.txt)|*.txt||");
CWaitCursor cwt;
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY,filter,this,0);
if (fileDlg.DoModal () == IDCANCEL)
{
return;
}
CString OpenFile = fileDlg.GetPathName ();
SetDlgItemText(IDC_PATH,OpenFile);
i want to open only .txt files,so i provide .txt format in filter.
but i open the dialog box and enter file name with some other extension its display and open.
i want as the list of CFileDialog not display the oher extension file same as its not open the other extension file from File Name field .
please help me for this.
thanks in advance.
|
|
|
|
|
AFAIK, user can type in any name and the file dialog will accept it, you can detect that by deriving your own class from CFileDialog and override some of the members (see the documentation)
Originally, hook ing was the proper method; but now override is the way to go.
Watched code never compiles.
|
|
|
|
|
|
Have you considered something like:
CFileDialog fileDlg(TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, _T("Text Files(*.txt)|*.txt||"), this);
do
{
if (fileDlg.DoModal () == IDCANCEL)
return;
} while (fileDlg.GetFileExt() != _T("txt"));
SetDlgItemText(IDC_PATH, fileDlg.GetPathName());
[edit]
Alain's suggestion is a much better solution.
[/edit]
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
modified on Thursday, November 4, 2010 11:25 AM
|
|
|
|
|
Hi,
For custom file name validation derive from CFileDialog and override CFileDialog::OnFileNameOK[^].
This function allows you to reject a filename for any application-specific reason.
cheers,
AR
When the wise (person) points at the moon the fool looks at the finger (Chinese proverb)
|
|
|
|
|
Hi all,
i m using assess database with odbc connection,and for each tabel of database i dervive the class from CRecordset.
when i m Trying to Update() the record its generate this error "string data,right truncated".
please help me how can i resolve this error.
thanks in advance.
|
|
|
|
|
I'd guess the string's longer than the column's maximum length.
Steve
|
|
|
|
|
no, field is text type and its max lenght is 255,but i always enter data less than 255
|
|
|
|
|
Le@rner wrote: please help me how can i resolve this error.
By using the debugger to step through the code, looking at the values of variables along the way.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
|
|
|
|
|
Hi All!
Probably will go better on the WinAPI section but since there is an ASM part i'm a bit confused of where to put it, and seen that i use gcc...heeelp!! :P
I'm just getting mad, i'm tryng to build a lock-free messaging system with the usage of atomic instructions. And yes i could use boost but i'll lose the interesting part of the whole thing :P
I actually work on windows (hence the Interlock...) with CodeBlocks and the gcc bundled with him on a dual core PC
I instantiated a class with
class ZTest{
public:
volatile LONG varToCheck;
}
And then i try to something like this (using a member variable of a class created with new)
ZTest *zt=new ZTest();
InterlockCompareExchange(&zt->varToCheck,DEFINE_ONE,DEFINE_TWO);
All the time, while in debug i obtain a segmentation fault... someone said that i should have not used the debug build, i then tryed with the release, removing all optimizations (just to be sure), but after 20/30 iteration over the Interlock... function everything explode...with a segmentation fault..
Reaching the limit of my wrath...i tried with assembly with the LOCK CMPXCHG instruction and... after 20/30 iteration guess what? A segmentation fault
Now, i guess something is totally worng with this, tomorrow i'll try with M$ compiler to check if it's only a gcc fault (i doubt but...)
Does someone ever tryed something like this?
Any suggestion, question and request clarification will be welcome...
Zak...ah, yes i think i'll get soon a segmentation fault myself...
|
|
|
|
|
MSDN says:[^]
The parameters for this function must be aligned on a 32-bit boundary; otherwise, the function will behave unpredictably on multiprocessor x86 systems and any non-x86 systems.
What is the value of __alignof__ (varToCheck); ?
|
|
|
|
|
Hi!
Firstly thank you for the answer! I did'nt even knew that existed this keyword!!
The variables seems aligned to 4 bytes, that is 32 bit so it should be fine, as far as i know (that is honestly really a little...).
I tried using pointer variables as member variables, allocating them (with sizeof(variable)+4)and taking an address in the mallocated area that was aligned...and everything concluded with segmentation...
There is something that i don't quite understand into this...
Thank you!
Zak
---EDIT---
Now i tryed with a snippet took from MSDN about porting from Unix... and everything works as expected...same compiler options...same everything. Even the alignement of the variables used is ok....
#include <iostream>
using namespace std;
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
class Pippo{
LONG pappa;
public:
LONG pippe;
char test;
LONG new_value;
VOID doStuff(){
printf("fuffa\r\n");
};
};
DWORD WINAPI thread_function(PVOID arg)
{
int count2;
Pippo*pipp = (Pippo*)arg;
printf("thread_function is running. %d\r\n",__alignof__(pipp->new_value));
for (count2 = 0; count2 < 1000; count2++) {
Sleep(10);
printf("(T-%d)", pipp->new_value);
InterlockedExchange(&pipp->new_value, 1);
}
Sleep(3000);
return 0;
}
int main()
{
HANDLE a_thread;
DWORD a_threadId;
DWORD thread_result;
int count1;
Pippo* pipp=new Pippo();
pipp->new_value=1;
a_thread = CreateThread(NULL, 0, thread_function, (PVOID)pipp,0, &a_threadId);
if (a_thread == NULL) {
perror("Thread creation failed");
exit(EXIT_FAILURE);
}
printf("entering loop\n");
for (count1 = 0; count1 < 10000; count1++) {
Sleep(1);
printf("(P-%d)", pipp->new_value);
InterlockedExchange(&pipp->new_value, 2);
}
printf("\nWaiting for thread to finish...\n");
if (WaitForSingleObject(a_thread, INFINITE) != WAIT_OBJECT_0) {
perror("Thread join failed");
exit(EXIT_FAILURE);
}
GetExitCodeThread(a_thread, &thread_result);
printf("\nThread joined\n");
exit(EXIT_SUCCESS);
return 0;
}
modified on Thursday, November 4, 2010 4:48 AM
|
|
|
|
|
Not really part of the thread, but I would be interested in the algorithm you're gonna use for your lock free queue... may you share a pointer to that?
|
|
|
|
|
What the !###$@#$
I was passing the class that contains the variable to use inside the interlock functions to the CreateThread function for the "child" threads, but before that i was putting them into an stl list...
For who know what reason (may be i forgot the copy constructors etc. inside the class to put into the std::list container ) the class i were getting FROM the list was "clean" as just created...with the variables for the interlock uninitialized...and then CRASH!!!!
Thank you for the suggestions...and always remember the "not so ancillary" methods...
Zal
|
|
|
|
|
This is a basic COM Compound Document or Structured Storage question.
I created an IStream within an IStorage and wrote four of these (each four bytes) to that IStream…
typedef struct tagINDEX
{
DWORD dwPlotRecord;
}INDEX;
The Storage was created like so…
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr07\\Release\\Data.dat";
IStorage* pStorage=NULL;
DWORD grfMode;
HRESULT hr;
grfMode=STGM_SIMPLE | STGM_CREATE | STGM_READWRITE | STGM_SHARE_EXCLUSIVE ;
hr=StgCreateDocfile(szFile,grfMode,0,&pStorage);
I can read those four records out of my IStream using IStream::Read() but have been unable to determine the correct byte count of the four records (each four bytes) I wrote in with IStream::Write(). Since each INDEX record is four bytes and I wrote four such records ‘in’, then I’d hope to obtain an…
IStream::Stat(STATSTG*, STATFLAG_NONAME)
…return where the STATSTG.cbSize.LowPart would equal 16. This is not what is returned to me, but rather the number 4096, which looks suspiciously to me like a sector size, which I’m further assumming was the initial memory/file allocation for the IStream.
It does not appear to me that Streams have an analogous function to the Windows Base Services GetFileSize() Api. Does anyone know anything about this? How do you get the number of bytes actually written to a Stream as opposed to the total allocation for the Stream? I'm just teaching myself COM Compound Document Storage Interfaces, and was doing rather well until I hit this problem!
I'll provide some additional information.
Here is what got written into a Simple IStream...
Now Try To Put Data In Structured Storage!
szFile = C:\Code\VStudio\VC++6\Projects\COM\CompStor\CmpStr07\Release\Data.dat
StgCreateDocFile() Succeeded!
pStorage->CreateStream(Index) Succeeded!
Will Now Try To Write Index Records To Structured Storage
dwNumPlots = 4
i idx.dwPlotRecord pcbWritten
=========================================
1 1 4
2 3 4
3 4 4
4 5 4
After having written those 16 bytes and Releasing() both pStream and pStorage, then re-opening both, that's where I ran into the difficulty. Here is a short program with output afterward showing that even S_OK is returned by reading past the original 16 byte IStream::Write()...
#include <objbase.h>
#include <stdio.h>
#include <string.h>
typedef struct tagINDEX
{
DWORD dwPlotRecord;
}INDEX;
int main(void)
{
wchar_t szFile[]=L"C:\\Code\\VStudio\\VC++6\\Projects\\COM\\CompStor\\CmpStr08\\Release\\Data.dat";
IStream* pIdxStream=NULL;
IStorage* pStorage=NULL;
char szBuffer[128];
ULONG pcbRead=0;
DWORD grfMode;
STATSTG sts;
unsigned i;
HRESULT hr;
INDEX idx;
wprintf(L"szFile = %s\n",szFile);
grfMode=STGM_SIMPLE | STGM_READ | STGM_SHARE_EXCLUSIVE;
hr=StgOpenStorage(szFile,NULL,grfMode,NULL,0,&pStorage);
if(SUCCEEDED(hr))
{
printf("StgOpenStorage() Succeeded!\n");
hr=pStorage->OpenStream(L"Index", NULL, STGM_READ | STGM_SHARE_EXCLUSIVE, 0, &pIdxStream);
if(SUCCEEDED(hr))
{
printf("pStorage->OpenStream(Index) Succeeded!\n");
hr=pIdxStream->Stat(&sts,1);
if(SUCCEEDED(hr))
{
printf("pIdxStream->Stat(&sts,1) Succeeded!\n");
printf("sts.cbSize.LowPart = %u\n",sts.cbSize.LowPart);
printf("sts.cbSize.HighPart = %u\n",sts.cbSize.HighPart);
}
printf("\ni\tpcbRead\tidx.dwPlotRecord\tHRESULT\n");
printf("===============================================\n");
for(i=1; i<=8; i++)
{
hr=pIdxStream->Read(&idx,sizeof(INDEX),&pcbRead);
switch(hr)
{
case S_OK:
strcpy(szBuffer,"S_OK");
break;
case S_FALSE:
strcpy(szBuffer,"S_FALSE");
break;
default:
strcpy(szBuffer,"Don't Know What hr Means!");
break;
}
printf("%u\t%u\t%u\t\t\t%s\n",i,pcbRead,idx.dwPlotRecord,szBuffer);
}
pIdxStream->Release();
}
pStorage->Release();
}
getchar();
return 0;
}
modified on Wednesday, November 3, 2010 4:36 PM
|
|
|
|
|