Windows API GetOpenFileName with template and hook
I'm trying to use a template with GetOpenFileName without success. I've found very little on this topic in the MSDN or on the web. I've based my attempt on what I saw here
http://visual-c.itags.org/visual-c-c++/77687/
My code follows. The TEMPLATE comments show where I made changes to code b4 the template attempt; mainly to remove certain lines. The normal Windows explorer type open windows is displayed but without the additions I wish to make with the template. I'm not at all sure what should be in the hook function but I know it does not get called since I set a break point there.
// Global variable
OPENFILENAME IFN;
// In WndProc
case WM_CREATE:
IFN.hInstance = ((LPCREATESTRUCT)lParam)->hInstance; // TEMPLATE
IFN.hwndOwner = hWnd; // TEMPLATE
break;
// In WndProc menu processing
case IDM_INPUT_FILE:
{
// OPENFILENAME IFN; // TEMPLATE
strcpy (szFile,"NEWEXPORT.GED");
IFN.lStructSize = sizeof(IFN);
// IFN.hwndOwner = hWnd; // TEMPLATE
// IFN.hInstance = NULL; // TEMPLATE
IFN.lpstrFilter = "All\0*.*\0GEDCOM\0*.GED\0";
IFN.nFilterIndex = 2;
IFN.lpstrCustomFilter = NULL;
IFN.lpstrFile = szFile;
IFN.nMaxFile = 510;
IFN.lpstrFileTitle = NULL;
IFN.lpstrInitialDir = NULL;
IFN.lpstrTitle = NULL;
IFN.Flags = OFN_FILEMUSTEXIST || OFN_PATHMUSTEXIST || OFN_EXPLORER || OFN开发者_如何学Go_ENABLETEMPLATE || OFN_ENABLEHOOK ; // TEMPLATE
IFN.lpstrDefExt = NULL;
IFN.lpfnHook = FileAddOn; // TEMPLATE NULL;
IFN.lpTemplateName = MAKEINTRESOURCE(IDD_FILEADDON); // TEMPLATE
if (!GetOpenFileName(&IFN))
{
Beep (1000,500);
break;
}
// **************** Hook function
UINT_PTR CALLBACK FileAddOn (HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
return TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
break;
}
return TRUE;
}
// IDD_FILEADDON was made with the visual C dialog editor and has the following properties
// Style=Child, Border=none,clip siblings,3D look
You must OR the OPENFILENAME flags with |
, not ||
精彩评论