The menuitem, which id is MI_OPENBITMAP, is ower-drawn,
When calling OnDraw function, the x, y, right and bottom of DrawItemStruct.rcItem
are shown. And i found that the right is zero! So when calling DrawText, no text is being drawn.
Do anyone know why the right is zero? and what's the solution?

Thanks



================ Mosaic.rc ================
MAINMENU MENU DISCARDABLE
{

POPUP "&File"
{

MENUITEM "&Open Bitmap ", MI_OPENBITMAP
}
}

================ Mosaic.asm ================
.data
buffer byte 256 dup(?)

.code
WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD

.IF uMsg==WM_CREATE
invoke OnCreateMenu, hWnd
.ELSEIF uMsg==WM_MEASUREITEM
.if wParam == 0
push edi
mov edi, lParam
invoke OnMeasureItem, hWnd, MEASUREITEMSTRUCT ptr [edi]
pop edi
.endif
.ELSEIF uMsg==WM_DRAWITEM
.if wParam == 0
push edi
mov edi, lParam
invoke OnDrawItem, hWnd, DRAWITEMSTRUCT ptr [edi]
pop edi
.endif
.ELSE
invoke DefWindowProc,hWnd,uMsg,wParam,lParam
ret
.ENDIF
ret
WndProc endp


OnCreateMenu proc hWnd:DWORD

LOCAL mii : MENUITEMINFO
LOCAL lf : LOGFONT

invoke GetSubMenu, hMenu, 0
mov hMenu, eax

mov mii.fMask, MIIM_FTYPE
invoke GetMenuItemInfo, hMenu, MI_OPENBITMAP, FALSE, addr mii
or mii.fType, MFT_OWNERDRAW

invoke SetMenuItemInfo, hMenu, MI_OPENBITMAP, FALSE, addr mii

ret
OnCreateMenu endp



OnDrawItem proc hWnd:DWORD, dis:DRAWITEMSTRUCT
LOCAL clrPrevText : COLORREF
LOCAL clrPrevBkgnd : COLORREF
LOCAL hfntPrev : HFONT

PrintDec dis.rcItem.left
PrintDec dis.rcItem.top
PrintDec dis.rcItem.bottom
PrintHex dis.rcItem.right


mov eax, dis.itemState

.if eax & ODS_SELECTED
invoke GetSysColor,COLOR_HIGHLIGHTTEXT
mov ebx, eax
invoke SetTextColor, dis.hdc, ebx
mov clrPrevText, eax
invoke GetSysColor, COLOR_HIGHLIGHT
mov ebx, eax
invoke SetBkColor, dis.hdc, ebx
mov clrPrevBkgnd, eax
.elseif
invoke GetSysColor,COLOR_MENUTEXT
mov ebx, eax
invoke SetTextColor, dis.hdc, ebx
mov clrPrevText, eax
invoke GetSysColor, COLOR_MENU
mov ebx, eax
invoke SetBkColor, dis.hdc, ebx
mov clrPrevBkgnd, eax
.endif

mov eax, dis.rcItem.left
mov x, eax
mov eax, dis.rcItem.top
mov y, eax

invoke GetSystemMetrics,SM_CXMENUCHECK
add x, eax

invoke GetMenuString,hMenu,MI_OPENBITMAP,addr buffer,100,MF_BYCOMMAND
invoke DrawText, dis.hdc, addr buffer, -1, addr dis.rcItem, DT_CENTER

invoke SetTextColor, dis.hdc, clrPrevText
invoke SetBkColor, dis.hdc, clrPrevBkgnd
xor eax, eax
inc eax
.endif
ret

OnDrawItem endp


OnMeasureItem proc hWnd:DWORD, mis : MEASUREITEMSTRUCT
LOCAL hdc : HDC
LOCAL hfntOld : HFONT
LOCAL s : _SIZE

.if mis.itemID == MI_OPENBITMAP

invoke GetDC, hWnd
mov hdc, eax

invoke GetMenuString,hMenu,MI_OPENBITMAP,addr buffer,100,MF_BYCOMMAND
invoke lstrlen, addr buffer
mov ebx, eax
invoke GetTextExtentPoint32, hdc, addr buffer, ebx, addr s ; give logical unit

mov eax, s.px
mov mis.itemWidth, eax
mov eax, s.py
mov mis.itemHeight, eax

invoke ReleaseDC,hWnd, hdc

xor eax, eax
inc eax
.endif

ret

OnMeasureItem endp

Posted on 2002-04-29 11:39:05 by yoursguideline
The problem occur is due to the second passing argument in OnMeasureItem and OnDrawItem.

Instead of passing MEASUREITEMSTRUCT or DRAWITEMSTRUCT, pass the pointer of these structure as a argument.

It works for me!
Posted on 2002-04-29 14:01:42 by yoursguideline