Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "Win32API.inc"
#Include "CommCtrl.inc"
%IDC_Toolbar = 500 : %IDC_ListBox = 501
Global hDlg As Dword 'main dialog handle
Function PBMain()
'create dialog
Dialog New Pixels, 0, "Toolbar Shift-Drag Test",500,300,250,300, %WS_SysMenu, To hDlg
Control Add Toolbar, hDlg, %IDC_Toolbar,"", 0,0,0,0, %WS_Child Or %WS_Visible Or %WS_Border Or %CCS_Top Or %TbStyle_Flat Or %CCS_Adjustable
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 200, %TbStyle_Button, "200"
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 201, %TbStyle_Button, "201"
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 202, %TbStyle_Button, "202"
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 203, %TbStyle_Button, "203"
Control Add ListBox, hDlg, %IDC_ListBox,,10,55,230,245, %WS_TabStop Or %WS_VScroll, %WS_Ex_ClientEdge
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local NMT As NMToolbar Ptr, temp$, bCount, DeleteID As Long
Static StartMoveIndex, EndMoveIndex,iCount,ButtonDeleted As Long
Select Case Cb.Msg
Case %WM_ContextMenu
ListBox Reset hDlg, %IDC_ListBox 'right-mouse click to clear ListBox
Case %WM_Notify
Select Case Cb.NmId
Case %IDC_Toolbar
Toolbar Get Count hDlg, %IDC_Toolbar To bCount : Decr bCount 'to get zero-based answer
Select Case Cb.NmCode 'order received: QueryDelete --> QueryInsert --> DeletingButton
Case %TBN_QueryDelete
'on mouse-down, zero-based index of button
NMT = Cb.LParam
StartMoveIndex = @NMT.iItem 'contains zero-based Index
EndMoveIndex = StartMoveIndex
ButtonDeleted = 1
Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + "---"
Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + " QueryDelete: Idx#: " + Trim$(Str$(StartMoveIndex))
Function = %True
Case %TBN_QueryInsert
'on mouse-up, zero-based index of button, when user drops button on toolbar
NMT = Cb.LParam
EndMoveIndex = @NMT.iItem
EndMoveIndex = Min(bCount,EndMoveIndex) '@NMT.iItem can be greater than bCount
ButtonDeleted = 0 'is a move
Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + " QueryInsert: Idx# " + Trim$(Str$(StartMoveIndex)) + " TO Idx# " + Trim$(Str$(EndMoveIndex))
If StartMoveIndex <> EndMoveIndex Then Function = %True
Case %TBN_DeletingButton
'on mouse-up, ID of button being moved off the toolblar
'also received when button is dragged to a new location
NMT = Cb.LParam
DeleteID = @NMT.iItem 'contains ID
temp$ = Space$(5)
' Control Send hDlg, %IDC_Toolbar, %TB_GetButtonText, DeleteID, StrPtr(temp$) '<-- is deleted already
If ButtonDeleted Then 'delete
Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + " DeletingButton: ID#: " + Trim$(Str$(DeleteID))
' Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + " DeletingButton: Text: " + temp$
Else
Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + " MovingButton: ID#: " + Trim$(Str$(DeleteID))
Incr iCount : ListBox Add hDlg, %IDC_ListBox, Format$(iCount,"0000") + " MovingButton: Text: " + temp$
End IF
End Select
End Select
End Select
End Function
'gbs_00813
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm