News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Godamn Menus....

Started by xandaz, December 25, 2013, 12:03:02 AM

Previous topic - Next topic

xandaz

  Hey peas. I wasnt even doing anything too complicated. Just a menu bar with 3 sub menus. The submenus don't show. Remember i'm that distracted guy that can't see the obvious?
  Can someone see in the procedure why the sumenu don't show?
ProcessWMC  PROTO   :DWORD

.const
MII         TYPEDEF     MENUITEMINFO

noMenuBarItems      equ         3
noMenuFileItems     equ         5
noMenuToolsItems    equ         1
noMenuHelpItems     equ         3

; ++++ File Menu ++++
IDM_OPEN            equ         1000h
IDM_EXPORT          equ         1001h
IDM_EXIT            equ         1002h
; ++++ Tools Menu ++++
IDM_NOTHING         equ         1003h
; ++++ Help Menu ++++
IDM_HELP         equ         1004h
IDM_ABOUT           equ         1005h

.data
hMenuBar    dd          ?
hMenuFile   dd          ?
hMenuTools  dd          ?
hMenuHelp   dd          ?

MIIMenuBar  MII     <sizeof MII,MIIM_TYPE,MFT_STRING,0,?,?,?,?,?,offset szFile,sizeof szFile/2-2>
            MII     <sizeof MII,MIIM_TYPE,MFT_STRING,MFS_GRAYED,?,?,?,?,?,offset szTools,sizeof szTools/2-2>
            MII     <sizeof MII,MIIM_TYPE,MFT_STRING,0,?,?,?,?,?,offset szHelp,sizeof szHelp/2-2>
           
UCSTR       szFile,"File",0
UCSTR       szTools,"Tools",0
UCSTR       szHelp,"Help",0

MIIMenuFile MII     <sizeof MII,MIIM_TYPE+MIIM_ID,MFT_STRING,0,IDM_OPEN,0,?,?,?,offset szOpen,sizeof szOpen/2-2>
            MII     <sizeof MII,MIIM_TYPE,MFT_SEPARATOR,0,0,?,?,?,?,?,?>
            MII     <sizeof MII,MIIM_TYPE+MIIM_ID,MFT_STRING,0,IDM_EXPORT,0,?,?,?,offset szExport,sizeof szExport/2-2>
            MII     <sizeof MII,MIIM_TYPE,MFT_SEPARATOR,0,0,0,0,0,0,0,0>
            MII     <sizeof MII,MIIM_TYPE+MIIM_ID,MFT_STRING,0,IDM_EXIT,0,?,?,?,offset szExit,sizeof szExit/2-2>                 
UCSTR       szOpen,"Open",0
UCSTR       szExport,"Export",0
UCSTR       szExit,"Exit",0

MIIMenuTools    MII <sizeof MII,MIIM_TYPE+MIIM_ID+MIIM_STATE,MFT_STRING,MFS_GRAYED,IDM_NOTHING,0,?,?,?,offset szNothing,sizeof szNothing/2-2>

UCSTR       szNothing,"Nothing...",0

MIIMenuHelp MII     <sizeof MII,MIIM_TYPE+MIIM_ID,MFT_STRING,0,IDM_HELP,0,?,?,?,offset szHelp,sizeof szHelp/2-2>
            MII     <sizeof MII,MIIM_TYPE,MFT_SEPARATOR,0,0,0,0,0,0,0,0>
            MII   <sizeof MII,MIIM_TYPE+MIIM_ID,MFT_STRING,0,IDM_ABOUT,0,?,?,?,offset szAbout,sizeof szAbout/2-2>

;UCSTR       szHelp,"Help",0
UCSTR       szAbout,"About",0


.code

ProcessWMC  PROC    hWnd:DWORD

    invoke  CreateMenu
    mov     hMenuBar,eax
    invoke  SetMenu,hWnd,eax
    invoke  CreatePopupMenu
    mov     hMenuFile,eax
    invoke  CreatePopupMenu
    mov     hMenuTools,eax
    invoke  CreatePopupMenu
    mov     hMenuHelp,eax

    lea     esi,MIIMenuBar
    mov     ecx,noMenuBarItems
    push    hMenuHelp
    push    hMenuTools
    push    hMenuFile
loop_0:
    pop     [esi.MII].hSubMenu
    push    ecx
    invoke  InsertMenuItem,hMenuBar,-1,TRUE,esi
    add     esi,sizeof MII
    pop     ecx
    dec     ecx
    jcxz    end_loop_0
    jmp     loop_0
end_loop_0:
    lea     esi,MIIMenuFile
    mov     ecx,noMenuFileItems
loop_1:
    push    ecx
    invoke  InsertMenuItem,hMenuFile,-1,TRUE,esi
    add     esi,sizeof MII
    pop     ecx
    dec     ecx
    jcxz    end_loop_1
    jmp     loop_1
end_loop_1:
    lea     esi,MIIMenuTools
    mov     ecx,noMenuToolsItems
