tags:

views:

180

answers:

2

Hello,

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?

A: 

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.

RED SOFT ADAIR
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.
Lars Kanto
Never mind, I just read somewhere that if the dialog is defined in resource file I can use CreateDialog().
Lars Kanto
+1  A: 

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

Roel