开发者

Win32 GUI: dialog in dialog

开发者 https://www.devze.com 2022-12-19 17:47 出处:网络
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)?

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开发者_JAVA技巧' to "container" control?


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消