Jump to content
Tuts 4 You

WM_MEASUREITEM problem


LCF-AT

Recommended Posts

Hi guys,

I have a new problem found at WM_MEASUREITEM message and using the content of MEASUREITEMSTRUCT.itemData.

I created a normal popmenu with ownerdraw flag and at WM_MEASUREITEM & WM_DRAWITEM I am using the content of itemData of both structs (DRAWITEMSTRUCT and MEASUREITEMSTRUCT) to read the menu string and draw it.But anyhow its working diffrent so I dont get the same results.For my popmenu everything works well and the menu strings are comletely inside of itemData to see but when I am also using a second normal main menu with ownerdraw flag then I dont have the whole menu string inside of itemData and I got only ONE letter and the menu does also show only one letter for each menu entry.The main menu I created in the resources of WinASM.So my question is why I dont have the full menu string X inside of the itemData from my main menu in this case?For popup menu I have it.Thats a problem because I need to handle the string lenghts of menu entrys at WM_MEASUREITEM message to calc the right size of it.

Example:

MeasureItem proc...
...
Invoke lstrlen,[edi].MEASUREITEMSTRUCT.itemData
mov ecx,eax
Invoke GetTextExtentPoint32,hDCs,[edi].MEASUREITEMSTRUCT.itemData,ecx,addr TextSize
....

Below 2 pics of main menu and popup menu.Both using same code of measure & drawitem itemData.

N1.png.1de14422d3516570b93db197c4be1070.pngN2.png.36d5434d28a04de8fa355f4d865fb5d7.png

Does anyone know why I am getting diffrent results from itemData content?So I could also use GetMenuString function instead itemData content but for this function I need the menuhandle X what is bad if I am using more than one menus.So I would still like to use the itemData content for all menus to read the menu strings inside without using a extra Menu function with handle X.How can I fix this problem now?I only method what does work is using ModifyMenu function at WM_INITDIALOG.....

	.if	uMsg == WM_INITDIALOG
		invoke GetMenu,hWnd
		mov menuhandle,eax
		invoke ModifyMenu,menuhandle,10011,MF_OWNERDRAW,10011,chr$("Tuts4you")

....then it works again...

N3.png.0584b029d6b8dbd3f756d885a1cb6eeb.png

...but then I have to double the menu work so its already created in the resoureces.Maybe its any resources issue but I dont know yet how to fix it you know.Maybe you have any idea.

Thank you and greetz

Link to comment

Just a quick thought/idea ... did you try to put/apply owner-draw flag also for menu item in resources?
This way it should send/call the WM_MEASUREITEM for every items and your processing should be the same.

[EDIT]
Sorry, re-reading your message, you're already using ownerdrawn flag for your menu in resources ... so my previous answer is not useful.

Anyway, itemData is a "place" to put custom information and, by default, as far as I remember, it should be empty/uninitialized and/or system-reserved ... unless you put something in it. That's why you actually *have to* modify the resources' menu to set it explicitly.

I found this maybe useful quote:  https://docs.microsoft.com/en-us/windows/desktop/menurc/using-menus

Quote

Setting the Owner-Drawn Flag

    You cannot define an owner-drawn menu item in your application's resource-definition file. Instead, you must create a new menu item or modify an existing one by using the MFT_OWNERDRAW menu flag.

    :

    By setting the appropriate members of the MENUITEMINFO structure, you can associate an application-defined value, which is called item data, with each menu item. To do so, specify the MIIM_DATA value for the fMask member and the application-defined value for the dwItemData member.

 You created popup menu straight by code, right (not using resources) ?

You could use the SetMenuItemInfo (as suggested in the quoted link) to set only the itemdata ... without having to re-set the item text again.

--

 It's a lot I don't play with this stuff, so everyone is very welcome to correct me :)

 Best Regards,
 Tony

 

Edited by tonyweb
  • Like 1
Link to comment

Hello tonyweb,

thank you for trying to help me.Ok,so I think I got it working now with your infos and putting menu string into itemData instead of dwTypeData of MENUITEMINFO.Now I get all menu string to see in my menu correctly as I wanted. 😃 Not using menu from resources now and I just used functions to create it.Always this strange diffrent issues / problems if I use any resources control or no menu but I thought already that this depends on it as you said tony.Thanks again.

PS: Yes,the popup I created by code and the main menu above in resources.I thought it would be easier to create a menu in resources to save coding that parts also the part where I can directly set acceletators shortcuts.Just need to find out now how to put the shortcuts automatically at the end after the menu string like this....

Exit                F4

.....using Ownerdraw.

greetz

 

Link to comment

Hi again,

just have 2 small addon questions about ownerdraw & measureitem.

1.) How to handle this shortcuts in a menu to set them on the right side in if use ownerdraw?I only can set the menu string name like "Menu 1     F3" but need to set spaces between.Is there any standart way to set / handle this shortcut entrys in a menu?

2.) What is the message in a ownerdraw if I move the mouse pointer over a button to get triggerd?On Windows mode the buttons does change the color if I move the mouse over but in the DRAWITEMSTRUCT I cant find any message to catch that.Or have I to subclass all buttons and checking WM_MOUSEMOVE?

Thanks again & greetz

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...