loop_2:
    push    ecx
    invoke  InsertMenuItem,hMenuTools,-1,TRUE,esi
    add     esi,sizeof MII
    pop     ecx
    dec     ecx
    jcxz    end_loop_2
    jmp     loop_2
end_loop_2:   
    lea     esi,MIIMenuHelp
    mov     ecx,noMenuHelpItems
loop_3:
    push    ecx
    invoke  InsertMenuItem,hMenuHelp,-1,TRUE,esi
    add     esi,sizeof MII
    pop     ecx
    dec     ecx
    jcxz    end_loop_3
    jmp     loop_3
end_loop_3:       
    invoke  DrawMenuBar,hWnd
    ret

lasterz

jj2007

The good news is that all API calls succeed. The bad news is it doesn't work, indeed :(

Why so complicated? This is simple and works:

  SWITCH uMsg
  CASE WM_CREATE        ; this message serves to initialise your application
        mov esi, rv(CreateMenu)        ; create the main menu
        mov edi, rv(CreateMenu)        ; create a sub-menu
        invoke AppendMenu, esi, MF_POPUP, edi, chr$("&File")                ; add it to the main menu
        invoke AppendMenu, edi, MF_STRING, 101, chr$("&New")                ; and add
        invoke AppendMenu, edi, MF_STRING, 102, chr$("&Save")                ; two items
        invoke SetMenu, hWnd, esi                                ; attach menu to main window

xandaz

   Yeah...JJ... When i read the manual, those functions are treated as obolete. But that's the method right? Can you apply it in vista or higher? that's why i use InsertMenuItem. I can show you all of these small app attempts that use the same loop type of procedure and they work. I was just looking for someone that had the clear mind to see what i did wrong...
   I dont usually use macros either. is that stupid? i can't even remember the number of times i coded hex2mem in my app-attempts.

xandaz

   Thanks man....ALL HAIL M32!!!!

xandaz

   so.... remember what i first said about distracted and not seeing the obvious. The mii's for the main menu didn't have the MIIM_SUBMENU flag. All it required was a clear mind. Mine's a dark-grey cloud.
   thanks all

jj2007

Quote from: xandaz on December 25, 2013, 01:51:12 AM
   Yeah...JJ... When i read the manual, those functions are treated as obolete.

Where did you read that? They work on Win7 (32+64 bit), and I am sure also on Win8.1...

QuoteI dont usually use macros either. is that stupid? i can't even remember the number of times i coded hex2mem in my app-attempts.

That is partly a matter of taste, partly of productivity. Which one is easier to code/understand/maintain?
invoke AppendMenu, esi, MF_POPUP, edi, chr$("&File")
invoke AppendMenu, esi, MF_POPUP, edi, addr Item1


I like your pic with your son. Merry Christmas to you.

dedndave

yah - they are marking some of the menu functions as obsolete
but, if you want your app to work on XP and newer OS's, you'll avoid the newer ones - lol

like Jochen showed you
CreateMenu to create the main menu
CreatePopupMenu to create sub-menus
AppendMenu to "connect" the sub-menus to the main menu
AppendMenu to add menu items

if a sub-menu has a drop-down, use CreatePopupMenu/AppenMenu just like it was a sub-menu

dedndave

i am also learning that, if i want to start a "real" application, start with UNICODE
it's much easier than converting it to UNICODE later on

what that means is that you may be better off to create the menu in resource
because the advantage of creating them in code is gone if you use UNICODE strings

of course, you will still have code for modifying them during run-time

xandaz

   Hay... sorry for replying late. Yeah... i thought i had read that... i don't know how...i was really picturing it. So it's alright. But the method i used works fine as well... So...
   ...InsertMenuItem is something to avoid?

dedndave

no - i sometimes use it to modify an existing menu
for example, i may want to change the text of a menu item
unfortunately, they don't really give you a good way to do that
but, you can use DeleteMenuItem, then replace the item with InsertMenuItem

the main difference between AppendMenu and InsertMenuItem is position
i use AppendMenu if i want to add something at the end of a menu
otherwise, i use InsertMenuItem

when you are initially building a menu, there is no need for InsertMenuItem
because you can start at the top and work your way down

xandaz

   Thanks for the reply mate... I'm struggling to get back online... haven't been practicing my asm smalltime habilities.

Gunther

Hi xandaz,

Quote from: xandaz on March 28, 2014, 08:52:15 AM
   Thanks for the reply mate... I'm struggling to get back online... haven't been practicing my asm smalltime habilities.

good to see you again after quite a long break.  :t Go forward.

Gunther
You have to know the facts before you can distort them.

xandaz

   The thing that got me into the whole OWNERDRAWn menu thing was that the spacings are different from Vista to XP. I was working on this drawing experience kinda thing and the menus where wierd looking. I didnt use the standard system metrics and the icons didnt fit the rect.
   It's kinda going slowly... It crashes on the edit menu because of the separators. i'm still working on that.

dedndave

Chib777 did a nice library a while back called xxcontrols
it has examples in C and in ASM

http://www.codeproject.com/Articles/17153/XXControls-Library-to-Develop-User-Interface