自定义Win32的“保存文件"对话框 [英] Customizing Win32's Save File Dialog

查看:258
本文介绍了自定义Win32的“保存文件"对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用GetSaveFileName保存文件,并且希望在我的保存文件"对话框的底部有几个额外的弹出窗口,以允许用户指定其他选项.我正在尝试遵循 MSDN文档 a>(特别是资源管理器样式的自定义),但似乎无法显示我的自定义项目.我相信在接到OFNHookProc的呼叫时,我会正确设置OPENFILENAME结构.据我所知,应该在WM_INITDIALOG消息中创建子控件,这就是我正在做的事情:

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);
}

对于WM_INITDIALOG消息,我还从我的OFNHookProc返回1,对于其他所有消息,返回0.

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?

推荐答案

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

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);

这篇关于自定义Win32的“保存文件"对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