Article ID: 130758
Article Last Modified on 7/11/2005
// Fill in the OPENFILENAME structure to support
// a hook and a template (optional).
OpenFileName.lStructSize = sizeof(OPENFILENAME);
OpenFileName.hwndOwner = hWnd;
OpenFileName.hInstance = g_hInst;
...
...
...
...
OpenFileName.lpfnHook = ComDlg32HkProc;
OpenFileName.lpTemplateName = NULL;
OpenFileName.Flags = OFN_SHOWHELP |
OFN_EXPLORER | OFN_ENABLE_HOOK;
Note that the lpTemplateName parameter is set to NULL. To just install a
hook, one does not need a custom template. The hook function will get
called if it is sepcified in the structure.
BOOL CALLBACK ComDlg32HkProc(HWND hDlg,
UINT uMsg,
WPARAM wParam,
LPARAM lPar
{
HWND hWndParent;
HICON hIcon;
switch (uMsg)
{
case WM_INITDIALOG:
hWndParent = GetParent(hDlg);
hIcon = LoadIcon(g_hInst, "CustomIcon");
SendMessage(hWndParent,
WM_SETICON,
(WPARAM)(BOOL)FALSE,
(LPARAM)(HICON)hIcon);
return TRUE;
break;
default:
break;
}
NOTE: This code calls GetParent() to get the actual window handle of the
common dialog box. This is done for the FileOpen and SaveAs dialog boxes
only. These dialogs, when created with the OFN_EXPLORER look with a hook
and a template (optional), create a seperate dialog to hold all the
controls. This is the dialog handle that is passed in the hook function.
The parent of this dialog is the main common dialog window, whose caption
icon must be modified. The FileOpen and SaveAs dialog boxes with the old
style (no OFN_EXPLORER) need not call GetParent().
Additional query words: user common dialog
Keywords: kbhowto kbcmndlgfileo kbcmndlg kbcmndlgsave KB130758