make Child Dialog not Popup?

This is a discussion on make Child Dialog not Popup? within the Windows Programming forums, part of the Platform Specific Boards category; Ok, i am going to ask this in a few different parts, with my tutorial code on the bottom for ...

  1. #1
    #junkie
    Join Date
    Oct 2004
    Posts
    240

    make Child Dialog not Popup?

    Ok, i am going to ask this in a few different parts, with my tutorial code on the bottom for refrence.
    Here is a bit of background on what i'm learning win32 to do .. for my current project.
    I wish to make a project with a toolbar on top, though without toying with the look/functionaility i do not know what to put in it yet. Most likely it will be Graphic Buttons, Normal Buttons, a Dropdown box, or all of them. Under that tool box i would like a dynamic dialog system. Well not so dynamic, i need to load different predefined dialogs in that depending on what the user does in the toolbox. Just like any program, i have the top bar for the users main category options, and the bottom bar for the selected option and more dialog junk in that.

    1.) How can i get my dialogs to spawn inside its parent window? Can you point me to any tutorials ect.. that explain this?

    2.) Do you know of any tutorials to take that kinda go over what i am trying to do? I am taking the forgers but unless i missed something where i'm at now he went over controls, and a dropdown box was not included, now how to make my dialog.. my main window so to say. At the moment my window is blank with a toolbar on top, and thats it. Then from the tool bar (File, options like that) i can make my dialogs popup.

    *edit
    3.) As vaguely said, it also didnt say how to make dropdown boxes. Can someone explain to me how this is done? (Example via my code would be awesome, because without either expalanation of insertion or an example, i'll prob fail atmlol)


    Ya.. im fairly confused on how to do any of what i asked, and i dont know what all to ask since it would (and is) so broad.
    Any help would be much appreciated, thanks!
    main.cpp
    Code:
    #include <windows.h>
    #include "resource.h"
    
    LRESULT     CALLBACK WindowProcedure (HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam);
    BOOL        CALLBACK AboutDlgProc (HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
    BOOL        CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
    HWND        g_hToolbar = NULL;
    
    class WinClass
    {
    public:
        WinClass (WNDPROC winProc, char const * className, HINSTANCE hInst);
        void Register ()
        {
            ::RegisterClass (&_class);
        }
    private:
        WNDCLASS _class;
    };
    
    WinClass::WinClass
        (WNDPROC winProc, char const * className, HINSTANCE hInst)
    {
        _class.style = 0;
        _class.lpfnWndProc = winProc; // window procedure: mandatory
        _class.cbClsExtra = 0;
        _class.cbWndExtra = 0;
        _class.hInstance = hInst;         // owner of the class: mandatory
        _class.hIcon = 0;
        _class.hCursor = ::LoadCursor (0, IDC_ARROW); // optional
        _class.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1); // optional
        _class.lpszMenuName = 0;
        _class.lpszClassName = className; // mandatory
    }
    class WinMaker
    {
    public:
        WinMaker (): _hwnd (0) {}
        WinMaker (char const * caption, 
                  char const * className,
                  HINSTANCE hInstance);
        void Show (int cmdShow)
        {
            ::ShowWindow (_hwnd, cmdShow);
            ::UpdateWindow (_hwnd);
        }
    protected:
        HWND _hwnd;
    };
    
    WinMaker::WinMaker (char const * caption, 
                        char const * className,
                        HINSTANCE hInstance)
    {
        _hwnd = ::CreateWindow (
            className,              // name of a registered window class
            caption,                // window caption
            WS_OVERLAPPEDWINDOW,    // window style
            CW_USEDEFAULT,          // x position
            CW_USEDEFAULT,          // y position
            300,                    // witdh
            200,                    // height
            0,                      // handle to parent window
            0,                      // handle to menu
            hInstance,              // application instance
            0);                     // window creation data
    }
    
    int WINAPI WinMain (HINSTANCE hInst, HINSTANCE hPrevInst, char * cmdParam, int cmdShow)
    {
        char className [] = "Winnie";
    
        WinClass winClass (WindowProcedure, className, hInst);
        winClass.Register ();
    
        WinMaker win ("Hello Windows!", className, hInst);
        win.Show (cmdShow);
    
        MSG  msg;
    
        while (::GetMessage (& msg, 0, 0, 0) > 0)
        {
            if(!IsDialogMessage(g_hToolbar, & msg))
            {
                ::TranslateMessage(& msg);
                ::DispatchMessage(& msg);
            }
        }
    
        return msg.wParam;
    }
    
    LRESULT CALLBACK WindowProcedure (HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
    {
        switch (message)
        {
            case WM_CREATE:
            {
                HMENU hMenu, hSubMenu;
                hMenu = CreateMenu();
    
                hSubMenu = CreatePopupMenu();
                AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit");
                AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File");
    
                hSubMenu = CreatePopupMenu();
                AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, "&Go");
                AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "&Help");
                AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT_TWO, "H&elp Two");
                AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Stuff");
    
                hSubMenu = CreatePopupMenu();
                AppendMenu(hSubMenu, MF_STRING, ID_DIALOG_HIDE, "&Hide");
                AppendMenu(hSubMenu, MF_STRING, ID_DIALOG_SHOW, "&Show");
                AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Toolbar");
    
                SetMenu(hwnd, hMenu);
                
                g_hToolbar = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_TOOLBAR),
                hwnd, ToolDlgProc);
                if(g_hToolbar != NULL)
                {
                    ShowWindow(g_hToolbar, SW_SHOW);
                }
                else
                {
                    MessageBox(hwnd, "CreateDialog returned NULL", "Warning!",  
                        MB_OK | MB_ICONINFORMATION);
                }
            }
            break;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case ID_FILE_EXIT:
                        ::PostMessage(hwnd, WM_CLOSE, 0, 0);
                    break;
                    case ID_STUFF_GO:
    
                    break;
                    case ID_HELP_ABOUT:
                    {
                        int ret = DialogBox(GetModuleHandle(NULL), 
                            MAKEINTRESOURCE(IDD_ABOUT), hwnd, AboutDlgProc);
                        if(ret == IDOK){
                            MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                                MB_OK | MB_ICONINFORMATION);
                        }
                        else if(ret == IDCANCEL){
                            MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                                MB_OK | MB_ICONINFORMATION);
                        }
                        else if(ret == -1){
                            MessageBox(hwnd, "Dialog failed!", "Error",
                                MB_OK | MB_ICONINFORMATION);
                        }
                    }
                    break;
                    case ID_HELP_ABOUT_TWO:
                    {
                        int ret = DialogBox(GetModuleHandle(NULL), 
                            MAKEINTRESOURCE(IDD_ABOUT_TWO), hwnd, AboutDlgProc);
                        if(ret == IDOK){
                            MessageBox(hwnd, "Dialog exited with IDOK.", "Notice",
                                MB_OK | MB_ICONINFORMATION);
                        }
                        else if(ret == IDCANCEL){
                            MessageBox(hwnd, "Dialog exited with IDCANCEL.", "Notice",
                                MB_OK | MB_ICONINFORMATION);
                        }
                        else if(ret == -1){
                            MessageBox(hwnd, "Dialog failed!", "Error",
                                MB_OK | MB_ICONINFORMATION);
                        }
                    }
                    break;
                    case ID_DIALOG_SHOW:
                        ShowWindow(g_hToolbar, SW_SHOW);
                    break;
                    case ID_DIALOG_HIDE:
                        ShowWindow(g_hToolbar, SW_HIDE);
                    break;
    
                }
            break;
            case WM_DESTROY:
                ::DestroyWindow(g_hToolbar);
                ::PostQuitMessage (0);
                return 0;
            break;
            default:
                return ::DefWindowProc (hwnd, message, wParam, lParam );
        }
        return 0;
    }
    BOOL CALLBACK AboutDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_INITDIALOG:
    
            return TRUE;
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDOK:
                        EndDialog(hwnd, IDOK);
                    break;
                    case IDCANCEL:
                        EndDialog(hwnd, IDCANCEL);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }
    BOOL CALLBACK ToolDlgProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
    {
        switch(Message)
        {
            case WM_COMMAND:
                switch(LOWORD(wParam))
                {
                    case IDC_PRESS:
                        MessageBox(hwnd, "Hi!", "This is a message", 
                            MB_OK | MB_ICONEXCLAMATION);
                    break;
                    case IDC_OTHER:
                        MessageBox(hwnd, "Bye!", "This is also a message", 
                            MB_OK | MB_ICONEXCLAMATION);
                    break;
                }
            break;
            default:
                return FALSE;
        }
        return TRUE;
    }
    dialog.rc
    Code:
    #include <windows.h>
    #include "resource.h"
    
    IDD_ABOUT DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nby theForger",
                        IDC_STATIC,16,18,144,33
    END
    IDD_ABOUT_TWO DIALOG DISCARDABLE  0, 0, 239, 66
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
    CAPTION "My About Box"
    FONT 8, "MS Sans Serif"
    BEGIN
        DEFPUSHBUTTON   "&OK",IDOK,174,18,50,14
        PUSHBUTTON      "&Cancel",IDCANCEL,174,35,50,14
        GROUPBOX        "About this program...",IDC_STATIC,7,7,225,52
        CTEXT           "An example program showing how to use Dialog Boxes\r\n\r\nEdited by Zeusbwr",
                        IDC_STATIC,16,18,144,33
    END
    IDD_TOOLBAR DIALOGEX 0, 0, 98, 52
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
    EXSTYLE WS_EX_TOOLWINDOW
    CAPTION "My Dialog Toolbar"
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "&Press This Button",IDC_PRESS,7,7,84,14
        PUSHBUTTON      "&Or This One",IDC_OTHER,7,31,84,14
    END
    resource.h
    Code:
    #define IDD_ABOUT               101
    #define IDD_ABOUT_TWO           102
    #define IDC_STATIC              -1
    #define ID_FILE_EXIT            9001
    #define ID_STUFF_GO             9002
    #define ID_HELP_ABOUT           9003
    #define ID_HELP_ABOUT_TWO       9004
    #define IDD_TOOLBAR             9005
    #define IDC_PRESS               9006
    #define IDC_OTHER               9007
    #define ID_DIALOG_SHOW          9008
    #define ID_DIALOG_HIDE          9009
    Last edited by Zeusbwr; 04-07-2005 at 11:38 PM. Reason: added question
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    What you are describing seems like a variant of what I believe mfc describes as a 'formview' window - one where the client, or in your case a part of it, is occupied by a dialog box.

    The simplest way to achieve that is to change the style of the dialog with id IDD_TOOLBAR DIALOGEX to WS_CHILD and remove the EXSTYLE resource definition statement. If you need to position/size the dialog you can do so with MoveWindow/SetWindowPos in the dialog's WM_INITDIALOG or, probably better, in the parent's WM_SIZE handler.
    Last edited by Ken Fitlike; 04-08-2005 at 12:44 PM.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Well i tried a few ways but i cannot seem to get it to spawn inside, i keep getting syntax errors. Are any of the following ways what you mean?
    (Note: i am not adding the window position/size yet, i was just trying to get it to spawn inside first).

    Tried One
    Code:
    IDD_TOOLBAR WS_CHILD 0, 0, 98, 52
    EXSTYLE WS_EX_TOOLWINDOW
    CAPTION "My Dialog Toolbar"
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "&Press This Button",IDC_PRESS,7,7,84,14
        PUSHBUTTON      "&Or This One",IDC_OTHER,7,31,84,14
    END
    Two
    Code:
    WS_CHILD
    EXSTYLE WS_EX_TOOLWINDOW
    CAPTION "My Dialog Toolbar"
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "&Press This Button",IDC_PRESS,7,7,84,14
        PUSHBUTTON      "&Or This One",IDC_OTHER,7,31,84,14
    END
    Three
    Code:
    WS_CHILD
    STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION
    EXSTYLE WS_EX_TOOLWINDOW
    CAPTION "My Dialog Toolbar"
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "&Press This Button",IDC_PRESS,7,7,84,14
        PUSHBUTTON      "&Or This One",IDC_OTHER,7,31,84,14
    END
    ect.., i tried multiple ways but kept getting resource errors.
    And WS_CHILD DIALOGEX caused some dialog returned null error on runtime.
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    My mistake - I mean't remove the EXSTYLE resource definition statement; remove the CAPTION, too. So that particular dialog resource becomes:
    Code:
    IDD_TOOLBAR DIALOGEX 0, 0, 98, 52
    STYLE  WS_CHILD
    FONT 8, "MS Sans Serif"
    BEGIN
        PUSHBUTTON      "&Press This Button",IDC_PRESS,7,7,84,14
        PUSHBUTTON      "&Or This One",IDC_OTHER,7,31,84,14
    END
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    #junkie
    Join Date
    Oct 2004
    Posts
    240
    Are there any tutorials about the ways of making various GUI structures? Even though it now spawns in my main parent window, many things are still left to question.

    So.. do you know of any bigger Win32 GUI tutorials? Like making a program from start to finish? All i can seem to get ahold of are text editors, which use basically an empty Window, a Menu System, and a input field. And i have yet to even find a dropdown box on google for win32..
    01110111011000010110110001100100011011110010000001 11000101110101011010010111010000100000011011000110 10010110011001100101001000000111100101101111011101 0100100000011011100111010101100010

  6. #6
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    A dropdown box is called a combo box. The biggest problem encountered with combo boxes is remembering that the height of the combo box includes the drop down portion.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. inter process communcation, parent - child
    By tallan in forum C Programming
    Replies: 5
    Last Post: 02-28-2009, 03:04 AM
  2. Replies: 7
    Last Post: 02-06-2009, 11:27 AM
  3. Replies: 3
    Last Post: 10-15-2008, 09:24 AM
  4. Make a dialog show up
    By guitarist809 in forum Windows Programming
    Replies: 4
    Last Post: 05-04-2008, 01:08 AM
  5. Dialog popup when program executed.
    By xlnk in forum Windows Programming
    Replies: 1
    Last Post: 03-03-2004, 05:44 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21