Customizing Win32's Save File Dialog

2019-02-20 05:22发布

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?

3条回答
一纸荒年 Trace。
2楼-- · 2019-02-20 05:36

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,

查看更多
Root(大扎)
3楼-- · 2019-02-20 05:38

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

查看更多
萌系小妹纸
4楼-- · 2019-02-20 05:54

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);
查看更多
登录 后发表回答