News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Ownerdraw Separator doesn't work?!

Started by trp, May 28, 2005, 04:12:37 PM

Previous topic - Next topic

trp

Well,

> first of all I tell you that my english is not as proper, because I am from Germany.
> ok, so far, my problem seems to be very simple: an ownerdraw separator in a ownerdraw submenu doesn't work whatever i tried to fix this problem ...
> can anybody tell me what could be wrong with this?
> or can anybody post a working code sniplet that I can see what such a code section should look like??

thanks, trp  :green 

MichaelW

There is a menu demo by Ewayne Wagner in \masm32\examples\EXAMPLE6\ that might be of some help.
eschew obfuscation

trp

@MichelW:

> Thanks for the hint, but my menu is not a menu in a window, its a popup menu opening from a trayicon ...
> and its also build in the ownerdraw way  ::)

> everything works, but not the submenu separator ... any ideas how the code has to look like therefor??? (just for a submenu)


cheers ---trp---

trp

ok, lets take a look at the code:

NouveauMenu   proc  hWin:DWORD
LOCAL CntD  :DWORD       

szText Apropos,"À Propos de ...",0
szText Config,"Programmes",0
szText Conf,"Configuration",0
szText Opti,"Options",0
szText Sort,"Quitter",0
szText Internet,"Aide",0
szText hExec, "Exécuter...",0
szText hExec1, "Rechercher",0
szText hExec2, "Arrêter...",0
szText hExec4, "Explorateur",0

                  INVOKE GetPrivateProfileString,addr bufferR,addr bufferCHK1,addr buffer3, addr bufferRIN,sizeof bufferRIN,addr buffer5
                 .if byte ptr [bufferRIN] == "0"
                  mov hCheck1,0
                 .else
                  mov hCheck1,1
                 .endif

                  INVOKE GetPrivateProfileString,addr bufferR,addr bufferCHK,addr buffer3, addr bufferRIN,sizeof bufferRIN,addr buffer5
                 .if byte ptr [bufferRIN] == "0"
                  mov hCheck,0
                 .else
                  mov hCheck,1
                 .endif                 

                  INVOKE GetPrivateProfileString,addr bufferR,addr bufferMEN,addr buffer3, addr bufferRIN,sizeof bufferRIN,addr buffer5
                 .if byte ptr [bufferRIN] == "0"
                  mov hCheck2,0
                 .else
                  mov hCheck2,1
                 .endif

                  INVOKE GetPrivateProfileString,addr bufferR,addr bufferUTI,addr buffer3, addr bufferRIN,sizeof bufferRIN,addr buffer5
                 .if byte ptr [bufferRIN] == "0"
                  mov hCheck3,0
                 .else
                  mov hCheck3,1
                 .endif

                  INVOKE GetPrivateProfileString,addr bufferR,addr bufferR1,addr buffer3, addr bufferRIN,sizeof bufferRIN,addr buffer5
                 .if byte ptr [bufferRIN] == "1"
                  MOV bRadio1,1
                  invoke CheckRadioButton,hWin,IDC_R1,IDC_R3,IDC_R1
                 .elseif byte ptr [bufferRIN] == "2"
                  MOV bRadio1,2
                  invoke CheckRadioButton,hWin,IDC_R1,IDC_R3,IDC_R2
                 .elseif byte ptr [bufferRIN] == "3"
                  MOV bRadio1,3
                  invoke CheckRadioButton,hWin,IDC_R1,IDC_R3,IDC_R3
                 .endif
                  INVOKE GetPrivateProfileString,addr bufferR,addr bufferLST,addr buffer3, addr bufferRIN,sizeof bufferRIN,addr buffer5
                 .if byte ptr [bufferRIN] == "0"
                  mov bRadioL,0
                 .ELSE
                  MOV bRadioL,1
                 .ENDIF

                 invoke CreatePopupMenu
         mov hPopupMenu,eax
            INVOKE CreateMenu
            mov hPopupMenu1,eax
            INVOKE AppendMenu, hPopupMenu1,MF_OWNERDRAW or MF_ENABLED ,ID_ID,ADDR Config
            INVOKE AppendMenu, hPopupMenu1,MF_OWNERDRAW or MF_ENABLED,IDC_CHOIX,ADDR Opti
            INVOKE AppendMenu, hPopupMenu1,MF_OWNERDRAW or MF_ENABLED,IDC_INTER,ADDR Internet
            INVOKE AppendMenu, hPopupMenu1,MF_OWNERDRAW or MF_ENABLED,IDC_ABOUT,ADDR Apropos
            INVOKE AppendMenu, hPopupMenu1,MF_OWNERDRAW or MF_ENABLED,IDC_QUIT,ADDR Sort
            invoke AppendMenu, hPopupMenu, MF_OWNERDRAW or MFT_SEPARATOR,IDC_BIT,NULL
            INVOKE InsertMenu, hPopupMenu,0, MF_POPUP or MF_OWNERDRAW or MF_BYPOSITION  ,hPopupMenu1,MF_OWNERDRAW
            invoke ModifyMenu, hPopupMenu,0,    MF_BYPOSITION or MF_OWNERDRAW   ,0,addr Conf
            mov CntD,0
           .if hCheck3 == 1           
            INVOKE CreateMenu
            mov hPopupMenu2,eax
            INVOKE InsertMenu, hPopupMenu,1, MF_POPUP or MF_OWNERDRAW or MF_BYPOSITION ,hPopupMenu2,MF_OWNERDRAW
            invoke ModifyMenu, hPopupMenu,1, MF_BYPOSITION or MF_OWNERDRAW ,IDC_SH,addr Mprog
            invoke MenuLstU,hWin
            mov CntD,35
           .endif

            mov Titems,0
            mov TitemC,0
            mov TitemB,0
