带有模板和挂钩的 Windows API GetOpenFileName
我尝试使用带有 GetOpenFileName 的模板但没有成功。我在 MSDN 或网络上发现关于这个主题的信息很少。我的尝试基于我在这里看到的
http://visual- c.itags.org/visual-c-c++/77687/
我的代码如下。 TEMPLATE 注释显示了我在模板尝试中对代码 b4 进行的更改;主要是去除某些线条。显示正常的 Windows 资源管理器类型打开的窗口,但没有我希望使用模板进行的添加。我完全不确定挂钩函数中应该包含什么,但我知道它不会被调用,因为我在那里设置了断点。
// 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_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
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_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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须OR OPENFILENAME 标志使用
|
,而不是<代码>||You must OR the OPENFILENAME flags with
|
, not||