This is another part of an interface for a game I've been working on for a couple of years.
Now if I can figure out how to color the tabs I'll be in 7th heaven.
This code is released as public domain.
Comments welcome via the appropriate board.
Now if I can figure out how to color the tabs I'll be in 7th heaven.
This code is released as public domain.
Comments welcome via the appropriate board.
Code:
#COMPILE EXE DEFLNG A - Z #INCLUDE "WIN32API.INC" #INCLUDE "COMMCTRL.INC" #INCLUDE "PBForms.INC" %IDD_DIALOG1 = 101 %TAB_CTRL = 100 DECLARE SUB Tab_Control_DLG(BYVAL hParent AS DWORD) DECLARE CALLBACK FUNCTION Tab_Control_CB() FUNCTION PBMAIN() PBFormsInitComCtls (%ICC_WIN95_CLASSES OR %ICC_DATE_CLASSES OR _ %ICC_INTERNET_CLASSES) Tab_Control_DLG %HWND_DESKTOP END FUNCTION '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ CALLBACK FUNCTION Tab_Control_CB() LOCAL DglHndl AS LONG LOCAL CtrlNotifyCode AS LONG LOCAL CtrlID AS LONG LOCAL CtrlHndl AS LONG LOCAL TabPos AS LONG LOCAL NmHdr_Ptr AS NMHDR POINTER LOCAL tTab AS TC_ITEM DlgHndl = CBHNDL SELECT CASE AS LONG CBMSG CASE %WM_INITDIALOG '========================================================================= ' Initialization handler. ' Each dialog created sends this message to the appropriate callback function. ' Here we query the dialog's user variable set previously to see if it is the ' first child dialog we created. '========================================================================= DIALOG GET USER DlgHndl, 1 TO D IF D = 1 THEN DIALOG SHOW STATE DlgHndl, %SW_SHOW END IF CASE %WM_NCACTIVATE STATIC hWndSaveFocus AS DWORD IF ISFALSE CBWPARAM THEN ' Save control focus hWndSaveFocus = GetFocus() ELSEIF hWndSaveFocus THEN ' Restore control focus SetFocus(hWndSaveFocus) hWndSaveFocus = 0 END IF CASE %WM_COMMAND ' Process control notifications SELECT CASE AS LONG CBCTL CASE %TAB_CTRL END SELECT CASE %WM_NOTIFY '================================================================ ' here we control the tab display using %NM_CLICK and the parameters ' that were stored in dialog and control user variables. '================================================================ NmHdr_Ptr = CBLPARAM CtrlNotifyCode = @NmHdr_Ptr.Code '<-- get notification message CtrlID = @NmHdr_Ptr.IdFrom '<-- get control ID SELECT CASE CtrlID CASE %TAB_CTRL CONTROL GET USER DlgHndl, %TAB_CTRL, 1 TO CtrlHndl '<-- get control window handle CtrlID = SendMessage(CtrlHndl, %TCM_GETCURSEL, 0, 0)'<-- get visible tab page tTab.Mask = %TCIF_PARAM '<-- set struct to param we want SendMessage(CtrlHndl, %TCM_GETITEM, CtrlID, VARPTR(tTab)) '<-- get param DIALOG SHOW STATE tTab.Lparam, %SW_HIDE '<-- hide page SELECT CASE CtrlNotifyCode '<-- check notification message CASE %NM_CLICK, 1 DIALOG GET USER DlgHndl, 1 TO CtrlID '<-- get dialog ID prefiously set IF CtrlID = 100 THEN CONTROL GET USER DlgHndl, %TAB_CTRL, 1 TO CtrlHndl '<-- get window handle CtrlID = SendMessage(CtrlHndl, %TCM_GETCURSEL, 0, 0)'<-- get new page tTab.Mask = %TCIF_PARAM '<-- set struct to param we want SendMessage(CtrlHndl, %TCM_GETITEM, CtrlID, VARPTR(tTab)) '<-- get param DIALOG SHOW STATE tTab.Lparam, %SW_SHOW '<-- show new page FUNCTION = 1 END IF END SELECT END SELECT END SELECT END FUNCTION '----------------------------------------------------------------- '----------------------------------------------------------------- SUB Tab_Control_DLG(BYVAL hParent AS DWORD) LOCAL Rslt AS DWORD LOCAL hDlg AS DWORD DIALOG NEW hParent, "Knowledge", 81, 97, 357, 189, %WS_POPUP OR %WS_BORDER _ OR %WS_DLGFRAME OR %WS_CAPTION OR %WS_SYSMENU OR %WS_CLIPSIBLINGS OR _ %WS_CLIPCHILDREN OR %WS_VISIBLE OR %DS_MODALFRAME OR %DS_3DLOOK OR _ %DS_NOFAILCREATE OR %DS_SETFONT, %WS_EX_CONTROLPARENT OR %WS_EX_LEFT OR _ %WS_EX_LTRREADING OR %WS_EX_RIGHTSCROLLBAR, TO hDlg CONTROL ADD "SysTabControl32", hDlg, %TAB_CTRL, _ "SysTabControl32_2", 15, 15, 330, 140, %WS_CHILD OR %WS_VISIBLE OR _ %WS_TABSTOP OR %TCS_MULTILINE OR %TCS_RIGHTJUSTIFY OR _ %TCS_FLATBUTTONS OR %TCS_FOCUSONBUTTONDOWN OR %WS_BORDER, _ %WS_EX_LEFT OR %WS_EX_LTRREADING DIALOG SET USER hDlg, 1, 100 CONTROL GET CLIENT hDlg, %TAB_CTRL TO X, Y CONTROL GET LOC hDlg, %TAB_CTRL TO Xtop, YTop '================================================================== ' set tab control user variable variable to window handle for ' later use '================================================================== CONTROL HANDLE hDlg, %TAB_CTRL TO TabCtrlID CONTROL SET USER hDlg, %TAB_CTRL, 1, TabCtrlID CONTROL SET COLOR hDlg, %TAB_CTRL, %BLACK, %WHITE CALL Child_Dlg(hDlg, TabCtrlID, Xtop, Ytop, X, Y, 20) DIALOG SHOW MODAL hDlg, CALL Tab_Control_CB TO Rslt END SUB '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ SUB Set_Tab_Control(BYVAL hDlg AS DWORD, BYVAL hCtl AS LONG, _ BYVAL ChildDlgHndl AS LONG, BYVAL TabPos AS LONG) '=============================================================================== ' Used to initialize the tab control. Each call sets a new tab of the control. ' hDlg = handle of main dialog ' hCtl = windows handle of tab control, not the tab control ID ' ChildDlgHndl = the handle of the child dialog associated with the tab ' TabPos = the tab number or label associated with the tab. To make ' this descriptive change TabPos to an ASCIIZ pointer and insert it ' directly or change it to ASCIIZ and delete "szBuf" below. '=============================================================================== LOCAL szBuf AS ASCIIZ * 32 LOCAL tTC_Item AS TC_ITEM szBuf = USING$("Tab #", TabPos) tTC_Item.Mask = %TCIF_TEXT OR %TCIF_PARAM tTC_Item.iImage = -1 tTC_Item.pszText = VARPTR(szBuf) '======================================================== ' each tab has a user defind variable. Here we set the ' user defined variable to the handle of the child dialog ' for later use '======================================================== tTC_Item.Lparam = ChildDlgHndl TabCtrl_InsertItem hCtl,TabPos, tTC_Item END SUB '------------------------------------------------------------------------------ '------------------------------------------------------------------------------ SUB Child_Dlg(BYVAL DlgHndl AS LONG, BYVAL TabCtrlID AS LONG, BYVAL XLoc AS LONG, _ BYVAL Yloc AS LONG, BYVAL XWide, YHigh, NumTabs) '=============================================================================== ' create child dialogs for each tab ' DlgHndl = handle of main dialog ' TabCtrlID = handle of tab control ' Xloc = upper left corner of tab control ' Yloc = upper right corner of tab control ' Xwide = width of tab control ' Yhigh = hight of tab control '================================================================================ LOCAL ChildHndl AS LONG LOCAL Rgbv AS LONG RANDOMIZE TIMER FOR I = 1 TO NumTabs DIALOG NEW DlgHndl, "", XLoc, YLoc + 13, XWide, YHigh - 12, %WS_CHILD OR %DS_CONTROL OR _ %WS_BORDER, ,TO ChildHndl Rgbv = RGB(RND(0, 255), RND(0, 255), RND(0,255)) DIALOG SET COLOR ChildHndl, -1, Rgbv CALL Set_Tab_Control(DlgHndl, TabCtrlID, ChildHndl, I) CONTROL ADD LABEL, ChildHndl, I * 200, "Page" + STR$(I), XLoc + 10, YLoc + 10, 50, 50 CONTROL SET COLOR ChildHndl, I * 200, %WHITE, -2 '=================== Set dialog user variable for later use =================== DIALOG SET USER ChildHndl, 1, I '============================================================================== DIALOG SHOW STATE ChildHndl, %SW_HIDE DIALOG SHOW MODELESS ChildHndl, CALL Tab_Control_CB NEXT I END SUB