Detect right click on toolbar button

Just starting out? Need help? Post your questions and find answers here.
Fredi
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Jul 23, 2008 10:45 pm

Detect right click on toolbar button

Post by Fredi »

Hi

Question is simple, how we can detect right click on toolbar button?
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4954
Joined: Sun Apr 12, 2009 6:27 am

Re: Detect right click on toolbar button

Post by RASHAD »

Hi
For Windows

Code: Select all

Global lpPrevWndFunc

Procedure tbCB(hWnd, uMsg, wParam, lParam)
 Select uMsg
    Case #WM_CONTEXTMENU
        Debug SendMessage_(ToolBarID(0), #TB_GETHOTITEM, 0,0)
      ProcedureReturn 0
            
  EndSelect
 ProcedureReturn CallWindowProc_(lpPrevWndFunc, hWnd, uMsg, wParam, lParam)
EndProcedure

If OpenWindow(0, 0, 0, 200, 150, "Right Click ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  If CreateToolBar(0, WindowID(0))
    ToolBarStandardButton(0, #PB_ToolBarIcon_New)
    ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
    ToolBarSeparator()
    ToolBarStandardButton(3, #PB_ToolBarIcon_Print)
    ToolBarStandardButton(4, #PB_ToolBarIcon_Find)
    ToolBarSeparator()
  EndIf
  
  lpPrevWndFunc = SetWindowLongPtr_(ToolBarID(0), #GWL_WNDPROC, @tbCB())

  Repeat
    EventID = WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow 
        Quit = 1
    EndSelect
  Until Quit = 1
EndIf
End
Added #2:

Code: Select all

If OpenWindow(0, 0, 0, 200, 150, "Right Click ToolBar", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

  If CreateToolBar(0, WindowID(0))
    ToolBarStandardButton(0, #PB_ToolBarIcon_New)
    ToolBarStandardButton(1, #PB_ToolBarIcon_Open)
    ToolBarStandardButton(2, #PB_ToolBarIcon_Save)
    ToolBarSeparator()
    ToolBarStandardButton(3, #PB_ToolBarIcon_Print)
    ToolBarStandardButton(4, #PB_ToolBarIcon_Find)
    ToolBarSeparator()
  EndIf
  
  Repeat
    EventID = WaitWindowEvent()
    Select EventID
      Case #PB_Event_CloseWindow 
        Quit = 1
        
      Case #WM_RBUTTONUP
        index = SendMessage_(ToolBarID(0), #TB_GETHOTITEM, 0,0)
        If index >= 0
          Debug index
        EndIf
    EndSelect
  Until Quit = 1
EndIf
End
Egypt my love
Fredi
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Jul 23, 2008 10:45 pm

Re: Detect right click on toolbar button

Post by Fredi »

Many thanks RASHAD :D
Post Reply