Dialogs and stuff

This is a discussion on Dialogs and stuff within the Windows Programming forums, part of the Platform Specific Boards category; Okay, I've only been trying to use the Win32 API for a short time but thought I was making great ...

  1. #1
    Registered User Nova_Collision's Avatar
    Join Date
    Feb 2003
    Posts
    40

    Dialogs and stuff

    Okay, I've only been trying to use the Win32 API for a short time but thought I was making great progress. Until now. I had written a small program in MSVC 6 that basically just displayed a modeless dialog (Or modal...I may have them backwards, but it's the one where the dialog doesn't have to be destroyed to return to the parent). It worked fine. Now I'm trying to do a real program and for some reason, I can't do the same thing. No matter what I try, I can't get a simple dialog to display. Message boxes are fine, but no dialogs. Instinct tells me that I have my dialog set up improperly but I can't find where and I really don't know for sure anyway. Here's some code :

    Code:
    LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_CREATE:
    			CreateDialog(myInstance, MAKEINTRESOURCE(IDD_MAIN), hwnd, MainProc);
    			break;
    		case WM_COMMAND:
    			break;
    		case WM_CLOSE:
    			DestroyWindow(hwnd);
    			break;
    		case WM_DESTROY:
    			PostQuitMessage(0);
    			break;
    		default:
    			return DefWindowProc(hwnd,  msg, wParam, lParam);
    	}
    	return 0;
    }
    
    BOOL CALLBACK MainProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    	switch(msg)
    	{
    		case WM_INITDIALOG:
    		return true;
    		break;
    		case WM_COMMAND:
    			switch(LOWORD(wParam))
    			{
    			}
    			break;
    		default:
    			return false;
    			break;
    	}
    	return true;
    }
    The parent window itself displays fine. A great big white box. Yay.

    Here's the bit of the .rc file with my dialog:
    IDD_MAIN DIALOG DISCARDABLE 0, 0, 449, 206
    STYLE WS_CHILD | WS_VISIBLE | WS_THICKFRAME
    FONT 8, "MS Sans Serif"
    BEGIN
    LTEXT "Yeah, this blows.",IDC_STATIC,63,36,172,72
    END

    If you need more, just let me know.
    When in doubt, empty your magazine - Murphy's Laws Of Combat #7

  2. #2
    Registered User dalek's Avatar
    Join Date
    May 2003
    Posts
    135
    I presume your myInstance is a global variable. Are you sure you have initialised it?

  3. #3
    Registered User Nova_Collision's Avatar
    Join Date
    Feb 2003
    Posts
    40
    Yeah, it's global because I know I'm going to need to manipulate later in other functions. Yeah, it's initialized. At least, would the main window have come up if it hadn't been? Hmmm...I wonder...
    When in doubt, empty your magazine - Murphy's Laws Of Combat #7

  4. #4
    Registered User Nova_Collision's Avatar
    Join Date
    Feb 2003
    Posts
    40
    Here's my WinMain method :

    Code:
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
    {
    	myInstance = hInstance;
    	WNDCLASSEX wc;
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.style = 0;
    	wc.lpfnWndProc = WndProc;
    	wc.cbClsExtra = 0;
    	wc.cbWndExtra = 0;
    	wc.hInstance = myInstance;
    	wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
    	wc.hCursor = LoadCursor(NULL,IDC_ARROW);
    	wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
    	wc.lpszMenuName = MAKEINTRESOURCE(NULL);
    	wc.lpszClassName = g_szClassName;
    	wc.hIconSm = LoadIcon(NULL,IDI_APPLICATION);
    	if(!RegisterClassEx(&wc)) 
      {
    		MessageBox(NULL , "Failed to register window class", "Error" , MB_ICONEXCLAMATION | MB_OK );
    		return 0;
    	}
    	HWND hwnd;
    	int cx, cy;
    	cx = GetSystemMetrics(SM_CXMAXIMIZED);
    	cy = GetSystemMetrics(SM_CYMAXIMIZED);
    	//char data[10];
    	//sprintf(data, "%d, %d", cx, cy);
    	//MessageBox(NULL, data, "Message", MB_OK);
    	if(cx >= 1024)
    		cx = 1024;
    	if(cy >= 746)
    		cy = 746;
    	hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, g_szClassName, "ASP Menu Configuration", WS_OVERLAPPEDWINDOW, 
    		0, 0, cx, cy, NULL, NULL, myInstance, NULL);
    	if(hwnd == NULL) 
    	{ 
    		MessageBox(NULL, "Failed to create window", "Error", MB_ICONEXCLAMATION | MB_OK ); 
    		return 0; 
    	}
    	ShowWindow(hwnd,nCmdShow);
    	UpdateWindow(hwnd);
    	MSG Msg;
    	while(GetMessage(&Msg,NULL,0,0) > 0)
    	{
    		TranslateMessage(&Msg);
    		DispatchMessage(&Msg);
    	}
    	return Msg.wParam;
    }
    When in doubt, empty your magazine - Murphy's Laws Of Combat #7

  5. #5
    Registered User Nova_Collision's Avatar
    Join Date
    Feb 2003
    Posts
    40
    I figured it out. And man, do I feel foolish. :P

    I hadn't added the resource.h header or script.rc files to the fileview in MSVC. Thing is, since it was compiling fine, I didn't even think about this, but I suppose it must look for the data at runtime. Which makes a lot of sense......maybe. Sometimes I want to find the person that invented computers and stab him in the face. Debugging makes working at A&W for the rest of my life seem mild in comparison.
    When in doubt, empty your magazine - Murphy's Laws Of Combat #7

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need a little help here about MFC and Tab Control stuff...
    By guitarist809 in forum Windows Programming
    Replies: 4
    Last Post: 09-19-2008, 11:36 AM
  2. Replies: 2
    Last Post: 05-29-2005, 11:06 AM
  3. Icons in dialogs...
    By void in forum Windows Programming
    Replies: 2
    Last Post: 10-27-2002, 10:39 AM
  4. Dialogs and resources
    By SushiFugu in forum Windows Programming
    Replies: 6
    Last Post: 01-23-2002, 02:05 PM

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