Reputation: 51
My problem in this code when Menu Item is Disable and then pass code "PostMessage" in Control Application to Crash because i need check menu Item is Enabled and then use PostMessage.
HandleMenu:= GetMenu(ParentAppHandle);
HandleMenu:= GetSubMenu(HandleMenu, 6 {menu item no});
item:= GetMenuItemID(HandleMenu , 12 {sub menu item no});
PostMessage(ParentAppHandle, WM_COMMAND, MakeWParam(item, 0), 0);
Upvotes: 1
Views: 1008
Reputation: 28499
Use the WinAPI function GetMenuState.
Example:
var
State: UINT;
begin
State:= GetMenuState(HandleMenu , 12, MF_BYPOSITION);
if (State and (MF_DISABLED or MF_GRAYED)) = 0 then
begin
// Menu Item is enabled
end
else
begin
// Menu Item is disabled
end;
Upvotes: 2