Page 1 of 1

Detect right click on toolbar button

Posted: Sat Nov 16, 2019 9:04 am
by Fredi
Hi

Question is simple, how we can detect right click on toolbar button?

Re: Detect right click on toolbar button

Posted: Sat Nov 16, 2019 1:00 pm
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

Re: Detect right click on toolbar button

Posted: Mon Nov 25, 2019 1:45 pm
by Fredi
Many thanks RASHAD :D