Hi All,
I have this awful hack to a problem and I am back trying to find a
good solution. Here's the situation...
I have a DLL (plug-in) that creates modal dialogs when a user clicks
on a button. For example, it may call GetOpenFileName(). The dialog
displays and works fine. The problem is that if the user clicks in the
background on the host app, they can't get back to the dialog. The
dialog is visible, but doesn't respond to any clicks, and neither does
the host app. However, it has not crashed. If I hit the windows key
and jump between applications I can eventually get the dialog back to
an active state.
I feel like I have exhausted all my knowledge about dialogs and
messages to fix this. Maybe there is a trick someone knows? My work-
around (and it is awful) is to minimize the host application while my
dialog is active. This works but does not provide the nice smooth
feeling of an integrated, professional tool.
I have tried disabling/enabling the host app. I have tried catching
all sorts of WM messages in my hook proc and setting
SetForegroundWindow(hDlg).
Here are snippets of my code, which I think is pretty basic:
<CODE>
// OpenFileDialog
bool File::OpenFileDialog() {
OPENFILENAME fileName;
char szFile[MAX_PATH];
char CurrentDir[MAX_PATH];
szFile[0] = 0;
GetCurrentDirectory(MAX_PATH, CurrentDir);
fileName.lStructSize = sizeof(OPENFILENAME);
fileName.hwndOwner = NULL;
fileName.lpstrFilter = "Text Files\0*.TXT;*.*\0\0";
fileName.lpstrCustomFilter = NULL;
fileName.nMaxCustFilter = 0;
fileName.nFilterIndex = 0;
fileName.lpstrFile = szFile;
fileName.nMaxFile = MAX_PATH;
fileName.lpstrFileTitle = NULL;
fileName.nMaxFileTitle = 0;
fileName.lpstrInitialDir = CurrentDir;
fileName.lpstrTitle = "Open Settings File";
fileName.nFileOffset = 0;
fileName.nFileExtension = 0;
fileName.lpstrDefExt = NULL;
fileName.lCustData = 0;
fileName.lpTemplateName = NULL;
fileName.lpfnHook = FileDialogHookProc;
fileName.Flags = OFN_EXPLORER|OFN_ENABLEHOOK;
if(GetOpenFileName(&fileName)){
mPath = szFile;
OpenRead();
return _isOpen;
}
return false;
}
// A hook to center the window
UINT CALLBACK FileDialogHookProc(HWND hDlg, UINT message, WPARAM
wParam, LPARAM lParam) {
switch (message) {
case WM_INITDIALOG: {//WM_INITDIALOG
RECT r1, r2;
POINT pt;
HWND hWnd = GetParent(hDlg);
GetWindowRect(GetDesktopWindow(), &r1);
GetWindowRect(hWnd, &r2);
pt.x = (r1.right - r1.left)/2 - (r2.right - r2.left)/2;
pt.y = (r1.bottom - r1.top)/2 - (r2.bottom - r2.top)/2;
//SetWindowPos(hDlg, HWND_TOP, pt.x, pt.y, r2.right-r2.left,
r2.bottom-r2.top, SWP_NOSIZE);
MoveWindow(hWnd, pt.x, pt.y, r2.right-r2.left, r2.bottom-r2.top,
false);
//MessageBox(0,"MESSAGE:
WM_INITDIALOG.","MESSAGE",MB_ICONINFORMATION);
SetForegroundWindow(hDlg);
SetCapture(hDlg);
break;
}
}
return 0; // allow the default proc to execute
}
// And finally here is the snippet of code that responds to a user
click to invoke the dialog:
HWND window = GetActiveWindow();
//this is my hack (which I would like to do away with)
ShowWindow(window, SW_FORCEMINIMIZE);
EnableWindow(window, false);// this btw seems to have no effect
File file;// this is a custom class object
file.OpenFileDialog();
ShowWindow(window, SW_SHOWNORMAL);
EnableWindow(window, true);
</CODE>
I really appreciate any advice anyone has.
Thanks for taking the time to read this.
Walker