Author Topic: Problems with OWNERDRAW menu  (Read 3925 times)

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Problems with OWNERDRAW menu
« on: February 16, 2022, 04:12:36 AM »
   Hi guys. I've dealing with this strange issue where the dwTypeData member appears empty. I'm posting the code so you can see what i'm doint wrong.
Code: [Select]
    .elseif uMsg==WM_DRAWITEM
mov edi,lParam
assume edi:PTR DRAWITEMSTRUCT
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
invoke MessageBoxA,0,tmii.dwTypeData,0,MB_OK
invoke SHGetFileInfoA,tmii.dwItemData,0,addr shfi,sizeof shfi,SHGFI_SMALLICON
invoke SelectObject,[edi].hdc,shfi.hIcon
invoke DeleteObject,eax
invoke DrawIcon,[edi].hdc,[edi].rcItem.left,[edi].rcItem.top,shfi.hIcon
invoke DrawTextA,[edi].hdc,tmii.dwTypeData,-1,addr [edi].rcItem,DT_LEFT

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #1 on: February 16, 2022, 09:46:41 PM »
    After reading a bit od msdn information i found out that to retirieve the dwTypeData member of MENUITEMINFO there's little protocol for it, it's described in the following lines of code.
Code: [Select]
  .elseif uMsg==WM_DRAWITEM
mov edi,lParam
assume edi:PTR DRAWITEMSTRUCT
mov tmii.dwTypeData,0
mov tmii.cch,0
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
inc tmii.cch
invoke LocalAlloc,LPTR,tmii.cch
mov tmii.dwTypeData,eax
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
Still the dwTypeData member appears empty. does MFT_STRING combine with MFT_OWNERDRAW? or can't they be mixed?

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Problems with OWNERDRAW menu
« Reply #2 on: February 17, 2022, 12:57:46 AM »
You don't need to call GetMenuItemInfo in the WM_DRAWITEM.
If you've stored a pointer in dwItemData of the MENUITEMINFO structure (MIIM_DATA) you'll find it in the DRAWITEMSTRUCT member itemData.
Just have a look at the MSDN example for ownerdrawn menus.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #3 on: February 17, 2022, 01:41:36 AM »
   Hi Greenhorn. The problem is the dwTypeData member. It appears empty. Ty

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Problems with OWNERDRAW menu
« Reply #4 on: February 17, 2022, 02:37:42 AM »
Did you stored a value in dwItemData ? You also have to set the corresponding flags in the fMask member of the MENUITEMINFO. What do you see in the itenData member of the DRAWITEMSTRUCT?
Did you had a look at the example on MSDN ?
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

Greenhorn

  • Member
  • ***
  • Posts: 493
Re: Problems with OWNERDRAW menu
« Reply #5 on: February 17, 2022, 03:00:59 AM »
Attached my old version of ownerdrawn menus.
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #6 on: February 17, 2022, 04:08:19 AM »
   The menu looks terrific but the code is kinda complex. I'll see what I can get out of it. Thanks Greenhorn

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #7 on: February 17, 2022, 11:52:04 PM »
   Hi Guys. The following lines of cpde should work but dont. It's in accoordance with MSDN documentation. It gives invalid handle eorror. Can anyone tell me why?
Code: [Select]
    .elseif uMsg==WM_DRAWITEM
mov edi,lParam
assume edi:PTR DRAWITEMSTRUCT
mov tmii.cbSize,sizeof MENUITEMINFO
mov tmii.fMask,MIIM_ID or MIIM_STRING or MIIM_TYPE OR MIIM_DATA
mov tmii.fType,MFT_STRING
mov tmii.dwTypeData,NULL
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
inc tmii.cch
invoke LocalAlloc,LPTR,tmii.cch
mov tmii.dwTypeData,eax
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
invoke DrawTextA,[edi].hdc,tmii.TypeData,-1,addr [edi].rcItem,DT_LEFT
mov eax,TRUE
ret

jj2007

  • Member
  • *****
  • Posts: 13957
  • Assembly is fun ;-)
    • MasmBasic
Re: Problems with OWNERDRAW menu
« Reply #8 on: February 18, 2022, 12:01:40 AM »
It would be much easier to read with spaces after the comma:
GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
GetMenuItemInfoA, [edi].hwndItem, [edi].itemID, FALSE, addr tmii

