a way to check if toolbar button is being held by the mouse?
a way to check if toolbar button is being held by the mouse?
Hello all. Is there a way to check if a toolbar button is actively being held by the mouse?
I want the user to click on a toolbar icon and hold the left button, and then move the mouse, and then I plan on getting the mouse position until they let go. However, I see the Event documentation doesn't cover this type of action.
I am only writing for Windows.
I want the user to click on a toolbar icon and hold the left button, and then move the mouse, and then I plan on getting the mouse position until they let go. However, I see the Event documentation doesn't cover this type of action.
I am only writing for Windows.
---
BASIC related discord: https://discord.gg/KS4en5y5j4
BASIC related discord: https://discord.gg/KS4en5y5j4
Re: a way to check if toolbar button is being held by the mouse?
I think you want the drag&drop feature
Re: a way to check if toolbar button is being held by the mouse?
I don't think that will work as the toolbar has no drag&drop functionality and I can't call a private drag and drop until after the buttons already released.
---
BASIC related discord: https://discord.gg/KS4en5y5j4
BASIC related discord: https://discord.gg/KS4en5y5j4
Re: a way to check if toolbar button is being held by the mouse?
Create the toolbar with the Canvas gadget and you can use the canvas's events to monitor the mouse according to your likingTRS-Eric wrote: Tue Dec 13, 2022 4:05 pm I don't think that will work as the toolbar has no drag&drop functionality and I can't call a private drag and drop until after the buttons already released.
Re: a way to check if toolbar button is being held by the mouse?
I havent used the toolbar yet, but if you can't use de normal drag&drop...
Make your own drag&drop:
Check the mouse button state.
If it's on the toolbar and it's pressed, save a flag (drag).
Then move the mouse
Now, If mouse button is released and drag flag is true, do something.
Make your own drag&drop:
Check the mouse button state.
If it's on the toolbar and it's pressed, save a flag (drag).
Then move the mouse
Now, If mouse button is released and drag flag is true, do something.
Re: a way to check if toolbar button is being held by the mouse?
This was the first thing I tried, sadly there's no mouse down event for the toolbar.
I think I can come up with a simpler method, the user presses the toolbar button and then presses escape for the ok dialog box, and I'll just monitor the mouse position. I'll give that a try instead
I think I can come up with a simpler method, the user presses the toolbar button and then presses escape for the ok dialog box, and I'll just monitor the mouse position. I'll give that a try instead

---
BASIC related discord: https://discord.gg/KS4en5y5j4
BASIC related discord: https://discord.gg/KS4en5y5j4
Re: a way to check if toolbar button is being held by the mouse?
You can check (globally) the mouse position and the mouse button state despite the gadget, so compare the position with the toolbar position, and so on...TRS-Eric wrote: Tue Dec 13, 2022 5:17 pm This was the first thing I tried, sadly there's no mouse down event for the toolbar.
Re: a way to check if toolbar button is being held by the mouse?
Anyway, the solution from Demivec should be better
Re: a way to check if toolbar button is being held by the mouse?
Maybe like this way?
Code: Select all
UsePNGImageDecoder()
Procedure WindowCallback(hWnd, uMsg, wParam, lParam)
Protected Result = #PB_ProcessPureBasicEvents
Protected *lpnmtb.NMTOOLBAR, pt.POINT, idx
Static iStartButton
If uMsg = #WM_NOTIFY
*lpnmtb = lParam
If *lpnmtb And *lpnmtb\hdr\hwndFrom = ToolBarID(0)
Select *lpnmtb\hdr\code
Case #TBN_BEGINDRAG
iStartButton = -1
If GetCursorPos_(@pt)
MapWindowPoints_(0, ToolBarID(0), pt, 1)
iStartButton = SendMessage_(ToolBarID(0), #TB_HITTEST, 0, pt)
EndIf
Case #TBN_ENDDRAG
If GetCursorPos_(@pt)
MapWindowPoints_(0, ToolBarID(0), pt, 1)
idx = SendMessage_(ToolBarID(0), #TB_HITTEST, 0, pt)
If idx >= 0
Debug "dropped on button " + idx
If iStartButton = idx
Debug "dropped on the same button."
EndIf
Else
MapWindowPoints_(ToolBarID(0), WindowID(0), pt, 1)
Debug "dropped outside: " + pt\x + "," +pt\y + " on window 0"
EndIf
EndIf
EndSelect
EndIf
EndIf
ProcedureReturn Result
EndProcedure
If OpenWindow(0, 100, 200, 195, 260, "ToolBar example", #PB_Window_SystemMenu | #PB_Window_SizeGadget)
If CreateToolBar(0, WindowID(0))
ToolBarImageButton(0, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/New.png"))
ToolBarImageButton(1, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Open.png"))
ToolBarImageButton(2, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Save.png"))
ToolBarSeparator()
ToolBarImageButton(3, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Cut.png"))
ToolBarToolTip(0, 3, "Cut")
ToolBarImageButton(4, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Copy.png"))
ToolBarToolTip(0, 4, "Copy")
ToolBarImageButton(5, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Paste.png"))
ToolBarToolTip(0, 5, "Paste")
ToolBarSeparator()
ToolBarImageButton(6, LoadImage(0, #PB_Compiler_Home + "examples/sources/Data/ToolBar/Find.png"))
ToolBarToolTip(0, 6, "Find a document")
EndIf
If CreateMenu(0, WindowID(0))
MenuTitle("Project")
MenuItem(0, "New")
MenuItem(1, "Open")
MenuItem(2, "Save")
EndIf
DisableToolBarButton(0, 2, 1)
SetWindowCallback(@WindowCallback(), 0)
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Menu
MessageRequester("Information", "ToolBar or Menu ID: "+Str(EventMenu()), 0)
Case #PB_Event_CloseWindow
Quit = 1
EndSelect
Until Quit = 1
EndIf
Re: a way to check if toolbar button is being held by the mouse?

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive