How to disable the "Move system" menu item?

On Microsoft Windows, this works:

 mnu := GetSystemMenu(h, false);
 EnableMenuItem(mnu, SC_CLOSE, MF_BYCOMMAND or MF_GRAYED);

But this does not work:

 mnu := GetSystemMenu(h, false);
 EnableMenuItem(mnu, SC_MOVE, MF_BYCOMMAND or MF_GRAYED);

Therefore, I know how to disable the Close menu item in a window, but not the Move item. How to do it?

Update

Of course, one alternative to using the very nice EnableMenuItem function is to use SetMenuItemInfo:

  FillChar(info, sizeOf(info), 0);
  with info do
  begin
    cbSize := sizeOf(info);
    fMask := MIIM_STATE;
    fState := MFS_GRAYED;
  end;
  SetMenuItemInfo(mnu, SC_MOVE, false, info);

But this again works fine for SC_CLOSE, but not for SC_MOVE!

Update 2

Despite the fact that the problem is solved in the sense that a working code was found that "does the job", so to speak, it would be interesting to hear hypotheses about the cause of the problem: why does SC_CLOSE work, but not SC_MOVE?

+5
source share
2

, , ModifyMenu DeleteMenu:

   HMENU mnu = GetSystemMenu(hWnd, false);
   DeleteMenu(mnu, SC_MOVE, MF_BYCOMMAND);

   HMENU mnu = GetSystemMenu(hWnd, false);
   MENUITEMINFO info = { sizeof(MENUITEMINFO) };
   TCHAR name[256] = _T("Cannot move");
   info.fMask = MIIM_TYPE;
   info.dwTypeData = name;
   info.cch = sizeof(name) / sizeof(TCHAR);
   GetMenuItemInfo(mnu, SC_MOVE, false, &info);
   ModifyMenu(mnu, SC_MOVE, MF_BYCOMMAND | MF_GRAYED, 0, info.dwTypeData);
+3

DeleteMenu(), ( ).

.

"", :

GetMenuString(hMenu, SC_MOVE, szMoveCaption, MAX_PATH, MF_BYCOMMAND);

:

RemoveMenu(hMenu, SC_MOVE, MF_BYCOMMAND);

"", InsertMenu()

InsertMenu(hMenu, 0, MF_BYPOSITION, SC_MOVE, szMoveCaption);

PS.

+4

All Articles