Problem with dialog procedure

I'm trying to make Some kind of a main menu for the app, I made a dialog box with buttons for easy, normal, hard, options..., I'm calling it at the WM_CREATE, like this:DialogBox(GetModuleHandle(NULL),MAKEINTRESOURCE(MMENU),hwnd, MMENUProc);

the MMENUProc function:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
BOOL CALLBACK MMENUProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{
    switch(Message)
    {
		case WM_INITDIALOG:

        return TRUE;
        case WM_COMMAND:
            switch(LOWORD(wParam))
            {
                case ID_EASY:
					MessageBox(hwnd,_T("You chose easy!"),_T("Difficulty"),MB_OK);
                    //EndDialog(hwnd, IDOK);
                break;
                case ID_EXIT:
                    DestroyWindow(hwnd);
                break;
            }
        break;
		default:
            return FALSE;
    }
    return TRUE;
}


Now no matter what the dialog doesn't show, but it always executes this part:
MessageBox(hwnd,_T("You chose easy!"),_T("Difficulty"),MB_OK);
3 times then the process keeps running and nothing happens. The dialog box doesn't even open. What am I doing wrong?
Last edited on
This might not solve your problem but you must return FALSE on line 23
well all that did is:
instead of 3x executing the MessageBox(); it does it 5x but the 5th one dissapears before you can click it. Still no menu...
Can you post more code?
1
2
3
4
5
6
7
8
9
10
#define ID_EASY 11
#define ID_NORMAL 12
#define ID_HARD 13
#define ID_HIGHSCORE 14
#define ID_OPTIONS 15
#define ID_EXIT 16
#define ID_CREDITS 17
#define ID_VERSION 18
#define ID_IME 0
#define IDC_STATIC 0 

That is the resource.h relating the menu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
MMENU DIALOGEX 0, 0, 293, 183
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Snake"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
    CTEXT           "SNAKE",ID_IME,51,23,201,37,SS_CENTERIMAGE | WS_BORDER
    PUSHBUTTON      "Easy",ID_EASY,93,69,33,14,BS_CENTER | BS_NOTIFY,WS_EX_STATICEDGE
    PUSHBUTTON      "Normal",ID_NORMAL,126,69,50,14,0,WS_EX_STATICEDGE
    PUSHBUTTON      "Hard",ID_HARD,175,69,34,14,0,WS_EX_STATICEDGE
    PUSHBUTTON      "Highscores",ID_HIGHSCORE,93,106,115,20,0,WS_EX_STATICEDGE
    PUSHBUTTON      "Options",ID_OPTIONS,93,129,115,20,BS_CENTER,WS_EX_STATICEDGE
    PUSHBUTTON      "Exit",ID_EXIT,94,151,114,25,0,WS_EX_STATICEDGE
    PUSHBUTTON      "Credits",ID_CREDITS,93,84,116,19
    LTEXT           "CircleLogic(C) Snake",IDC_STATIC,211,162,67,14
    PUSHBUTTON      "Version",ID_VERSION,7,163,50,13
END


Here's the menu that was supposed to open.
1. Remove BS_NOTIFY from line 7
2. Rename HMENU to something else (eg. MENU_DLG). I believe HMENU is declared somewhere in windows headers.

EDIT: Also, to close a dialog box use EndDialog(); function (you are using DestroyWindow() on line 16).
Last edited on
Refer to http://msdn.microsoft.com/en-us/library/windows/desktop/ms645452(v=vs.85).aspx for information on DialogBox(), and then refer to http://msdn.microsoft.com/en-us/library/windows/desktop/ms645469(v=vs.85).aspx for information on the callback procedure. Note that the callback's return type is INT_PTR, not BOOL. This is most important when compiling for 64-bit PC's because the data type sizes are different and you'll receive a compilation error.

Make the changes and see if there are any improvements.

If not, I am thinking that the parent window may not be suitable for the dialog box. You say you want the dialog box to show up during the WM_CREATE of its parent window. This means the window is not yet visible. It may be possible that DialogBox() checks for visibility of the parent in order to match that visibility. Try moving the call elsewhere. Maybe WM_ACTIVATE is good?
Thx Null! The BS_NOTIFY was the problem, as soon as I fixed that it worked!

Now so I don't need to open another topic, I was looking for a way to flip images by 90 degrees, I could only find examples with tons of code, for which I was almost certain I didn't need. ATM I'm drawing the bmp's like that:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//^includes
HBITMAP picture=NULL;

//In WM_CREATE
picture=LoadBitmap(GetModuleHandle(NULL), MAKEINTRESOURCE(PICTURE_ONE));

//Then in WM_PAINT
BITMAP bm;
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hwnd, &ps);
HDC hdcMem = CreateCompatibleDC(hdc);
HBITMAP hbmOld = SelectObject(hdcMem, picture);
GetObject(picture, sizeof(bm), &bm);
BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);
SelectObject(hdcMem, hbmOld);
DeleteDC(hdcMem);
EndPaint(hwnd, &ps);
Topic archived. No new replies allowed.