Creating a window from a dialog box

This is a discussion on Creating a window from a dialog box within the Windows Programming forums, part of the Platform Specific Boards category; Hi everyone, I have a program which has a dialog box as its main menu, and as such, my WinMain ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    128

    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    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
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

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, 06: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, 01: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, 08:27 AM

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