Click here to Skip to main content
15,878,959 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hy I am trying to disable/enable an item menu in win32 project .
my code :

C++
EnableMenuItem(GetMenu(hh), ID_FILE_SAVE,MF_ENABLED);


but it doesnt work . why ?
I dont understand . pleas help me
Posted
Comments
Malli_S 3-Oct-12 8:38am    
What error you're getting? What does GetLastError() returns ?
Richard MacCutchan 3-Oct-12 8:38am    
Are you sure that ID_FILE_SAVE is on your main menu?

You probably are using the wrong menu handle as the first parameter to the EnableMenuItem function.
Maybe you need to use the GetSubMenu function also.

Try this -
EnableMenuItem(GetSubMenu(GetMenu(hh), 0), ID_FILE_SAVE, MF_DISABLED | MF_GRAYED);

Here 0 is the position of the required sub-menu.
 
Share this answer
 
Comments
Jochen Arndt 4-Oct-12 7:17am    
Good catch: +5.
See this link[^] and see the sample inside.

Another resource[^] that could help...

Good luck!
 
Share this answer
 
It should be like this, otherwise the system does not know how to interpret the second parameter.

C++
EnableMenuItem(GetMenu(hh), ID_FILE_SAVE, MF_BYCOMMAND | MF_ENABLED);
 
Share this answer
 
Comments
Jochen Arndt 4-Oct-12 7:20am    
You are basically right but this will not solve the problem because MF_BYCOMMAND is null.

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