3
votes

I just started to use dialogs and I really like the possibility to define the layout in resource file. But is it possible to set up one dialog and embed it into another (i.e., no floating dialogs)?

With plain windows, I created the main window with one child window. Then, I created even more windows (like "edit", "static", ...) and added them to the child. I did so in order to group those several windows in to one window so I can control, say, the visibility of all edits and statics easily. Kind of like grouping (but it doesn't have the border of GroupBox).

Is it possible to rewrite the above, but with dialogs written down in .rc file?

I'm using plain C and Win32.

Example of what I did:

main = CreateWindow(...);
container = CreateWindow(... hWndParent = main ...);
label = CreateWindow("static", ... container);
edit = CreateWindow("edit", ... container);

Now, if I can hide or resize both label and edit just but controlling container.

Example of what I would like to have:

MAIN_DIALOG DIALOG 10, 20, 30, 40 STYLE ...
BEGIN
CONTROL "container" ...
END

How do I add 'label' and 'edit' to "container" control?

3
I'm not sure I understand your question, but you could create a modeless dialog box with CreateDialog() and embed your controls within this dialog in your resource file.anno
Suppose I have dialog-based app. If I created that modeless dialog you mentioned is it possible to embed it into my app? I mean, is it possible to create a dialog which has for the parent another dialog?Lars Kanto

3 Answers

3
votes

Also, in the resource editor set the dialog style to 'child' and border to 'none'.

2
votes

What you want to do is probably a little bit similar to tabbed dialogs. There some controls are embedded from separate resources with a outer dialog. You can then show/hide all the controls within a tab by calling ShowWindow just for the subdialog:

In you main dialog Callback add something like

HWND SubDlgHwnd; // Global or probably within a struct/array etc.

case WM_INITDIALOG:
{
    HRSRC       hrsrc;
    HGLOBAL     hglobal;
    hrsrc = FindResource(sghInstance, MAKEINTRESOURCE(SubDlgResId), RT_DIALOG);

    hglobal = ::LoadResource(sghInstance, hrsrc);

    SubDlgHwnd = CreateDialogIndirect(sghInstance, (LPCDLGTEMPLATE)hglobal, hDlg, ChildDialogCallback); 
    SetWindowPos(SubDlgHwnd, HWND_TOP, x, y, 0, 0, SWP_NOSIZE); 
    break;
}

case WM_COMMAND:
{
    ...
    if(UpdateVisibility)
        ShowWindow(SubDlgHwnd, showSubDialog ? SW_SHOW : SW_HIDE);
}

This might be a good Startpoint for Microsofts documentation.

2
votes

You also have to add DS_CONTROL style to the dialog(s) you want to embed. Without it embedded dialog window will be shown with window header what is hardly one wants to.