just wondering, system menu items

Just starting out? Need help? Post your questions and find answers here.
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

just wondering, system menu items

Post 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...
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

Use GetSystemMenu_() then modify it.
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
Matt
Enthusiast
Enthusiast
Posts: 447
Joined: Sat May 21, 2005 1:08 am
Location: USA

Post by Matt »

thanks :D
Post Reply