How to append menu item to string gadget context menu?

Just starting out? Need help? Post your questions and find answers here.
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

How to append menu item to string gadget context menu?

Post by Lord »

Hi!

How can an useless code posted by netmaestro here
(http://www.purebasic.fr/english/viewtop ... 13&t=60938)
made even more useless by appending a new menu item?

Code: Select all

; Yet another useless program from netmaestro

#WM_HOLYCONTEXTMENUBATMAN = #WM_APP + 1

#PU_Save = 9; ??? which number should be used?

Procedure HookProc(nCode, wParam, lParam)
 
  If (nCode = #HC_ACTION)
    *cwps.CWPSTRUCT = lParam
    Select *cwps\message
       
      Case #WM_CREATE
        szClass.s=Space(128)
        GetClassName_(*cwps\hwnd, @szClass, 127)
        If szClass="#32768"
          PostMessage_(WindowID(0), #WM_HOLYCONTEXTMENUBATMAN, *cwps\hwnd, 0) ; Must institute a delay before executing MN_GETMENU
        EndIf
       
    EndSelect
  EndIf
 
  ProcedureReturn CallNextHookEx_(0, nCode, wParam, lParam)
 
EndProcedure

Procedure WinProc(hwnd, msg, wparam, lparam)
  Static g_hHook
   
  Select msg

; ??? What msg has to be catched here?

    Case #WM_PARENTNOTIFY
      If wparam & $FFFF = #WM_RBUTTONDOWN ; Detect right-click on child windows
        With wp.POINT
          \x = lparam & $FFFF
          \y = lparam >> 16
        EndWith
        MapWindowPoints_( WindowID(0), #HWND_DESKTOP, @wp, 1)
        If WindowFromPoint_(PeekQ(@wp)) = GadgetID(0) ; Modify menu for only selected controls
          g_hHook = SetWindowsHookEx_(#WH_CALLWNDPROC, @HookProc(), #Null, GetCurrentThreadId_())
        EndIf
      EndIf
      ProcedureReturn 0
     
    Case  #WM_HOLYCONTEXTMENUBATMAN
      hwnd = wparam
      hmenu = SendMessage_(hwnd, #MN_GETHMENU,0,0) ; Get the hMenu and modify it
      RemoveMenu_(hmenu, 14, #MF_BYPOSITION)
      RemoveMenu_(hmenu, 13, #MF_BYPOSITION)
;       RemoveMenu_(hmenu, 12, #MF_BYPOSITION)        ; leave menubar
      RemoveMenu_(hmenu, 11, #MF_BYPOSITION)
      RemoveMenu_(hmenu, 10, #MF_BYPOSITION)
      RemoveMenu_(hmenu, 9, #MF_BYPOSITION)
      RemoveMenu_(hmenu, 8, #MF_BYPOSITION)
      Save$="Save..."
      AppendMenu_(hMenu, #MF_STRING, #PU_Save, @Save$); new menu item
       
     UnhookWindowsHookEx_(g_hHook)                ; So as not to affect submenus
     
  EndSelect
 
  ProcedureReturn #PB_ProcessPureBasicEvents
 
EndProcedure



OpenWindow(0,0,0,320,240,"", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)

SetWindowCallback(@WinProc())
StringGadget(0,20,40,200,20,"stuff")


Repeat
  EventID = WaitWindowEvent()
;  Select EventID
;    Case #PB_Event_Menu
;      Select EventMenu()
;        Case #PU_Save
;          Debug "Menu item "
;      EndSelect
;  EndSelect
Until EventID=#PB_Event_CloseWindow
The menu item "Save..." shows up, but where do I intercept
this new message?
Any useless help is appreciated. :wink:
Image
User avatar
Lord
Addict
Addict
Posts: 907
Joined: Tue May 26, 2009 2:11 pm

Re: How to append menu item to string gadget context menu?

Post by Lord »

Nobody has a hint for this? :(
Image
Post Reply