Click here to Skip to main content
15,888,968 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I got the other software's Menu handle,but i want to know Menu's MenuItem whether is checked state or unchecked state,how to use windows api to get the other software's MenuItem state.

[DllImport("user32.dll")]
public static extern int GetMenuState(int hMenu, int wID, int wFlags);

private int MF_BYPOSITION = 0x400;

int it = GetMenuState(menuHandle, 2, MF_BYPOSITION );

I'm sure the menuHandle value is correct,but return value it aways equals -1,i can't find out the reason.
can anybody help me?
Posted
Updated 5-Jul-13 6:14am
v5

1 solution

I hope this isn't stating the obvious but by specifying MF_BYPOSITION, this means that the second parameter is the item index, which is a zero based index. If you have 2 items, they are numbered 0 and 1.

If you use MF_BYCOMMAND, then the second parameter is the command ID for the item of interest. If I was coding this, I would use MF_BYCOMMAND.
 
Share this answer
 
Comments
xuyunhai 5-Jul-13 22:36pm    
I will try it with the command ID,but maybe it's another way to get menuItem state,logically speaking,either will do!
but how can i get the command ID?
H.Brydon 5-Jul-13 23:00pm    
You would find it in the resource.h (or equiv) relevant to the .rc file.

Are you mixing C++ and C#? I don't know that the menuHandle is necessarily valid on the C# side. How do you know that?
xuyunhai 5-Jul-13 23:07pm    
I use c# code to get menu handle,and then use SPY++ tool to get the same,so i'm sure it correct.
what can i do now,use command ID to get menuitem state? how can i get the command ID?
H.Brydon 5-Jul-13 23:36pm    
Ah - it seems that the C++ code is not yours... That is a different problem with a different strategy. I know there is a way to get the resource ID for the menu items but I don't know offhand how to do it.

Use of MF_BYPOSITION might be a better way to do it then. Make sure you have the index correct, and I am still not convinced that the menuHandle is valid in C# land.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900