views:

484

answers:

3

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  A: 

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);
Remy Lebeau - TeamB
+1  A: 

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

Anders
+1  A: 

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,

RED SOFT ADAIR