problem with calling dialog

This is a discussion on problem with calling dialog within the Windows Programming forums, part of the Platform Specific Boards category; i was just programming a windows app, and so far it's just a window with a menu (just started it, ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    157

    problem with calling dialog

    i was just programming a windows app, and so far it's just a window with a menu (just started it, basic designing and functionality). in the menu there's "new", "open" (which does nothign right now), and "exit" (destroys window, exits app).

    anyways, "new" is supposed to call a dialog which should allow for choosing some options, etc. anyways, when i hit "new", it greys the main window like there's supposed to be a dialog, but there's not! even though there should be.

    then, during one run, i accidentally hit "alt" and it popped up the dialog (after i previously hit "new"). what could be causing this? would you like to see my code? i've been looking through it, and i can't find it. if you would like to see the code (as that might help), then i'll post it. pretty much it's just a lot of routine api programming, and very little functionality. that's why i can't figure out the problem!

    help, please! thanks.

    -stallion

  2. #2
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Seeing the code would be helpful. Speculation: Perhaps you have neither set the WS_VISIBLE style of the dialog or have not called ShowWindow ie the dialog is created but not shown? Is the dialog modal or modeless?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    >> would you like to see my code?

    Always assume we would like to see relevant parts of the code.

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    Code:
    #include <windows.h>
    #include "resource.h"
    
    LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
    BOOL	CALLBACK NewTournyProc(HWND, UINT, WPARAM, LPARAM);
    
    HINSTANCE hInst;
    
    int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int nCmdShow)
    {
    	static TCHAR szAppName[] = TEXT("Tournament");
    	MSG			msg;
    	HWND		hwnd;
    	WNDCLASS	wcl;
    	hInst = hInstance;
    
    	wcl.style = CS_HREDRAW | CS_VREDRAW;
    	wcl.lpfnWndProc = WndProc;
    	wcl.cbClsExtra = 0;
    	wcl.cbWndExtra = 0;
    	wcl.hInstance = hInstance;
    	wcl.hIcon = LoadIcon(NULL, IDI_APPLICATION);
    	wcl.hCursor = LoadCursor(NULL, IDC_ARROW);
    	wcl.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
    	wcl.lpszMenuName = "Tournament";
    	wcl.lpszClassName = szAppName;
    
    	if(!RegisterClass(&wcl))
    	{
    		MessageBox(NULL, "Couldn't register class...", "Error!", MB_OK);
    		return 0;
    	}
    
    	hwnd = CreateWindow(szAppName, TEXT("Tournament"),
    			WS_OVERLAPPEDWINDOW,
    			GetSystemMetrics(SM_CXSCREEN)/4, GetSystemMetrics(SM_CYSCREEN)/4,
    			GetSystemMetrics(SM_CXSCREEN)/2, GetSystemMetrics(SM_CYSCREEN)/2,
    			NULL, NULL, hInst, NULL);
    
    	ShowWindow(hwnd, nCmdShow);
    	UpdateWindow(hwnd);
    
    	while(GetMessage(&msg, NULL, 0, 0))
    	{
    		TranslateMessage(&msg);
    		DispatchMessage(&msg);
    	}
    
    	return msg.wParam;
    }
    
    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
    	static HWND			hwndPlayer;
    	static HINSTANCE	hInstance;
    
    	switch(message)
    	{
    	case WM_CREATE:
    		hInstance = ((LPCREATESTRUCT) lParam)->hInstance;
    		return 0;
    
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case IDM_NEW:			// new tourny selected
    			DialogBox(hInstance, TEXT("NewTourny"), hwnd, NewTournyProc);
    			return 0;
    
    		case IDM_EXIT:			// exit menu selected
    			PostQuitMessage(0);
    			return 0;
    		}
    
    		return 0;
    
    	case WM_PAINT:
    		return 0;
    
    	case WM_DESTROY:
    		PostQuitMessage(0);
    		return 0;
    
    	default:
    		break;
    	}
    
    	return DefWindowProc(hwnd, message, wParam, lParam);
    }
    
    BOOL CALLBACK NewTournyProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
    	switch(message)
    	{
    	case WM_INITDIALOG:
    		return TRUE;
    
    	case WM_COMMAND:
    		switch(LOWORD(wParam))
    		{
    		case IDOK:
    		case IDCANCEL:
    			EndDialog(hDlg, 0);
    		}
    		return TRUE;
    	}
    
    	return FALSE;
    }
    -stallion

  5. #5
    Registered User Penguin of Oz's Avatar
    Join Date
    Dec 2002
    Posts
    16
    Just to be sure, put a few breaks and stuff into your dialog procedure:
    Code:
    BOOL CALLBACK NewTournyProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
    {
    
    	switch(message)
    	{
    	            case WM_INITDIALOG:
    		         return TRUE;
                        break;
    
                        case WM_COMMAND:
    	                 switch(LOWORD(wParam))
    		         {
    		              case IDOK:
    		              case IDCANCEL:
                                  EndDialog(hDlg, 0);
            		 }
                             return TRUE;
                        break;
    
                        default:
                             // Message not handled...
                             return FALSE;
                        break;
    	}
    
    	return TRUE; // Just in case we forgot to above
    }
    "I don't think there's anything else I can do... my shoes are tied"

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    157

    Question

    what woudl those breaks help with? they shouldn't even be executed in the code command.

  7. #7
    Registered User Penguin of Oz's Avatar
    Join Date
    Dec 2002
    Posts
    16
    They define where the end of each "case" is - I put them in to stop some cases accidentally running into eachother.
    "I don't think there's anything else I can do... my shoes are tied"

  8. #8
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    >>They define where the end of each "case" is - I put them in to stop some cases accidentally running into eachother.<<

    No. The return statements are executed and so the 'break' statements are never reached.

    >>what woudl those breaks help with? they shouldn't even be executed in the code command.<<

    Yes. The return statements are executed and so the 'break' statements are never reached.

    Returning to your original question, your code appears ok so the problem is most likely in your resource script. Have you included the WS_VISIBLE style in your dialog resource as I previously mentioned? If not, your dialog will be created but will not be shown. Alternatively you can use ShowWindow in your WM_INITDIALOG handler for your dialog box to display the dialog:
    Code:
    case WM_INITDIALOG:
      ShowWindow(hDlg,SW_SHOW);
      return TRUE;
    Hope that helps.
    Last edited by Ken Fitlike; 12-09-2002 at 04:38 PM.

  9. #9
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    okay, i got it up and working. thanks!

    -stallion

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    So how did you get it working? I'm just curious because my Win32 API documentation states that DialogBox() displays the dialog box regardless of whether the template specifies the WS_VISIBLE style.
    Thx.
    If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
    What happens is not as important as how you react to what happens. -Thaddeus Golas

  11. #11
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Penguin of Oz mention breaks.

    Ken Fitlike pointed out they are not needed.

    Just a matter of style.
    I use them as others have to read my code and so will find it easier to understand not only what I have done, but what I was attempting.

    One thing.

    The dialogs WM_COMMAND will always return TRUE regardless of weather or not the msg was actually processed.
    Not a problem if you have the code for all the possible commands and don't wish windows to do any default command msg processing.



    Code:
                        case WM_COMMAND:
    	                 switch(LOWORD(wParam))
    		         {
    		              case IDOK:
    		              case IDCANCEL:
                                  EndDialog(hDlg, 0);
            		 }
                             return TRUE;
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  12. #12
    Registered User
    Join Date
    Nov 2002
    Posts
    157
    i had to set the visibility of the dialog.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. shell problem
    By ArXi in forum Linux Programming
    Replies: 2
    Last Post: 06-04-2009, 02:30 AM
  2. MFC Dialog Problem
    By prongs_386 in forum Windows Programming
    Replies: 1
    Last Post: 05-10-2007, 12:25 AM
  3. Problem with Dialog Box
    By KonArtis in forum Windows Programming
    Replies: 3
    Last Post: 01-04-2005, 01:28 PM
  4. problem getting result when calling a function
    By drb2k2 in forum Windows Programming
    Replies: 1
    Last Post: 04-14-2003, 09:51 AM
  5. Dialog Edit box v's WindowsText Problem
    By simham_uk in forum Windows Programming
    Replies: 2
    Last Post: 06-10-2002, 07:28 AM

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