3

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?

2
  • 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. Commented Feb 11, 2010 at 15:22
  • 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? Commented Feb 12, 2010 at 3:48

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

3 Comments

Just one question: why have you used CreateDialogIndirect(), instead of CreateDialog()? I mean, with the later one you could directly link to the .rc file and according to the docs they have the same functionality.
Never mind, I just read somewhere that if the dialog is defined in resource file I can use CreateDialog().
You may want to set the WS_EX_CONTROLPARENT EX style bit on the inner dialog (in the .rc template), to ensure that you can tab seamlessly between controls on the inner and outer dialogs.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.