Thread: Creating a window from a dialog box

  1. #1
    george7378
    Guest

    Creating a window from a dialog box

    Hi everyone,

    I have a program which has a dialog box as its main menu, and as such, my WinMain looks like this:

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    return DialogBox(hInstance, MAKEINTRESOURCE(IDD_MAINMENU), NULL, MainDlgProc);
    }
    This means that I don't have a message loop and I don't register any window classes. However, on my dialog box, I want to have a button which launches a window when pressed (not another dialog box) and of course this window requires a message loop. So, my question is: is it possible to create a window from a dialog box? Where should I put the message loop?

    Thanks!

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    13
    Well, you probably don't want to return the value returned from DialogBox to main. From what I think, when you return from main you end the program. The return from main is the exit point of the program, the point of no return. Also, whatever value returned that is no 0, is probably seen as an error. The way I believe it can be done is just by creating window(s) like you would normally do, except you don't use ShowWindow. You only show the windows when you receive a command from the dialog.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    The DialogBox macro uses the CreateWindowEx function to create the dialog box. DialogBox then sends a WM_INITDIALOG message (and a WM_SETFONT message if the template specifies the DS_SETFONT or DS_SHELLFONT style) to the dialog box procedure. The function displays the dialog box (regardless of whether the template specifies the WS_VISIBLE style), disables the owner window, and starts its own message loop to retrieve and dispatch messages for the dialog box.
    So if you do not want to relay on DialogBox internal message loop - You can call CreateWindowEx by yourself and then use your own custom message loop
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Connecting Dialog window to main window
    By vopo in forum Windows Programming
    Replies: 1
    Last Post: 11-26-2007, 07:55 PM
  2. Creating a child window in a parent window
    By vopo in forum Windows Programming
    Replies: 8
    Last Post: 10-06-2007, 04:15 PM
  3. Embedding a window within a dialog window
    By deathscythe in forum Windows Programming
    Replies: 5
    Last Post: 07-30-2006, 02:55 AM
  4. Problem with creating new window, from another window
    By Garfield in forum Windows Programming
    Replies: 6
    Last Post: 01-11-2004, 02:10 PM
  5. opening a dialog window from inside a dialog window
    By uvacow in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2002, 09:27 AM