So have you checked whether [edi].hwndItem has a valid value?

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #9 on: February 18, 2022, 02:38:28 AM »
   Yeah JJ. I've actually changed it to the original Menu Handle. Nothing seems to work. And i've tried to retrieve the dwItemData ( although its present in DRAWITEM Struct) and it worked. I've seen the same problem in StackOverflow and the solution presented is the same. Ty

TimoVJL

  • Member
  • *****
  • Posts: 1320
Re: Problems with OWNERDRAW menu
« Reply #10 on: February 18, 2022, 05:17:38 AM »
This C code is from working example:
Code: [Select]
void OnMeasureItem(HWND hwnd, MEASUREITEMSTRUCT * lpMeasureItem)
{
if (lpMeasureItem) {
// if (lpMeasureItem->itemHeight < 16)
// lpMeasureItem->itemHeight = 16;
lpMeasureItem->itemHeight = 24;
lpMeasureItem->itemWidth = 24;
}
return;
}

void OnDrawItem(HWND hwnd, const DRAWITEMSTRUCT * lpDrawItem)
{
if (lpDrawItem->CtlType == ODT_MENU) {
if (lpDrawItem->itemID < 10000) {
if (lpDrawItem->itemData) {
ImageList_Draw(g_hIml, lpDrawItem->itemData, lpDrawItem->hDC, 2, 2, ILD_NORMAL );
}
} else {
//FillRect(lpDrawItem->hDC, &lpDrawItem->rcItem, hBkBrush);
SetBkMode(lpDrawItem->hDC, TRANSPARENT);
char *p = (char*)lpDrawItem->itemData;
DrawText(lpDrawItem->hDC, (char*)lpDrawItem->itemData, -1, (RECT*)&lpDrawItem->rcItem, 0);
}
}
return;
}
May the source be with you

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #11 on: February 18, 2022, 06:34:33 AM »
    Sorry man. That doesn't help me much. ty anyway

TimoVJL

  • Member
  • *****
  • Posts: 1320
Re: Problems with OWNERDRAW menu
« Reply #12 on: February 19, 2022, 12:10:47 AM »
If we don't know what you are after, it's hard to help :sad:
May the source be with you

xandaz

  • Member
  • ****
  • Posts: 529
  • I luv you babe
    • My asm examples
Re: Problems with OWNERDRAW menu
« Reply #13 on: February 19, 2022, 04:41:09 AM »
   Thanks all for help me out. Now i'm facing a new problem. Only the first dwTypeData gets Drawn.The other members of the menu seem to be overwritten by the others members. the code is as follows.
Code: [Select]
    .elseif uMsg==WM_DRAWITEM
mov edi,lParam
assume edi:PTR DRAWITEMSTRUCT
.if [edi].itemAction==ODA_DRAWENTIRE
invoke Beep,1000,100
mov tmii.cbSize,sizeof MENUITEMINFO
mov tmii.fMask,MIIM_FTYPE or MIIM_ID or MIIM_STRING or MIIM_DATA
mov tmii.dwTypeData,0
mov tmii.cch,0
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
inc tmii.cch
invoke LocalAlloc,LPTR,tmii.cch
mov tmii.dwTypeData,eax
invoke GetMenuItemInfoA,[edi].hwndItem,[edi].itemID,FALSE,addr tmii
invoke DrawTextA,[edi].hdc,tmii.dwTypeData,-1,addr [edi].rcItem,DT_LEFT
mov eax,TRUE
ret
.endif
   The dwTypeData members seem to have a height that overfills the other members.
« Last Edit: February 19, 2022, 07:14:09 AM by xandaz »

mikeburr

  • Member
  • **
  • Posts: 189
Re: Problems with OWNERDRAW menu
« Reply #14 on: February 19, 2022, 08:46:31 AM »
1) dont use assume .. you keep forgetting to assume nothing ...also its not compatible with 64 bit afaik shd you wish to convert later
2) i suspect the invoke ... API ...might well alter  edi .. you cd test this by displaying edi before and after .. i know quite a few of them do and esi
regards mike b