Menu in WinApi

Mar 20, 2011 at 8:16pm
Hey, I'm just learning winapi programming and i'm having trouble with setting up the menu. The whole code compiles without warning but when i run the .exe file it runs as in goes on and off imediately... and when i remove the code that im using to make the menu blank window works fine.... There's my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
        case WM_CREATE:
    {
        HMENU hMenu, hSubMenu;
        HICON hIcon, hIconSm;

        hMenu = CreateMenu();

        hSubMenu = CreatePopupMenu();
        AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, L"&Exit");
        AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&File");

        hSubMenu = CreatePopupMenu();
        AppendMenu(hSubMenu, MF_STRING, ID_STUFF_GO, L"&Go");
        AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, L"&Stuff");

        SetMenu(hwnd, hMenu);

        hIcon = (HICON)LoadImage(NULL, L"users.ico", IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
        if(hIcon)
            SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
        else
            MessageBox(hwnd, L"Could not load large icon!", L"Error", MB_OK | MB_ICONERROR);

        hIconSm = (HICON)LoadImage(NULL, L"users.ico", IMAGE_ICON, 16, 16, LR_LOADFROMFILE);
        if(hIconSm)
            SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)hIconSm);
        else
            MessageBox(hwnd, L"Could not load small icon!", L"Error", MB_OK | MB_ICONERROR);
    }
Mar 20, 2011 at 8:53pm
To better find where the problem is specifically you should start off with commenting out the icon loading part (lines 18 - 28) or commenting out the menu loading part (lines 6 - 16). I'm pretty sure that it is an issue with the icons because I've used menus a lot and that seems like it is working fine. I can't say for sure about the icons because it has been quite a few months since I've used them.

If you find out what part of the code is the problem then try to comment out each line to find the line that is causing the issue. That will give you a better chance of fixing the problem.
Mar 20, 2011 at 9:03pm
Actually, I'd suggest you to learn how to write resource files. Saves you a lot of hassle with GUI creation.
Mar 20, 2011 at 11:10pm
lol i couldnt believe that i actually didnt put a break at the end of the case ;/

and yes i will try tomorrow doing the same with resource files. :)
Topic archived. No new replies allowed.