|
-
February 5th, 2002, 12:31 PM
#1
select a directory dynamically in a custom CFileDialog
Hi,
i've created a dialog based on CFileDialog.
Now i try to select automatically a directory without select it in the combobox.
Some ideas how to do ?
I know i can set the initial directory but i need to change it automatically.
Do i have to close the CFileDialog and reopen it with a new initial directory ? (it don't seem possible wihtout closing my dialog too)
Is there a better way to do it ?
Thanks for any help !
Gaëtan
Gaëtan
-
December 16th, 2003, 10:54 AM
#2
Hi,
I've the same problem, did u find a solution ?
If so, please, heeeelp !
thanks.
-
December 16th, 2003, 12:04 PM
#3
In my opinion the basic question that you have to put is WHEN DO U WANT TO CHANGE AUTOMATICALLY THE DIRECTORY ??
Remember CFileDialog is a modal box , so u cannot interfere from outside till it's closed. If u provide me this information I might have an answer for you. I'll give u shortly the idea:
- Use the EnumChildWindows() API to detect the handler (HWND), combo-box where normally u type the file/folder path. U can identify it by the content (storing the latest value).
- Identify the HWND of the Save/Open button using the same function before.
- Send to the combobox identified the message SetWindowText().
This is possible because u were identified previously the HWND of the combo.
- Send to the button Save/Open the message WM_COMMAND BN_CLICKED.
Now the list box showing the folder should modify accordingly.
Normally , when you want to modify the default behaviour of the default file dialog box, u have to provide a hook procedure and another template (see the OPENFILENAME structure for details). In my opinion that's the way u should do it.
RATE ME OR HATE ME
-
December 17th, 2003, 02:17 AM
#4
in fact, i've developed a dialog wich is inheriting from CFileDialog, and i want to add a list of default folders (like it already exists in some applications). On clicking on this list, i want to change the folder in the inherited part of CFileDialog...
Your idea is quite good, but my combo isn't displaying full path ; it's a combo which contains a tree, and the text displayed is only the current folder, so i don't think this can work (i've already tried to change current item in the combo, but not all the path are available, it should be the same with setWindow text, no ??)...
if you have any other idea ???
thanks
Arn0
-
December 17th, 2003, 07:17 AM
#5
My idea would be the following:
- In your derived class (let's call it CMyFileDialog), override the OnInitDone() method. Here u implement all the mechanism for getting the HWND of the dialog box controls that u are intrested into and store them in some member variabiles of your derived class for later use.
- Provide a hook function (see the lpfnHook member of the OPENFILENAME structure). This hook function will or should receive all the messages from the controls. Here u catch the click event on the combo box and do whatever u want ..... I mean after catching the click and insert whatever values u want in the combo u simply do not call the default dialog box procedure. I quote from MSDN:
"The default dialog box procedure processes the WM_INITDIALOG message before passing it to the hook procedure. For all other messages, the hook procedure receives the message first. Then, the return value of the hook procedure determines whether the default dialog procedure processes the message or ignores it."
The insertion mechanism (insert items in the combo), should work since u detected the HWND of the controls in the OnInitDone() function.
-
December 17th, 2003, 08:08 AM
#6
I think, u didn't understand what was my aim, or I totally don't understand your explanation....
BUT, I FOUND : to change current folder (on a button cklick for example), some messages are working : this code allows to change to path stored in strFolder,
m_nIdFileNameCombo, is th id of the dialog combo (UINT m_nIdFileNameCombo = 1152 works for me...)
void CMYFileDlg::OnBnClickedButton1()
{
CString strFolder("C:\\temp");
if (!strFolder.IsEmpty())
{
// change to new folder, leave file name control unchanged
TCHAR szText[_MAX_PATH*2];
memset(szText, 0, sizeof(szText));
GetParent()->GetDlgItem(m_nIdFileNameCombo)->SendMessage(WM_GETTEXT,
sizeof(szText)/sizeof(TCHAR)-1, (LPARAM)szText);
GetParent()->SendMessage(CDM_SETCONTROLTEXT, m_nIdFileNameCombo,
(LPARAM)(LPCTSTR)strFolder);
GetParent()->SendMessage(WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED),
(LPARAM)GetDlgItem(IDOK)->GetSafeHwnd());
GetParent()->SendMessage(CDM_SETCONTROLTEXT, m_nIdFileNameCombo,
(LPARAM)szText);
}
}
-
December 17th, 2003, 08:38 AM
#7
This looks really good. So, problem solved .
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|