Thread: How to Use a Dialog as Main Window?

  1. #1
    Mike2432
    Guest

    Question How to Use a Dialog as Main Window?

    I'm new to windows programming and have created my main menu window as a dialog. Right now I have it calling the dialog window when the program starts, but is there any way to actually make the dialog my main window?

    For example, when defining my window with WNDCLASSEX, can I set the style or something to a dialog I've created?

    Thanks!

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    It would be easier if you posted code for me to look at and offer advice. You can use WS_POPUP for your style.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quick post - i've got to go 5 minutes ago.

    Lots of ways. Use CreateDialog/DialogBox to create a modal/modeless dialog. Apart from returning FALSE for default msg processing, that's more or less it. Alternatively, if you want to have it as a registered WNCLASSEX then 'superclass' the dialog resource thingy:

    1. Create dialog resource.
    2. Use GetClassInfoEx to fill a WNDCLASSEX structure with required info.
    3. Modify the 'wndproc' param of 'wndclassex' to point to your custom wndproc.
    4. Register wnd with RegisterClassEx.
    5. Create window with CreateWindowEx.
    6. Use DefDlgProc for default msg handling.

    Something like that anyway...Hopefully someone else will fill in the details or a quick 'google' may furnish you with a concrete example. Good luck.

    I really have to go...
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Unregistered
    Guest
    Thanks; this is what I have, but when I run it nothing happens.

    Code:
    LRESULT CALLBACK MainMenu(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	switch (uMsg)
    	{
    		case WM_CREATE:
    			MessageBox(NULL, "hi", "", MB_OK);
    			break;
    
    		case WM_INITDIALOG:
    			return true;
    
    		case WM_COMMAND:
    			if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) 
    			{
    				EndDialog(hDlg, LOWORD(wParam));
    				return true;
    			}
    			break;
    
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    
    		default:
    			return DefDlgProc(hDlg, uMsg, wParam, lParam);
    	}
        return false;
    }
    
    int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmdLine, int nShowCmd)
    {
    	WNDCLASSEX window;
    	MSG msg;
    	HWND hWnd;
    	LPCTSTR className = "IDD_MAINMENU", windowName = "test";
    	
    	window.cbSize = sizeof(WNDCLASSEX);
    
    	GetClassInfoEx(hInst, "IDD_MAINMENU", &window);
    
    	window.lpfnWndProc = MainMenu;
    
    	RegisterClassEx(&window);
    	hWnd = CreateWindow(className, windowName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 
    						CW_USEDEFAULT, 500, 500, NULL, NULL, hInst, NULL);
    
    	ShowWindow(hWnd, nShowCmd);
    	UpdateWindow(hWnd);
    
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }

  5. #5
    Mike2432
    Guest
    That last post was mine but I forgot my name.

  6. #6
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Instead of CreateWindow you should use CreateDialog to make the dialog, it returns the handle to the newly created dialog box if successful. Also in a dialogproc you should not send unhandled messages to "defwindowproc".
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  7. #7
    Registered User
    Join Date
    Jul 2002
    Posts
    36

    Taskbar Entry for modal Dialog?

    Well I also have a Dialog as main window, but a modal one. Now I want it to be listed in the taskbar like a normal window. Is that possible?
    "I don't know with what weapons World War III will be fought... but World War IV will be fought with sticks and stones." - Albert Einstein

  8. #8
    Registered User The Dog's Avatar
    Join Date
    May 2002
    Location
    Cape Town
    Posts
    788
    You could also create a dialog box in a resource editor, then when you call CreateDialog(), you pass MAKEINTRESOURCE(/*the id of the dialog goes here*/) as the hMenu parameter.

    Not sure if this method is frowned upon or not, but doing it this way makes creating a good GUI very easy.

  9. #9
    Mike2432
    Guest
    Thanks everyone!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  2. Dialog window size
    By xkrja in forum Windows Programming
    Replies: 1
    Last Post: 11-22-2006, 06:07 AM
  3. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  4. what to do with the main window
    By stallion in forum Windows Programming
    Replies: 2
    Last Post: 01-28-2003, 08:58 PM
  5. I want main window to be a dialog...
    By Garfield in forum Windows Programming
    Replies: 15
    Last Post: 02-20-2002, 08:41 PM