Ts:
           
            lea esi,Progs
            invoke wsprintf,addr buf,addr FrmtStr,Titems
            invoke lstrcat,esi,addr buf
            INVOKE GetPrivateProfileString,addr buffer1,esi,addr buffer3, addr buffer,sizeof buffer,addr buffer5
            invoke lstrcpy,addr Progs,addr ProgC

            cmp byte ptr [buffer],00h
            je Termi
           .if byte ptr [buffer] == "-"
            invoke AppendMenu,hPopupMenu,  MF_OWNERDRAW or MFT_SEPARATOR,IDC_BIT,NULL
            inc Titems
            add TitemB,20
            add TitemC,4
            JMP Ts
           .endif
           
            lea edi,Dest
            invoke wsprintf,addr buf,addr FrmtStr,Titems
            invoke lstrcat,edi,addr buf
            sub ecx,ecx
            MOV ecx,TitemB
            push ecx
            INVOKE GetPrivateProfileString,addr buffer1,edi,addr buffer3,  addr  [buffer01+ecx],20,addr buffer5
            invoke SHGetFileInfo,addr buffer,NULL,addr sh,sizeof sh,SHGFI_ICON ;or SHGFI_SMALLICON
            pop ecx
            invoke AppendMenu,hPopupMenu, MF_OWNERDRAW or MF_ENABLED   ,sh.hIcon,  addr  [buffer01+ecx]
            invoke lstrcpy,addr Dest,addr DestC

            mov eax,sh.hIcon
            mov ecx,TitemC
            mov [hIconeZ+ecx],eax
            inc Titems
            add TitemC,4
            add TitemB,20
            dec CntD
            jnz Ts
Termi:
            invoke AppendMenu,hPopupMenu, MF_OWNERDRAW or MFT_SEPARATOR,IDC_BIT,NULL
           .if hCheck2 == 1
            invoke AppendMenu,hPopupMenu,  MF_OWNERDRAW or MF_ENABLED,IDC_EXEC4,addr hExec4
            invoke AppendMenu,hPopupMenu, MF_OWNERDRAW or MF_ENABLED,IDC_EXEC1,addr hExec1
            invoke AppendMenu,hPopupMenu, MF_OWNERDRAW or MF_ENABLED,IDC_EXEC,addr hExec
            invoke AppendMenu,hPopupMenu, MF_OWNERDRAW or MF_SEPARATOR ,IDC_BIT,0
            invoke AppendMenu,hPopupMenu,  MF_OWNERDRAW or MF_ENABLED,IDC_EXEC2,addr hExec2
            invoke AppendMenu,hPopupMenu, MF_MENUBREAK or MF_OWNERDRAW,666,NULL
           .endif

invoke CreateSolidBrush,00F8F8F8h ;00F5F5F5h ;00FFFFFFh
mov MenuInfo.hbrBack,eax
mov MenuInfo.cbSize,SIZEOF MENUINFO
mov MenuInfo.fmask,MIM_BACKGROUND+MIM_APPLYTOSUBMENUS+MIM_STYLE+MIM_MAXHEIGHT
mov MenuInfo.dwstyle,MNS_NOCHECK
mov MenuInfo.cyMax,0
invoke SetMenuInfo,hPopupMenu,ADDR MenuInfo

