Click here to Skip to main content
15,881,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I t5ried to disable a button of hmenu but it doesn't work..

What I have tried:

I tried:

HMENU hMenu = ::LoadMenu(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_MENU1));
	EnableMenuItem(hMenu, 0, MF_DISABLED | MF_GRAYED | MF_BYPOSITION);
Posted
Updated 20-Sep-20 22:13pm
Comments
Shao Voon Wong 21-Sep-20 3:35am    
Is your MFC application a SDI/MDI application?

It appears that calling LoadMenu returns something different than what is required. I just tried a few experiments and the following code does work:
C++
hMenu = GetMenu(hWnd);  // get the top level menu*
EnableMenuItem(hMenu, 0, MF_DISABLED | MF_GRAYED | MF_BYPOSITION);


*or use CWnd Class::GetMenu() | Microsoft Docs[^]

[edit]
The issue is that you were using the wrong system call. LoadMenu gets a handle to a menu resource in the executable file. Whereas GetMenu returns a handle to the actual menu object attached to your application's Window.
[/edit]
 
Share this answer
 
v2
I just made a tip about disabling the submenu of MFC SDI application.

Disable MFC SDI/MDI Submenu[^]
 
Share this answer
 

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