Making dialog box the only window

This is a discussion on Making dialog box the only window within the Windows Programming forums, part of the Platform Specific Boards category; I have a simple dialog box created (IDD_DIALOG1) that I want to make as the sole window to the entire ...

  1. #1
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728

    Making dialog box the only window

    I have a simple dialog box created (IDD_DIALOG1) that I want to make as the sole window to the entire program. Everything works great except that being a dialog box no tab shows up in the taskbar when run, the user has to close all other open windows to find it. Here is my skimmed down code, is there an easy way to make it so my program can be accessed from the task bar without having to manually create a child window that looks like a dialog box? I'm using MSVC++ by the way. I feel like I'm missing something very simple...
    Code:
    #include <windows.h>
    #include <process.h>
    #include <vector>
    #include <commctrl.h>
    #include <shlobj.h>
    #include <objbase.h>
    #include <string>
    #include <direct.h>
    #include <time.h>
    #include <shellapi.h>
    
    #include <stdio.h>
    #pragma comment(lib, "gdi32.lib")
    #pragma comment(lib, "comctl32.lib")
    #pragma comment(lib, "shell32.lib")
    #pragma comment(lib, "ole32.lib")
    
    #include "resource.h"
    
    using namespace std;
    
    
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    BOOL CALLBACK MainDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int iCmdShow)
    {
    	srand(time(NULL));
    	static TCHAR szAppName[]=TEXT("Test");  // TCHAR=character string
    	HWND hwnd;   // handle to a window
    	MSG msg;   // message
    	WNDCLASS wndclass;  // window class we are declaring
    
    
    	// Now we set the attributes for our window
    	wndclass.style=CS_HREDRAW | CS_VREDRAW;  // Style, in this case can be redrawn
    	wndclass.lpfnWndProc=WndProc;  // window process name - handles message calls
    	wndclass.cbClsExtra=0;  // Extra space for the window
    	wndclass.cbWndExtra=0;  // ditto
    	wndclass.hInstance=hInstance;  // program instance name passed to WinMain
    	wndclass.hIcon=LoadIcon(hInstance, MAKEINTRESOURCE(IDI_ICON1));  // Load icon for the tray
    	wndclass.hCursor=LoadCursor(NULL, IDC_ARROW);  // Load icon for the mouse arrow
    	wndclass.hbrBackground=(HBRUSH) GetStockObject(WHITE_BRUSH);  // Load background color
    	wndclass.lpszMenuName=NULL;  // Set menu - none here
    	wndclass.lpszClassName=szAppName;  // Sets window name, taken from above
    
    
    	if (!RegisterClass(&wndclass))
    	{
    		MessageBox(NULL, TEXT("Unable to open program!"), szAppName, MB_ICONERROR);
    		return 0;
    	}
    
    
    
    	hwnd=CreateWindow(szAppName, TEXT("Test"), WS_OVERLAPPEDWINDOW,
    		CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, NULL, NULL,
    		hInstance, NULL);  // Create the window!  Name, Title, Style, x Position, y Position
    	                       // X size, Y size, parent window handle, window menu handle, 
    						   // program instance handle, creation parameters(passing variables)
    
    	//ShowWindow(hwnd, iCmdShow);  // now show the window!
    	UpdateWindow(hwnd);   // update it
    
    	while (GetMessage(&msg, NULL, 0, 0))  // gets message from mouse and keyboard, always non
    		                                  // zero until you quit the window
    	{
    		TranslateMessage(&msg);           // translates message from message queue (mouse/keyboard/etc)
    		DispatchMessage(&msg);			  // sends to WndProc to translate and tell what to do!
    	}
    
    	return msg.wParam;
    
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HINSTANCE hInstance;
    	static HWND hDlg;
    
    	switch (message)
    	{
    	case WM_CREATE:
    		hInstance=((LPCREATESTRUCT) lParam)->hInstance;
    		DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, MainDialogProc);
    		PostQuitMessage(0);
    		return 0;
    
    	case WM_SIZE:
    	
    		return 0;
    
    	case WM_PAINT:
    
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	}
    
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
    BOOL CALLBACK MainDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
    	switch (message)
    	{
    	case WM_INITDIALOG:
    
    		return TRUE;
    
    
    	case WM_COMMAND:
    
    		return TRUE;
    
    	case WM_CLOSE:
    
    		PostQuitMessage(0);
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	}
    
    	return FALSE;
    }

  2. #2
    Registered /usr
    Join Date
    Aug 2001
    Location
    Newport, South Wales, UK
    Posts
    1,262
    Code:
    DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG1), hwnd, MainDialogProc);
    Here, you're assigning the window you created as the owner of the dialog. If you want it to be visible on the taskbar, that's a no-no.

  3. #3
    Cheesy Poofs! PJYelton's Avatar
    Join Date
    Sep 2002
    Location
    Boulder
    Posts
    1,728
    Brilliant, thanks, I knew it was something small and stupid. It works perfectly now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. Dialog Box causes program to exit
    By norbs27 in forum Windows Programming
    Replies: 10
    Last Post: 01-14-2008, 09:09 PM
  3. Add a dialog box to a tab
    By axr0284 in forum Windows Programming
    Replies: 0
    Last Post: 01-10-2005, 07:38 AM
  4. Adding colour & bmps to a Win 32 Window??
    By carey_sizer in forum Windows Programming
    Replies: 4
    Last Post: 09-04-2004, 05:55 PM
  5. Tab Controls - API
    By -KEN- in forum Windows Programming
    Replies: 7
    Last Post: 06-02-2002, 09:44 AM

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