PDA

View Full Version : WinAPI menu



PowersWithin
08-21-2009, 10:46 AM
I've written a C++ program in Visual Studio 2008 using OpenGL, GLUT, and GLUI. I wish to add a winAPI menu to the top of the window (not the popup ones). I'm wondering how I should go about in doing this? Thanks!

Milsom
08-21-2009, 01:20 PM
what do you mean by not the pop up ones?

PowersWithin
08-21-2009, 01:31 PM
Like I want the ones that appear on top of the window instead of the right click or middle click menus.

Milsom
08-21-2009, 01:42 PM
lol ok

1- create a resource for the menu, goto resource view and create a menu into the project. Editing the menu is simple

2- make sure resource.h is included in where you are creating the window

3- where you create and register the class add the name of the menu resource ( for example where iv bolded )


m_hInst = instance;

// Register your window "class" with Windows
WNDCLASS wc;
//wc.cbSize = sizeof(WNDCLASSEX);
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = 0;
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hIcon = 0;
wc.hInstance = instance;
wc.lpfnWndProc = wndproc;
wc.lpszClassName = L"name";
wc.lpszMenuName = MAKEINTRESOURCE(IDR_MENU1);
wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
if ( 0 == RegisterClass( &wc ) )
throw std::runtime_error( "RegisterClass failed" );


4- in callback do



switch ( msg )
{
case WM_COMMAND:
{
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case **menu button id**:
{
// code here for button
}
break;
}
}
}

PowersWithin
08-24-2009, 10:02 AM
Thank you, that's just what I needed :D