Date: 02-16-2022
Return to Index
created by gbSnippets
'Compilable Example: (Jose Includes)
'The following compilable code demonstrates a dialog with a TAB control
'which contains label and textbox controls. Right mouse click on a TAB
'will give a context menu that allows taking action on the current TAB.
#Compiler PBWin 9, PBWin 10
#Compile EXE
#Dim All
%Unicode=1
#Include "win32api.inc"
Global hDlg, hTAB, hContext As DWord
Global hPage1, hPage2, hPage3 As Long
Global TabOrder As String
%IDC_Tab = 500 : %IDC_Tab1 = 501 : %IDC_Tab2 = 502
Function PBMain() As Long
TabOrder = "123"
Dialog New Pixels, 0, "TAB Test",300,300,200,200, %WS_SysMenu, 0 To hDlg
CreateTab
CreatePopup
Dialog Show Modal hDlg Call DlgProc
End Function
CallBack Function DlgProc() As Long
Local x, y, iReturn As Long
Local temp As String
Select Case CB.Msg
Case %WM_Command
Select Case CB.Ctl
Case %IDC_Tab1 'move left
Tab Get Select hDlg, %IDC_Tab To iReturn
temp = Mid$(TabOrder,iReturn, 1)
Mid$(TabOrder,iReturn,1) = Mid$(TabOrder,iReturn-1,1)
Mid$(TabOrder,iReturn-1,1) = temp
DestroyTAB
CreateTAB
Case %IDC_Tab2 'move right
Tab Get Select hDlg, %IDC_Tab To iReturn
temp = Mid$(TabOrder,iReturn, 1)
Mid$(TabOrder,iReturn,1) = Mid$(TabOrder,iReturn+1,1)
Mid$(TabOrder,iReturn+1,1) = temp
DestroyTAB
CreateTAB
End Select
Case %WM_ContextMenu
x = Lo(Integer,CB.lParam) : y = Hi(Integer, CB.lParam)
iReturn = GetDlgCtrlID (CB.wParam) 'get control ID
Select Case iReturn
Case %IDC_Tab
TrackPopupMenu hContext, %TPM_LEFTALIGN, x, y, 0, CB.Hndl, ByVal 0
End Select
End Select
End Function
Sub CreateTAB
Local i, iReturn As Long
Local temp As String
Control Add Tab, hDlg, %IDC_Tab, "", 20,20,150,150
For i = 1 To Len(TabOrder)
temp = Mid$(TabOrder,i,1)
Select Case temp
Case "1" : Insert1(i)
Case "2" : Insert2(i)
Case "3" : Insert3(i)
End Select
Next i
End Sub
Sub DestroyTAB
Local i As Long
For i = 601 To 606 : Control Kill hDlg, i : Next i
Control Kill hDlg, %IDC_Tab
End Sub
Function Insert1(iPos As Long) As Long
Tab Insert Page hDlg, %IDC_Tab, iPos,0,"Page1" To hPage1
Control Add TextBox, hPage1, 601, "Text1", 20,20,60,20
End Function
Function Insert2(iPos As Long) As Long
Tab Insert Page hDlg, 500, iPos,0,"Page2" To hPage2
Control Add TextBox, hPage2, 602, "Text2", 20,20,60,20
Control Add TextBox, hPage2, 603, "Text2", 20,50,60,20
End Function
Function Insert3(iPos As Long) As Long
Tab Insert Page hDlg, 500, iPos,0,"Page3" To hPage3
Control Add TextBox, hPage3, 604, "Text3", 20,20,60,20
Control Add TextBox, hPage3, 605, "Text3", 20,50,60,20
Control Add TextBox, hPage3, 606, "Text3", 20,80,60,20
End Function
Sub CreatePopup
'context menu
Menu New Popup To hContext
Menu Add String, hContext, "Left", %IDC_Tab1, %MF_Enabled
Menu Add String, hContext, "Right", %IDC_Tab2, %MF_Enabled
End Sub
'gbs_00541
'Date: 03-10-2012
http://www.garybeene.com/sw/gbsnippets.htm