Can someone help me figure out why my dialog isn't showing?

This is a discussion on Can someone help me figure out why my dialog isn't showing? within the Windows Programming forums, part of the Platform Specific Boards category; I have a resource file that has a few commands. All of them bring up messageboxes. the last one is ...

  1. #1
    Shadow12345
    Guest

    Can someone help me figure out why my dialog isn't showing?

    I have a resource file that has a few commands. All of them bring up messageboxes. the last one is supposed to bring up a dialog box. I thought I had the dialog procedure set up correctly, and I thought i was doing everything right but im not sure why the dialog doesn't show up.

    The important code is in the wndproc, but i included everything any just in case something from winmain needs to be looked at.

    well here is my code, i didn't comment it because it is a pretty straightforward winapi program.

    Code:
    #include <windows.h>
    #include "resource.h"
    
    HWND Child1;
    
    HINSTANCE gHinst;	//NOT USED, REFERENCED A DIFFERENT WAY
    
    LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    BOOL CALLBACK AboutDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd ){
    	HWND Uber;
    	MSG msg;
    	WNDCLASSEX wc;
    	gHinst = hInstance;
    	wc.cbClsExtra = 0;
    	wc.cbSize = sizeof(WNDCLASSEX);
    	wc.cbWndExtra = 0;
    	wc.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
    	wc.hCursor = LoadCursor(hInstance, IDC_CROSS);
    	wc.hIcon = LoadIcon(hInstance, IDI_ERROR);
    	wc.hIconSm = NULL;
    	wc.hInstance = hInstance;
    	wc.lpfnWndProc = MainWndProc;
    	wc.lpszClassName = "Main Window";
    	wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
    	wc.style = CS_HREDRAW | CS_VREDRAW;
    	
    	if(!RegisterClassEx(&wc)) {
    		MessageBox(NULL, "Could not initialize window", "ERROR", MB_OK);
    		return ERROR;
    	}
    	
    	if(!(Uber = CreateWindowEx(NULL, "Main Window", "Main Window", WS_SYSMENU |  WS_MAXIMIZEBOX | WS_MINIMIZEBOX, 
    							   0, 0, 
    							   CW_USEDEFAULT, CW_USEDEFAULT, 
    							   NULL, NULL, hInstance, NULL))) {
    							   MessageBox(NULL, "Could not initialize window", "ERROR", MB_OK);
    								return ERROR;						   
    	}
    
    	Child1 = CreateWindowEx(NULL, "BUTTON", "SEX!",WS_VISIBLE | WS_CHILD |BS_DEFPUSHBUTTON, 10, 40, 35, 35, Uber, NULL, hInstance, NULL );
    
    	ShowWindow(Uber, nShowCmd);
    	UpdateWindow(Uber);
    
    	while(GetMessage(&msg, NULL, 0, 0)) {
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    	return 0;
    }
    
    LRESULT CALLBACK MainWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) {
         static HINSTANCE hInstance ;
    
    	switch(message) {
    	case WM_COMMAND:
    		switch(LOWORD(wParam)) {
    		case WM_CREATE:
    			hInstance = ((LPCREATESTRUCT) lParam)->hInstance ;
    			break;
    		case ID_FILE_HI:
    			MessageBox(hWnd, "Hi Mother", "HMF", MB_YESNO);
    			break;
    		case ID_APP_BUTTON2:
    			MessageBox(hWnd, "This is the ID_APP_ABOUT EVENT", "asdf", MB_OK);
    			break;
    		case ID_APP_BUTTON3:
    			MessageBox(hWnd, "This is the ID_BUTTON3 EVENT", "cheese", MB_OK);
    			break;
    		case ID_APP_DIALOG1:
    			DialogBox(hInstance, TEXT ("AboutBox"), hWnd, AboutDlgProc);
    			break;
    		}
    	
    		return 0;
    		//switch to determine what kind of command has taken place and provide appropriate code
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    	default:
    		return DefWindowProc(hWnd, message, wParam, lParam);
    	}
    }
    
    BOOL CALLBACK AboutDlgProc(HWND Dlg, UINT message, WPARAM wParam, LPARAM lParam) {
    
         switch (message)
         {
         case WM_INITDIALOG :
              return TRUE ;
              
         case WM_COMMAND :
              switch (LOWORD (wParam))
              {
              case IDOK :
              case IDCANCEL :
                   EndDialog (Dlg, 0) ;
                   return TRUE ;
              }
              break ;
         }
         return FALSE ;
    }

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Check your resource script where you have defined your dialog resource and ensure that it has the WS_VISIBLE style. Alternatively you can use ShowWindow in your WM_INITDIALOG handler.

  3. #3
    Registered User
    Join Date
    Jan 2002
    Posts
    11
    I'd need to see your resource (rc) file to double check, but I'm pretty sure the problem is that you are calling DialogBox without using MAKEINTRESOURCE for the template.

    Code:
    int DialogBox(
        HINSTANCE hInstance,	// handle to application instance
        LPCTSTR lpTemplate,	// identifies dialog box template
        HWND hWndParent,	// handle to owner window
        DLGPROC lpDialogFunc 	// pointer to dialog box procedure  
    );
    Would be DialogBox(hInstance, MAKEINTRESOURCE(AboutBox), hWnd, AboutDlgProc);

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    ...On second thoughts, I think that Sindol may well be right, depending on how you have identified your dialog resource (ie as a string or number).

    Good call, Sindol.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Shadow12345
    Guest
    Ok thanks it works. Btw this is the first time making a dialog box. Every time I do something new under windows programming i get really excited lol

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-13-2008, 01:59 PM
  2. make Child Dialog not Popup?
    By Zeusbwr in forum Windows Programming
    Replies: 5
    Last Post: 04-08-2005, 02:42 PM
  3. Getting the position of a dialog without parent on the screen
    By stormbringer in forum Windows Programming
    Replies: 1
    Last Post: 08-27-2003, 02:59 AM
  4. Problem with Dialog not showing
    By face_master in forum Windows Programming
    Replies: 12
    Last Post: 12-29-2002, 08:14 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