自定义 Win32 的保存文件对话框

发布于 2024-08-04 15:50:05 字数 1475 浏览 3 评论 0原文

我正在尝试使用 GetSaveFileName 保存文件,并希望在保存文件对话框的底部有几个额外的弹出窗口,以允许用户指定更多选项。我正在尝试遵循 MSDN 文档 (特别是 资源管理器样式自定义< /a>)关于这个主题,但似乎无法让我的自定义项目出现。我相信当我收到对我的 OFNHookProc 的调用时,我正确设置了 OPENFILENAME 结构。据我所知,在 WM_INITDIALOG 消息期间,我应该创建子控件,这就是我正在做的事情:

HWND settings_popup =
    ::CreateWindowExW(WS_EX_CLIENTEDGE | WS_EX_NOPARENTNOTIFY,
                      L"COMBOBOX",
                      L"Settings:",
                      WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_BORDER | CBS_DROPDOWNLIST,
                      10,
                      10,
                      150,
                      30,
                      dialog, // the window parameter from the OFNHookProc
                      NULL,
                      ::GetModuleHandle(NULL),
                      NULL);

if (settings_popup)
{
    HWND parent = ::GetParent(settings_popup); // for verification
    ::ShowWindow(settings_popup, SW_SHOW);
    ::EnableWindow(settings_popup, true);
}

我还从我的 OFNHookProc 返回 1 WM_INITDIALOG 消息,0 表示其他所有内容。

在我所有让组合框显示在对话框中的尝试中,它都没有出现。为了使组合框成为我的保存文件对话框自定义的一部分,我的代码中缺少什么?

I am trying to save a file using GetSaveFileName and want to have a couple extra popups at the bottom of my save file dialog to allow the user to specify further options. I am trying to follow the MSDN documentation (specifically the Explorer-style customization) on the subject but can't seem to get my custom item to appear. I believe I set up the OPENFILENAME struct properly as I'm getting calls into my OFNHookProc. As far as I know it is during the WM_INITDIALOG message that I should be creating my subcontrols, which is what I'm doing:

HWND settings_popup =
    ::CreateWindowExW(WS_EX_CLIENTEDGE | WS_EX_NOPARENTNOTIFY,
                      L"COMBOBOX",
                      L"Settings:",
                      WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_BORDER | CBS_DROPDOWNLIST,
                      10,
                      10,
                      150,
                      30,
                      dialog, // the window parameter from the OFNHookProc
                      NULL,
                      ::GetModuleHandle(NULL),
                      NULL);

if (settings_popup)
{
    HWND parent = ::GetParent(settings_popup); // for verification
    ::ShowWindow(settings_popup, SW_SHOW);
    ::EnableWindow(settings_popup, true);
}

I also return 1 from my OFNHookProc for the WM_INITDIALOG message and 0 for everything else.

In all my attempts to get the combobox to show in the dialog, it's not coming up. What am I missing from my code to make the combobox a part of my save file dialog customization?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

傾旎 2024-08-11 15:50:05

当调用 CreateWindowEx() 创建子窗口时,需要使用 GetParent() 获取对话框的父窗口,然后使用该 HWND 作为父窗口。不要使用对话框本身作为父对话框。换句话说:

HWND settings_popup =
    ::CreateWindowExW(WS_EX_CLIENTEDGE | WS_EX_NOPARENTNOTIFY,
                      L"COMBOBOX",
                      L"Settings:",
                      WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_BORDER | CBS_DROPDOWNLIST,
                      10,
                      10,
                      150,
                      30,
                      ::GetParent(dialog),
                      NULL,
                      ::GetModuleHandle(NULL),
                      NULL);

When calling CreateWindowEx() to create your child window, you need to use GetParent() to get the parent window of the dialog, and then use that HWND as your parent window. Do not use the dialog itself as the parent. In other words:

HWND settings_popup =
    ::CreateWindowExW(WS_EX_CLIENTEDGE | WS_EX_NOPARENTNOTIFY,
                      L"COMBOBOX",
                      L"Settings:",
                      WS_CHILD | WS_CLIPSIBLINGS | WS_VSCROLL | WS_BORDER | CBS_DROPDOWNLIST,
                      10,
                      10,
                      150,
                      30,
                      ::GetParent(dialog),
                      NULL,
                      ::GetModuleHandle(NULL),
                      NULL);
贪了杯 2024-08-11 15:50:05

通常,当您将控件添加到公共对话框时,这些新控件位于对话框模板中(作为资源或在内存中)。这样 Windows 就可以处理该位置。

如果您仍然想在运行时创建控件,我想您还必须在 WM_INITDIALOGCDN_INITDONE 中调整父级的大小和位置(您的父级是内部的空对话框)主对话框)使用 WinSpy++ 之类的工具在运行时“调试”对话框

Normally when you add controls to a common dialog, those new controls are in a dialog template (as a resource or in memory). This way windows takes care of the position.

If you still want to create your controls at runtime, I'd guess you also have to resize and position your parent in WM_INITDIALOG or CDN_INITDONE (Your parent is a empty dialog inside the main dialog) Use a tool like WinSpy++ to "debug" the dialog at runtime

冷情 2024-08-11 15:50:05

将控件传递到 OPENFILENAME 结构的 lpTemplateName 参数中的单独对话框资源模板中。其工作原理非常简单可靠。它在您引用的链接中进行了描述,

Pass your controls in a separate dialog ressource template in the lpTemplateName Parameter of the OPENFILENAME structure. That works very simply and reliably. It is described in the link you refered to,

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