Customizing Win32's Save File Dialog

旧时模样 提交于 2019-12-30 12:51:11

问题


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?


回答1:


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



回答2:


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




回答3:


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,



来源:https://stackoverflow.com/questions/1429266/customizing-win32s-save-file-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!