🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Menus in WIN32

Started by
2 comments, last by SomeCodeGuy 24 years, 5 months ago
Hi all, I'm just writing some simple Opengl program to play around. To setup a basic window, I use the Win32 functions - so it's just a normal Win32 program. I have a problem, however, I can't seem to get the damn window to show the menu. I have Petzold's Win32 programming book and I'm doing everything he talked in the book - I've written my .rc file, set the wndclass.lpszMenuName to point to the menu I defined, but the menu just does not show up. Everything else is working right, just not this, worse yet, I don't even get any error when I compile!! This is driving me nuts, I did exactly what the book told me to do. But when I run my program, the menu just isn't there. I have a feeling I'm missing something obvious here, but it's often the obvious mistakes that's hard to find. I'm on Win98 using MSVC++ 6.0, if you could give me any help I'd appreciate it. Is there some very special thing you have to do to setup a menu under WIN32 ??? Thanks!! btw, here's my normal windows init code, "IDR_MENU1" is the name of the menu I defined in the .rc file.

WNDCLASSEX wndclass;


wndclass.cbSize        = sizeof(wndclass);
wndclass.style         = CS_HREDRAW / CS_VREDRAW / CS_OWNDC;
wndclass.lpfnWndProc   = WndProc;
wndclass.cbClsExtra    = 0;
wndclass.cbWndExtra    = 0;
wndclass.hInstance     = hInstance;
wndclass.hIcon         = LoadIcon(NULL, IDI_APPLICATION);
wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
wndclass.lpszMenuName  = "IDR_MENU1";
wndclass.lpszClassName = WndClassName;
wndclass.hIconSm       = LoadIcon(NULL, IDI_APPLICATION);


RegisterClassEx(&wndclass);


hwnd = CreateWindow(WndClassName,
                    AppName,
                    WS_OVERLAPPEDWINDOW /
                    WS_CLIPCHILDREN /
                    WS_CLIPSIBLINGS,
                    CW_USEDEFAULT,
                    CW_USEDEFAULT,
                    640, 480,
                    NULL, NULL,
                    hInstance,
                    NULL);


ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
      
Edited by - SomeCodeGuy on 1/24/00 2:14:53 AM Edited by - SomeCodeGuy on 1/24/00 2:16:02 AM

- code
Advertisement
Okay, I think I see the problem. Try this...

Change This

wndclass.lpszMenuName = "IDR_MENU1";

To This

wndclass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);

Your code above is sort of correct. The thing is, you can use either an integer or a string as an ID in a resource script. If you created you script with the resource editor, IDR_MENU1 is really just an integer becuase it is a proprocessor define. You will have to include the header file created by the resource editor though. It's usually something like resource.h.

Petzold uses the string method, but this can be confusing since the newer IDE tools use integers becuase of MFC. If you ever start using MFC, it uses the integer method.

Either method is just fine, and I guess it's a matter of preference. If you want my opinion, use integers. You'll find that they are the prefered method and they are easier to work with, especially with larger programs. It's also easier to add things like context sensitive help and other things.

Edited by - I-Shaolin on 1/24/00 3:34:55 AM
I-Shaolin,

Two words for you: YOU ROCK!!

Thank you so much for this little bit of enlightenment. I bow before you for my unworthyless. (hehe, just kidding, but I really do appreciate your quick help!!)

Knowing this, I can finally sleep at night again.

- code
Alternatively, you could have also gone into the resource editor and put quotes around IDR_MENU1.

Either way works, tho I-Shaolin''s approach is the most common.



Mason McCuskey
Spin Studios - home of Quaternion, 2000 GDC Indie Games Fest Finalist!
www.spin-studios.com
Founder, Cuttlefish Industries
The Cuttlefish Engine lets anyone develop great games for iPad, iPhone, Android, WP7, the web, and more!

This topic is closed to new replies.

Advertisement