Skip to main content
GameDev.net gamedev.net
🔒 Locked

Win32 menu

Started by saisoft Oct 28, 2000 at 4:21 PM 14 replies 400+ views
Original Post
saisoft
saisoft
I made test resource file in notepad with the following: menu MENU { POPUP "Help" { MENUITEM "One",1 MENUITEM "Two",2 MENUITEM "Three" } I have this line in my window class code: winClass.lpszMenuName = "menu"; I also tried winClass.lpszMenuName = LoadMenu(hInstance, "menu"); I am not using numeric constants. The first way compiles and builds fine, but the menu is not shown on a overlappedwindow with vertical and horizontal scroll bars. the second way gives me a cast error Anyone help?
pUnkOuter
pUnkOuter
i think the only problem is that you have to use the DISCARDABLE keyword, i.e.

menu MENU DISCARDABLE
{
// etc....


------------------------
IUnknown *pUnkOuter

"Try the best you can
try the best you can
the best you can is good enough"
--Radiohead
------------------------IUnknown *pUnkOuter"Try the best you cantry the best you canthe best you can is good enough" --Radiohead
saisoft
saisoft
Thanks for replying, but that still did not work!!!!!!
Snyper
Snyper
Alright this msg board is pissing me off. Im having to edit it like a million times. :|

RC FILE
        
#inlcude <windows.h>

mymenu MENU DISCARDABLE
{
POPUP "File"
{
MENUITEM "Exit" 1000
}
}



And put these next two lines in winmain after you create the window.
HMENU hmymenu = LoadMenu( hInstance, "mymenu" );
ShowMenu( hWnd, hmymenu );

Snyper


Edited by - Snyper on October 28, 2000 5:50:41 PM
=============================Where's the 'any' key?=============================
saisoft
saisoft
Sorry, I included the windows.h file even though it is already included in my source code, it still did not work
Snyper
Snyper
Well you still need it in your rc file also. I found this out when i tried to do dialogs and it wouldnt compile. Turned out i needed the windows.h file in the rc file. I dont see why its not working. It works fine for me.

Snyper
=============================Where's the 'any' key?=============================
FordPrefect
FordPrefect
What is this ShowMenu function? It is not part of the win32 api. You can specify a window''s menu in several ways. The two most common involve specifying it in a paramater in the call to CreateWindow(Ex)(), or when the window''s class is registered.
Snyper
Snyper
Its not part of the win32 api is it? Well thats where you're wrong. If its not then how come it works when i include windows.h? Huh? And why does every win98 book i see mention it?

Snyper

Edited by - Snyper on October 28, 2000 11:55:45 PM
=============================Where's the 'any' key?=============================
Snyper
Snyper
Oh and i just looked in my windows 98 programming book and in the index it shows: ShowWindow() API function, 27, 132, 318, 470. Oh no this isn''t a win api funtion. heh.

Snyper
=============================Where's the 'any' key?=============================
Ironblayde
Ironblayde
saisoft: Are you passing the menu identifier as a parameter to CreateWindowEx()? You need to do that...

Snyper: Take it easy, man. Geez.

-Ironblayde
 Aeon Software

The following sentence is true.
The preceding sentence is false.
"Your superior intellect is no match for our puny weapons!"
The_C_Guy
The_C_Guy
This is how it is done.

(1) In the ".rc" file:

#include //The name of the .h file

MAINMENU MENU
{
MENUITEM "&Exit", CM_EXIT
}


(2) In the ".h" file:

#define CM_EXIT 1001

//Don't define the menu handle in this file.
//Example: #define MAINMENU 2001


(3) In the window creation:

WNDCLASS wcl;

wcl.lpszMenuName = "MAINMENU";



So, DONT USE ANY FUNCTION TO LOADING THE MENU. Just give the ID code you define in the ".h" file.

This is how I do all of my apps. If it does not work for you, you are doing it incorrectly.

BTW: I use Borland C++ 5 Pro to compile this but it should work with Microsoft.



Edited by - The_C_Guy on October 29, 2000 1:52:09 PM
http://www.crosswinds.net/~druidgames/resist.jpg
saisoft
saisoft
I figured it out. It was really stupid and simple. Being new to visual c++ probably caused this, but I just forgot to include the menu.rc in my project. But in my rc file, all I have is the definition of my menu. I do not have any header files. I just put this line in my class lpsz.MenuName = "menu"; and it came up fine. One other question though, if I create the menu by hand in notepad, how do u create the res file for your resources?

thanks alot
Ironblayde
Ironblayde
I''m not sure what you''re saying here. If I''m not mistaken the .res file is an output of the compiler. You don''t create it yourself. All your resource declarations, whether they be icons, string tables, menus, etc. go in the same .rc file. You can do this by hand in Notepad, but it''s easier to just use the commands within Visual C++. (Insert menu, "Resource...") Doing the .rc file in Notepad is probably good to do once or twice just so you''re familiar with the exact syntax of the resource file, but if you''re comfortable seeing it, just use the commands in Visual C++ to do it all for you.

-Ironblayde
 Aeon Software

The following sentence is true.
The preceding sentence is false.
"Your superior intellect is no match for our puny weapons!"
FordPrefect
FordPrefect
quote:
Original post by Snyper

Oh and i just looked in my windows 98 programming book and in the index it shows: ShowWindow() API function, 27, 132, 318, 470. Oh no this isn''t a win api funtion. heh.

Snyper


Yes, ShowWindow is indeed a win32 function. I was referring to ShowMenu, which is not, and should not work by just including windows.h


C:\Program Files\Microsoft Visual Studio\VC98\Include>grep "ShowMenu" *.h

C:\Program Files\Microsoft Visual Studio\VC98\Include>
Snyper
Snyper
Opps my bad i looked at the wrong one. It did say ShowMenu but i wrote the wrong one down. Next time ill try not to think when im half way asleep.

Snyper
=============================Where's the 'any' key?=============================
Snyper
Snyper
Well maybe its in windowsx.h (i dont remember) but i know it is an API funtion. Sorry if i sounded hostile. I didnt mean to sound like i was trying to bite your head off.

Snyper
=============================Where's the 'any' key?=============================

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.