I have made the template and the hook, and they work very well!
But I don't know how I should do to make the button change the folder.
There is a lot of messages to query the openfiledialog, but very few
where you could set a value.
One way, mayby not the most beautiful one, would be to set the text in
the editbox where the user should enter the name of the file he wants
to open, and then simulate a click on the Open button. That will make
the openfiledialog to change folder, but I don't manage to simulate a
mouseclick on the open button!
Any suggestions?
Im using Visual Studio 6, and Im writing in plain C for W2K / NT
Thanks
// Marcus
Here's a copy of an answer I posted nearly a year ago...
What I do is to read the contents of 'edt1' (the edit control containing the
default filename), replace it with the directory name which I want to be
displayed in the list box, simulate a click on the OK button, and then stick
the original text back in the 'edt1' control.
The code could look something like this:
void ChangeDir(HWND wOfn,TCHAR *NewDir)
{
TCHAR s[MAX_PATH];
/* backup contents of 'edt1' */
GetDlgItemText(wOfn,edt1,s,MAX_PATH);
/* replace with the directory name */
SendMessage(wOfn,CDM_SETCONTROLTEXT,edt1,(LPARAM)NewDir);
/* click on the OK button */
SendMessage(wOfn,WM_COMMAND,IDOK,0);
/* restore contents of 'edt1' */
SendMessage(wOfn,CDM_SETCONTROLTEXT,edt1,(LPARAM)s);
}
UINT CALLBACK OpenHookProc(HWND w,UINT msg,WPARAM wParam,LPARAM lParam)
{
int r=0;
switch(msg)
{
case WM_INITDIALOG:
/* call this from wherever is suitable, only here for an example */
ChangeDir(GetParent(w),TEXT("D:\\bbb"));
r=1;
break;
case CDN_INITDONE:
r=1;
break;
/* ... */
}
return r;
}
Damian