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
Global hDlg As Dword 'main dialog handle
Function PBMain()
Dialog New Pixels, 0, "Toolbar Shift-Drag Test",500,300,200,125, %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, "0"
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 201, %TbStyle_Button, "1"
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 202, %TbStyle_Button, "2"
Toolbar Add Button hDlg, %IDC_Toolbar, 0, 203, %TbStyle_Button, "3"
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local NMT As NMToolbar Ptr, temp$, bCount As Long
Static StartMoveIndex,EndMoveIndex As Long
Select Case Cb.Msg
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 'use later to test if move took place
Function = %True 'always allow a move/delete to start
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 incorrectly be greater than bCount
If StartMoveIndex <> EndMoveIndex Then Function = %True 'allow move only if move is to a new location
End Select
End Select
End Select
End Function
'gbs_00812
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm