Hi,
Can anyone show me how to create the drop down menu from the menu bar? This is what I have so far.


invoke CreateMenu
mov hMenu,eax
invoke AppendMenu,hMenu,MF_STRING,IDM_File,addr MenuFile
invoke SetMenu,hWnd,hMenu

I am able to get the top level menu bar (File) but I do not know how to make it drop down to show the other options(New, Open, Save.......etc).

Thank You!
Posted on 2003-01-01 21:55:02 by bgong68
Posted on 2003-01-02 01:51:34 by bazik
Hi Bazik,
Thanks for pointing me in the right direction. I actually did look at your code example from a search previously before posting this question but I was running into problems and was unable to figure out the solution. When I substituted CreatMenu with CreatePopupMenu I did not get any menu at all. I used your code example as a guideline.

call CreatePopupMenu ;your code example
mov hMenu, eax
invoke AppendMenu, hMenu, MF_STRING, ID_1, addr Item1
invoke AppendMenu, hMenu, MF_STRING, ID_2, addr Item2
invoke AppendMenu, hMenu, MF_SEPARATOR, 0, 0
invoke AppendMenu, hMenu, MF_STRING, ID_3, addr Item3


invoke CreatePopupMenu ;this is what I tried to do
mov hMenu,eax
invoke AppendMenu, hMenu, MF_STRING,IDM_File, addr MenuFile
invoke AppendMenu, hMenu, MF_STRING,IDM_New, addr MenuNew
invoke AppendMenu, hMenu, MF_STRING, IDM_Open, addr MenuOpen

Would you please give me a little more detail as to what I am doing wrong?
Thank You
Posted on 2003-01-02 17:18:34 by bgong68
bgong,
did you use TrackPopupMenu as in the post Bazik pointed you to or are you trying to use SetMenu?
as your AppendMenu code goes, it looks fine and will work if you use TrackPopupMenu
Posted on 2003-01-02 17:26:28 by Gunner
Hi Gunner,
Sorry I left that line out. I am using TrackPopupMenu.

invoke CreatePopupMenu ;this is what I tried to do
mov hMenu,eax
invoke AppendMenu, hMenu, MF_STRING,IDM_File, addr MenuFile
invoke AppendMenu, hMenu, MF_STRING,IDM_New, addr MenuNew
invoke AppendMenu, hMenu, MF_STRING, IDM_Open, addr MenuOpen
invoke TrackPopupMenu, hMenu, TPM_LEFTALIGN, pt.x, pt.y, 0, hWnd, 0

When I use this code I lose the menu bar and what I get is a pop up menu in the top left corner of the screen and when I click it then my window appears. How do I keep the menu bar(File) and get it to drop down(New, Open) with the other options?
Thank You
Posted on 2003-01-03 00:10:17 by bgong68
Originally posted by bgong68
I am able to get the top level menu bar (File) but I do not know how to make it drop down to show the other options(New, Open, Save.......etc).

Am I understanding you right when I say you just want to create a normal menu like in notepad or any other windows program? If yes, this has not much to do with the TrackPopupMenu style menus. The file menu is a submenu (MF_POPUP style). This means that the menu item can have childs. When you click it, windows automatically creates the popup menu with the childs of the File menu.

To create these items at runtime, you can use the usual menu item creation functions but with the handle of the File submenu as the parent.
However if your menu is not dynamic (or most of it isn't) it's *a lot* easier to create a menu resource, load it and assign it to your window. Iczelion probably has a tutorial on it.

Thomas
Posted on 2003-01-05 13:27:30 by Thomas
Hi Thomas,
Yes, what I am trying to do is create a regular menu like in notepad. Thanks for your help. I have a better understanding of what I need to do. I have created menus with a resource file but I wanted to learn how to do it directly in the source code.
Posted on 2003-01-05 20:40:27 by bgong68
Ahhhh, now I get what you are trying to do, try this:

When you are filling in your WNDCLASSEX structure for your class (window), you need to make wc.lpszMenuName = NULL then right before you create your window...

for menu 1:



invoke CreateMenu ; Create menu bar
mov ebx, eax ;
invoke CreatePopupMenu ; Create View menu
mov esi, eax ;

invoke AppendMenu, ; Toplevel menu - View
ebx, ;
MF_POPUP, ;
esi, ;
addr mnuView ;

invoke AppendMenu, ; Submenu - Collapse
esi, ;
MF_STRING, ;
0, ;
addr mnuCollapseTree ;

invoke AppendMenu, ; Submenu - Expand
esi, ;
MF_STRING, ;
1, ;
addr mnuExpandTree ;


for Menu 2:


invoke CreatePopupMenu ; Create Help menu
mov esi, eax ;

invoke AppendMenu, ; Toplevel menu Help
ebx, ;
MF_POPUP, ;
esi, ;
addr mnuHelp ;

invoke AppendMenu, ; Submenu - Contents
esi, ;
MF_STRING or MF_GRAYED, ;
4, ;
addr mnuContents ;

invoke AppendMenu, ; Submenu - Index
esi, ;
MF_STRING or MF_GRAYED, ;
5, ;
addr mnuIndex ;


and in your CreateWindowEx, pass the handle returned from CreateMenu (in the example ebx) to the 10th parameter for the menu, ex..



invoke CreateWindowEx,
WS_EX_APPWINDOW,
addr WndClsMain,
addr AppName,
WS_CAPTION or WS_CLIPCHILDREN or WS_MAXIMIZEBOX or WS_MINIMIZEBOX\
or WS_SYSMENU or WS_SIZEBOX or WS_VISIBLE,
esi,
edi,
600,
411,
NULL,
ebx, ; <---- handle to menu here
hInstance,
NULL


Make sense? Read the PSDK if you have it!
Hope this helped!
Posted on 2003-01-05 21:06:26 by Gunner
Hi Gunner,
This is EXACTLY what I wanted to learn! This will make a VERY good example for people who want to learn how to create the menu without a resource file.
Thank You!
Posted on 2003-01-06 21:08:08 by bgong68
thank you.. thank you.. thank you.. thank you.. thank you.. thank you.. thank you.. thank you..

oh and again thank you..
Posted on 2003-09-18 05:23:18 by devilsclaw
When using the explicit method (not resources) to build menus as in Gunner's example, how do you insert separators?
Posted on 2003-09-21 15:22:48 by msmith
Nevermind, I figured it out myself. It is:



invoke AppendMenu,[Popup1],MF_SEPARATOR,0,0


Thanks anyway!
Posted on 2003-09-21 15:30:05 by msmith