|
federico.strati wrote: you have just to assume what you would do in the first place, like an "I wouldn't do that,
wouldn't I?" ...
As David, pointed out, I assume what would do the average poster of this forum (unless I know him very well).
federico.strati wrote: Oh well, I just know I'll end up as always writing my own little app exploring all available options of the CTreeCtrl just for fun in learning...
By chance you've just found yourself the best route.
Si figuri...
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]
|
|
|
|
|
|
federico.strati wrote: but I did already my bit in searching the articles first...
How were we to know?
federico.strati wrote: neededless to say, giving an answer in search form is a bit pointless
Unless you consider that most folks that visit the C++ forums have NOT done an initial search. They would rather spend more time creating a CP profile and typing in an incoherent question than they would by just Googling. Lazy does not begin to describe some of the ones here. Given that your profile indicates you are indeed an educated person, you probably should have prefaced your post with what you had already tried. That would help to set you apart from the others.
"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
|
|
|
|
|
I cannot find a way to force an OpenFileDialog under Windows 7, Visual Studio 2010 C++ to always open the a folder of my choosing. The documentation for OPENFILENAME structure states for Windows 7 "If lpstrInitialDir has the same value as was passed the first time the application used an Open or Save As dialog box, the path most recently selected by the user is used as the initial directory."
I cannot find a way to override this - I have a set directory I always want to open to no matter what.
Of course I am always setting lpstrInitialDir to that folder. That works the first time, but as it says above, next time it opens to the last folder the user selected.
I saw a few C#, .NET flags in other posts to change this, but nothing I can find for MFC/C++.
Any ideas appreciated! TIA
|
|
|
|
|
Does it behave the same way also if you set lpstrInitialDir to NULL and pass the path in lpstrFile?
> The problem with computers is that they do what you tell them to do and not what you want them to do. <
> Leela: Fry, you're wasting your life sitting in front of that TV. You need to get out and see the real world.
Fry: But this is HDTV. It's got better resolution than the real world <
|
|
|
|
|
lpstrInitialDir is not supported starting from Vista.
As Code-o-mat said, you can copy the folder to be initially shown in lpstrFile .
An important point to note is that the path must have a trailing back slash.
|
|
|
|
|
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
|
|
|
|