mov MenuItem.cbSize,SIZEOF MENUITEMINFO
mov MenuItem.fMask, MIIM_FTYPE
mov MenuItem.fType,MFT_RIGHTORDER+MFT_OWNERDRAW
mov MenuItem.cbSize,sizeof MENUITEMINFO
invoke SetMenuItemInfo,hPopupMenu,0,TRUE,ADDR MenuItem
invoke SetMenuItemInfo,hPopupMenu,1,TRUE,ADDR MenuItem



ret
NouveauMenu   endp

MenuLstU   proc  hWin1:DWORD
LOCAL CntD  :DWORD

            mov CntD,10
            mov Titems,35
            mov TitemC,140 
            mov TitemB,700 
Ts1:
           
            lea esi,Progs
            invoke wsprintf,addr buf,addr FrmtStr,Titems
            invoke lstrcat,esi,addr buf
            INVOKE GetPrivateProfileString,addr buffer1,esi,addr buffer3, addr buffer,sizeof buffer,addr buffer5
            invoke lstrcpy,addr Progs,addr ProgC
            cmp byte ptr [buffer],00h
            je Term1
           .if byte ptr [buffer] == "-"
            invoke AppendMenu,hPopupMenu2,MFT_SEPARATOR,NULL,NULL
            inc Titems
            add TitemB,20
            add TitemC,4
            JMP Ts1
           .endif
            lea edi,Dest
            invoke wsprintf,addr buf,addr FrmtStr,Titems
            invoke lstrcat,edi,addr buf
            sub ecx,ecx
            MOV ecx,TitemB
            push ecx
            INVOKE GetPrivateProfileString,addr buffer1,edi,addr buffer3,  addr  [buffer01+ecx],20,addr buffer5
            invoke SHGetFileInfo,addr buffer,NULL,addr sh1,sizeof sh1,SHGFI_ICON or SHGFI_SMALLICON
            pop ecx
            invoke AppendMenu,hPopupMenu2, MF_OWNERDRAW,sh1.hIcon,  addr  [buffer01+ecx]
            invoke lstrcpy,addr Dest,addr DestC
            mov eax,sh1.hIcon
            mov ecx,TitemC
            mov [hIconeZ+ecx],eax
            inc Titems
            add TitemC,4
            add TitemB,20
            dec CntD
            jnz Ts1
Term1:

ret
MenuLstU   endp


this kind of code generates an ownerdraw separator - works (s. NouveauProc)

cmp byte ptr [buffer],00h
            je Termi
           .if byte ptr [buffer] == "-"
            invoke AppendMenu,hPopupMenu,  MF_OWNERDRAW or MFT_SEPARATOR,IDC_BIT,NULL
            inc Titems
            add TitemB,20
            add TitemC,4
            JMP Ts
           .endif


and this kind of code generates a simple separator - i see - but even i change the code that it looks like ownerdraw code, nothing appears?!?!  :dazzled: (s.MenuLstUProc)

je Term1
           .if byte ptr [buffer] == "-"
            invoke AppendMenu,hPopupMenu2,MFT_SEPARATOR,NULL,NULL
            inc Titems
            add TitemB,20
            add TitemC,4
            JMP Ts1
           .endif


this might help to solute this problem?!

trp

MichaelW

Don't you need to process the WM_MEASUREITEM and WM_DRAWITEM messages, and actually draw the separator?

MSDN: AppendMenu Function

MSDN: Using Menus
eschew obfuscation

pbrennick

trp,
I wonder if


invoke AppendMenu, hPopupMenu, MF_OWNERDRAW or MFT_SEPARATOR,IDC_BIT,NULL


should be


invoke AppendMenu, hPopupMenu1, MF_OWNERDRAW or MFT_SEPARATOR,IDC_BIT,NULL


Paul

trp

hi,

@michelw:

this is just a "cut off" code section, wm_measureitem and wm_drawitem are working correct, i can see this looking at the separators in the main trackpopup menu.

@pbrennick:

i thinks this should not be, because hPopupMenu and hPopupMenu1 are two different submenus :-)
but in both the separator doesn't work ...

thanks trp

pbrennick

I realize that they are 2 separate menues but you appear to be mixing them up.  Can you post the complete source so I can properly evaluate the problem?

Paul

trp

@pbrennick:

i posted the complete project (TrayIcon-1.zip).
thanks for the help,

trp

[attachment deleted by admin]