AleksandarH

PS - Context Menu

May 22nd, 2022 (edited)
984
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ENABLE MENU
  2. case ID_MENU_ENABLEMENU:
  3. {
  4.     HMENU hMenu = GetMenu(hWnd);
  5.     UINT res = GetMenuState(hMenu, ID_MENU_DISABLED, MF_BYCOMMAND);
  6.     if (res & MF_DISABLED)
  7.     {
  8.         EnableMenuItem(hMenu, ID_MENU_DISABLED, MF_BYCOMMAND | MF_ENABLED);
  9.     }
  10.     break;
  11. }
  12.  
  13. // DELETE MENU
  14. case ID_MENU_DELETE:
  15. {
  16.     HMENU hMenu = GetMenu(hWnd);
  17.     DeleteMenu(hMenu, ID_MENU_DELETED, MF_BYCOMMAND);
  18.     break;
  19. }
  20.  
  21. // INSERT MENU
  22. case ID_MENU_INSERT:
  23. {
  24.     HMENU hMenu = GetMenu(hWnd);
  25.     if (GetMenuState(hMenu, ID_MENU_MESSAGEBOX + 1, MF_BYCOMMAND) == -1)
  26.     {
  27.         MENUITEMINFO mii;
  28.         ZeroMemory(&mii, sizeof(mii));
  29.         mii.cbSize = sizeof(mii);
  30.         mii.fMask = MIIM_ID | MIIM_TYPE | MIIM_STATE;
  31.         mii.wID = ID_MENU_MESSAGEBOX + 1;
  32.         mii.fType = MFT_STRING;
  33.         mii.dwTypeData = const_cast<char*>("Inserted");
  34.         mii.fState = MFS_ENABLED;
  35.         InsertMenuItem(hMenu, ID_MENU_ENABLEMENU, FALSE, &mii);
  36.     }
  37.     break;
  38. }
  39.  
  40. // RIGHT BUTTON DOWN
  41. case WM_RBUTTONDOWN:
  42. {
  43.     HMENU hMenu = LoadMenu(hInst, MAKEINTRESOURCE(IDC_WINDOWSPROJECT2));
  44.     HMENU hSubMenu = GetSubMenu(hMenu, 2);
  45.     POINT pt = { LOWORD(lParam), HIWORD(lParam) };
  46.     ClientToScreen(hWnd, &pt);
  47.     (hSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hWnd, NULL);
  48.     DestroyMenu(hMenu);
  49. }
  50. break;
RAW Paste Data Copied