Date: 02-16-2022
Return to Index
created by gbSnippets
'Compiler Comments:
'This code is written to compile in PBWin10. To compile in PBWin9, split pt
'into pt.x and pt.y as arguments wherever the ChildWindowFromPoint() API is used (1 place).
'This example shows how to use the mouse to change the position of
'one tab page within the tab control.
'Compilable Example: (Jose Includes)
#Compiler PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
#Include "commctrl.inc"
Global hDlg, hTAB, hTemp As Dword
Global TabMoveInWork As Long, TabTitles() As String
%IDC_Tab = 500 : %IDC_Label = 501
Function PBMain() As Long
ReDim TabTitles(5) : Array Assign TabTitles() = "","Page01","Page02","Page03","Page04","Page05"
Dialog New Pixels, 0, "TAB Test",300,300,450,350, %WS_OverlappedWindow Or %WS_ClipChildren, 0 To hDlg
Control Add Label, hDlg, %IDC_Label, "", 0,0,50,20
Control Add Tab, hDlg, %IDC_Tab, "", 20,20,250,150
Control Handle hDlg, %IDC_Tab To hTab
AddTabPages
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local iReturn As Long, pt As Point
Static oldX, oldY As Long
Select Case Cb.Msg
Case %WM_SetCursor
GetCursorPos pt : ScreenToClient hDlg, pt 'pt now has dialog client coordinates
iReturn = ChildWindowFromPoint(hDlg, pt)
Select Case Hi(Word, Cb.LParam)
Case %WM_LButtonDown
If iReturn = hTab Then TabMoveInWork = 1 : oldX = pt.x : oldY = pt.y
Case %WM_MouseMove
If TabMoveInWork And (oldX <> pt.x Or oldY <> pt.y) Then MousePtr 13 : Function = 1
Case %WM_LButtonUp
If TabMoveInWork Then MoveTabToNewLocation : MousePtr 1
TabMoveInWork = 0
End Select
End Select
End Function
Sub MoveTabToNewLocation
'get the from - to tab page indices
Local i, iTab, iDrop As Long, HT As TC_HitTestInfo, temp$
Tab Get Select hDlg, %IDC_Tab To iTab 'selected tab page
GetCursorPos HT.pt : ScreenToClient hTab, HT.pt 'tab coordinates of mouse
iDrop = SendMessage(hTab, %TCM_HitTest, 0, VarPtr(HT)) + 1 'tab page under mouse at drop
If iTab = iDrop Or iDrop = 0 Then Exit Sub 'exit if not a valid drop
'reorder the titles (or whatever custom action you need to take)
temp$ = TabTitles(iTab)
Array Delete TabTitles(iTab)
Array Insert TabTitles(iDrop), temp$
AddTabPages
Tab Select hDlg, %IDC_Tab, iDrop
End Sub
Sub AddTabPages
Tab Reset hDlg, %IDC_Tab
Tab Insert Page hDlg, %IDC_Tab, 1, 0, TabTitles(5) To hTemp
Tab Insert Page hDlg, %IDC_Tab, 1, 0, TabTitles(4) To hTemp
Tab Insert Page hDlg, %IDC_Tab, 1, 0, TabTitles(3) To hTemp
Tab Insert Page hDlg, %IDC_Tab, 1, 0, TabTitles(2) To hTemp
Tab Insert Page hDlg, %IDC_Tab, 1, 0, TabTitles(1) To hTemp
End Sub
'gbs_00693
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm