Page 1 of 1

just wondering, system menu items

Posted: Sun Apr 23, 2006 1:58 am
by Matt
I was wondering, how do you add items to the system menu thingy for windows, like in the purebasic IDE, when you right click the window title on the task bar, it shows a debugger menu...

Posted: Sun Apr 23, 2006 11:02 am
by Trond
Use GetSystemMenu_() then modify it.

Posted: Sun Apr 23, 2006 11:07 am
by freak

Code: Select all

#Window = 0

; The lower 4 bits should not be used in a custom menu id and must
; be masked out when comparing in the callback
;
#Menu_A = 1<<4
#Menu_B = 2<<4
#Menu_C = 3<<4

Procedure WindowCallback(Window, Message, wParam, lParam)
  Result = #PB_ProcessPureBasicEvents
  
  If Message = #WM_SYSCOMMAND
    
    Select wParam & $FFF0    ; mask out the windows internal 4 bits

      Case #Menu_A
        MessageRequester("", "Menu A")
        Result = 0 ; return 0 to indicate the message was handled
      
      Case #Menu_B
        MessageRequester("", "Menu B")
        Result = 0      
      
      Case #Menu_C
        MessageRequester("", "Menu C")
        Result = 0      

    EndSelect

  EndIf
  
  ProcedureReturn Result
EndProcedure

If OpenWindow(#Window, 0, 0, 200, 200, "SystemMenu test", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
   
  systemMenu = GetSystemMenu_(WindowID(#Window), #False) ; copy the systemenu
  popupMenu = CreatePopupMenu_()  ; create a submenu
  
  If systemMenu And popupMenu
    ; fill submenu
    ;
    AppendMenu_(popupMenu, #MF_STRING, #Menu_A, "Custom A") 
    AppendMenu_(popupMenu, #MF_STRING, #Menu_B, "Custom B")  
    
    ; add items to systemmenu. We insert above the 'close' item
    ;
    InsertMenu_(systemMenu, #SC_CLOSE, #MF_POPUP|#MF_STRING, popupMenu, "Custom SubMenu") ; add submenu
    InsertMenu_(systemMenu, #SC_CLOSE, #MF_STRING, #Menu_C, "Custom C")                   ; add another menu item
    InsertMenu_(systemMenu, #SC_CLOSE, #MF_SEPARATOR, 0, 0)                               ; add separator
  EndIf   

  ; This can be used to reset any changed done to the menu
  ;
  ; GetSystemMenu_(WindowID(#Window), #True) ; revert changes done the last time
  
  SetWindowCallback(@WindowCallback())

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow

EndIf

Posted: Sun Apr 23, 2006 4:54 pm
by Matt
thanks :D