带有模板和挂钩的 Windows API GetOpenFileName

发布于 2024-09-16 14:25:26 字数 2295 浏览 1 评论 0原文

我尝试使用带有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梨涡 2024-09-23 14:25:26

您必须OR OPENFILENAME 标志使用|,而不是<代码>||

You must OR the OPENFILENAME flags with |, not ||

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文