Code:
'============================================================================== ' ' REBAR.BAS example for PowerBASIC for Windows PB/WIN 7.0 ' A simple DDT Rebar Control example ' ' Includes portions of: ' TOOLBAR.BAS example for PowerBASIC for Windows PB/WIN 7.0 ' Copyright (c) 2002 by PowerBASIC, Inc. ' ' Many thanks to Dominic Mitchell for providing this useful information: ' ' "When embedding controls in a rebar, the parent parameter of CreateWindowEx ' or Control Add should not be the handle of the rebar. Use the handle of the ' primary container(e.g. the dialog) for this parameter. The rebar uses the ' SetParent() API to change the parentage of the controls it manages. This means ' that there are limitations as to what can be done with controls in a rebar. ' But that's for another chapter." ' '============================================================================== '------------------------------------------------------------------------------ ' Metastatements '------------------------------------------------------------------------------ #COMPILE EXE #DIM ALL '------------------------------------------------------------------------------ ' Initial Declares - eliminate unnecessary macros in COMMCTRL.INC '------------------------------------------------------------------------------ %NOANIMATE = 1 ' Animate control %NOBUTTON = 1 ' Button %NOCOMBO = 1 ' Combo box %NOCOMBOEX = 1 ' ComboBoxEx %NODATETIMEPICK = 1 ' Date/time picker %NODRAGLIST = 1 ' Drag list control %NOEDIT = 1 ' Edit control %NOFLATSBAPIS = 1 ' Flat scroll bar %NOHEADER = 1 ' Header control %NOHOTKEY = 1 ' HotKey control %NOIMAGELIST = 1 ' Image APIs %NOIPADDRESS = 1 ' IP Address edit control %NOLIST = 1 ' List box control %NOLISTVIEW = 1 ' ListView control %NOMENUHELP = 1 ' Menu help %NOMONTHCAL = 1 ' MonthCal %NOMUI = 1 ' MUI %NONATIVEFONTCTL = 1 ' Native Font control %NOPAGESCROLLER = 1 ' Pager %NOPROGRESS = 1 ' Progress control '%NOREBAR = 1 ' Rebar control %NOSTATUSBAR = 1 ' Status bar %NOTABCONTROL = 1 ' Tab control '%NOTOOLBAR = 1 ' Tool bar '%NOTOOLTIPS = 1 ' Tool tips %NOTRACKBAR = 1 ' Track bar %NOTRACKMOUSEEVENT = 1 ' Track Mouse Event %NOTREEVIEW = 1 ' TreeView %NOUPDOWN = 1 ' Up Down arrow control '------------------------------------------------------------------------------ ' Include files '------------------------------------------------------------------------------ #INCLUDE "WIN32API.INC" #INCLUDE "COMMCTRL.INC" #INCLUDE "INITCTRL.INC" '------------------------------------------------------------------------------ ' Equates '------------------------------------------------------------------------------ $AppTitle = "DDT Rebar Example" %ToolButtons = 10 %ID_REBAR = 1001 %ID_COMBOBOX = 1002 %ID_TOOLBAR = 1003 %ID_Prev = 101 %ID_Next = 102 %ID_Mode1 = 103 %ID_Mode2 = 104 '------------------------------------------------------------------------------ ' Globals '------------------------------------------------------------------------------ GLOBAL hRebar AS DWORD '------------------------------------------------------------------------------ ' Declarations '------------------------------------------------------------------------------ DECLARE CALLBACK FUNCTION DialogCallback DECLARE FUNCTION CreateRebar (BYVAL hParent AS DWORD) AS LONG DECLARE FUNCTION CreateComboBox (BYVAL hParent AS DWORD) AS DWORD DECLARE FUNCTION CreateToolBar (BYVAL hParent AS DWORD) AS DWORD FUNCTION CreateComboBox (BYVAL hParent AS DWORD) AS DWORD REGISTER i AS LONG LOCAL hComboBox AS DWORD CONTROL ADD COMBOBOX, hParent, %ID_COMBOBOX,, 0, 0, 0, 100, _ %WS_CHILD OR %WS_VISIBLE OR %CBS_DROPDOWNLIST OR %WS_VSCROLL _ OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN CONTROL HANDLE hParent, %ID_COMBOBOX TO hComboBox FOR i = 1 TO 20 COMBOBOX ADD hParent, %ID_COMBOBOX, "Item " & FORMAT$(i) NEXT COMBOBOX SELECT hParent, %ID_COMBOBOX, 1 FUNCTION = hComboBox END FUNCTION FUNCTION CreateToolBar (BYVAL hParent AS DWORD) AS DWORD ' General Register variables for speed optimization REGISTER x AS LONG LOCAL hToolBar AS DWORD ' Toolbar variables LOCAL Tbb() AS TBBUTTON LOCAL Tabm AS TBADDBITMAP DIM Tbb(0:%ToolButtons - 1) AS LOCAL TBBUTTON CONTROL ADD "TOOLBARWINDOW32", hParent, %ID_TOOLBAR, "", 0, 0, 0, 0, _ %WS_CHILD OR %WS_VISIBLE OR %TBSTYLE_TOOLTIPS OR %TBSTYLE_FLAT _ OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %CCS_NODIVIDER OR %CCS_NORESIZE ' Init Tbb array. FOR x = 0 TO %ToolButtons - 1 ' Set the initial states for each button Tbb(x).iBitmap = 0 Tbb(x).idCommand = 0 Tbb(x).fsState = %TBSTATE_ENABLED Tbb(x).fsStyle = %TBSTYLE_BUTTON Tbb(x).dwData = 0 Tbb(x).iString = 0 SELECT CASE AS LONG x CASE 0,3,6,8 ' Gap creation buttons. Tbb(x).fsStyle = %TBSTYLE_SEP CASE 1& Tbb(x).iBitmap = %STD_UNDO Tbb(x).idCommand = %ID_Prev Tbb(x).iString = 0 Tbb(x).fsState = 0 ' Would be %TBSTATE_DISABLED if defined CASE 2& Tbb(x).iBitmap = %STD_REDOW Tbb(x).idCommand = %ID_Next Tbb(x).iString = 1 CASE 4& Tbb(x).iBitmap = %STD_FILENEW Tbb(x).idCommand = %ID_Mode1 Tbb(x).iString = 2 Tbb(x).fsState = %TBSTATE_ENABLED OR %TBSTATE_CHECKED Tbb(x).fsStyle = %TBSTYLE_CHECKGROUP OR %TBSTYLE_BUTTON CASE 5& Tbb(x).iBitmap = %STD_FILESAVE Tbb(x).idCommand = %ID_Mode2 Tbb(x).iString = 3 Tbb(x).fsStyle = %TBSTYLE_CHECKGROUP OR %TBSTYLE_BUTTON CASE 7& Tbb(x).iBitmap = %STD_PRINT Tbb(x).idCommand = %IDOK Tbb(x).iString = 4 CASE 9& Tbb(x).iBitmap = %STD_DELETE Tbb(x).idCommand = %IDCANCEL Tbb(x).iString = 5 END SELECT NEXT x Tabm.nID = %IDB_STD_LARGE_COLOR ' Use the ID of the bitmap image, ie, %ID_TOOLBAR Tabm.hInst = %HINST_COMMCTRL ' Use GetModuleHandle(BYVAL %NULL) ' if using a bitmap in a linked resource file ' Set the imge list for the TB CONTROL SEND hParent, %ID_TOOLBAR, %TB_ADDBITMAP, %ToolButtons, VARPTR(Tabm) ' Set the buttons CONTROL SEND hParent, %ID_TOOLBAR, %TB_BUTTONSTRUCTSIZE, SIZEOF(Tbb(0)), 0 CONTROL SEND hParent, %ID_TOOLBAR, %TB_ADDBUTTONS, %ToolButtons, VARPTR(Tbb(0)) CONTROL HANDLE hParent, %ID_TOOLBAR TO hToolBar FUNCTION = hToolBar END FUNCTION FUNCTION CreateRebar (BYVAL hParent AS DWORD) AS LONG LOCAL rbi AS REBARINFO LOCAL rbBand AS REBARBANDINFO LOCAL rc AS RECT LOCAL hCbBox AS DWORD LOCAL szCbText AS ASCIIZ * 255 LOCAL hTbBar AS DWORD LOCAL szTbText AS ASCIIZ * 255 LOCAL dwBtnSize AS DWORD CONTROL ADD $REBARCLASSNAME, hParent, %ID_REBAR, "", 0, 0, 0, 0, _ %WS_CHILD OR %WS_VISIBLE OR %WS_CLIPSIBLINGS OR %WS_CLIPCHILDREN OR _ %RBS_VARHEIGHT OR %RBS_BANDBORDERS OR %CCS_NODIVIDER CONTROL HANDLE hParent, %ID_REBAR TO hRebar ' Initialize and send the REBARINFO structure rbi.cbSize = SIZEOF(rbi) rbi.fMask = 0 rbi.himl = 0 CONTROL SEND hParent, %ID_REBAR, %RB_SETBARINFO, 0, VARPTR(rbi) '// Initialize REBARBANDINFO for all rebar bands rbBand.cbSize = SIZEOF(rbBand) rbBand.fMask = %RBBIM_COLORS OR _ '// clrFore and clrBack are valid %RBBIM_CHILD OR _ '// hwndChild is valid %RBBIM_CHILDSIZE OR _ '// cxMinChild and cyMinChild are valid %RBBIM_STYLE OR _ '// fStyle is valid %RBBIM_ID OR _ '// wID is valid %RBBIM_SIZE OR _ '// cx is valid %RBBIM_TEXT OR _ '// lpText is valid %RBBIM_BACKGROUND '// hbmBack is valid rbBand.clrFore = RGB(250,0,0) '// Red rbBand.clrBack = RGB(250,250,0) '// Yellow rbBand.fStyle = %RBBS_NOVERT OR _ '// do not display in vertical orientation %RBBS_CHILDEDGE OR _ %RBBS_FIXEDBMP rbBand.hbmBack = 0 hTbBar = CreateToolBar(hParent) dwBtnSize = SendMessage(hTbBar, %TB_GETBUTTONSIZE, 0, 0) szTbText = "ToolBar" rbBand.lpText = VARPTR(szTbText) rbBand.hwndChild = hTbBar rbBand.wID = %ID_TOOLBAR rbBand.cxMinChild = 230 rbBand.cyMinChild = HIWRD(dwBtnSize) rbBand.cx = 250 '// Insert band into rebar CONTROL SEND hParent, %ID_REBAR, %RB_INSERTBAND, -1, VARPTR(rbBand) hCbBox = CreateComboBox(hParent) szCbText = "ComboBox" rbBand.lpText = VARPTR(szCbText) rbBand.hwndChild = hCbBox rbBand.wID = %ID_COMBOBOX GetWindowRect hCbBox, rc rbBand.cxMinChild = 150 rbBand.cyMinChild = rc.nBottom - rc.nTop rbBand.cx = 400 '// Insert band into rebar CONTROL SEND hParent, %ID_REBAR, %RB_INSERTBAND, -1, VARPTR(rbBand) END FUNCTION '------------------------------------------------------------------------------ ' Main entry point for the application '------------------------------------------------------------------------------ FUNCTION PBMAIN() AS LONG LOCAL hDlg AS DWORD ' Initialize the common control library InitComCtl32 %ICC_COOL_CLASSES OR %ICC_USEREX_CLASSES ' No error trapping, we will handle it ourself ON ERROR RESUME NEXT DIALOG NEW %HWND_DESKTOP, $AppTitle, 0, 0, _ 350, 200, %WS_MAXIMIZEBOX OR %WS_MINIMIZEBOX OR %WS_SYSMENU OR _ %WS_THICKFRAME OR %WS_CLIPCHILDREN OR %WS_CLIPSIBLINGS OR %DS_CENTER _ TO hDlg CreateRebar hDlg DIALOG SHOW MODAL hDlg CALL DialogCallback END FUNCTION '------------------------------------------------------------------------------ ' Main callback '------------------------------------------------------------------------------ CALLBACK FUNCTION DialogCallback LOCAL x AS LONG LOCAL pTOOLTIP AS TOOLTIPTEXT PTR ' Structure pointer via NMHDR STATIC szTipText AS ASCIIZ * 64 ' ToolTips text buffer SELECT CASE CBMSG CASE %WM_COMMAND IF CBCTL = %IDCANCEL THEN DIALOG END CBHNDL, %TRUE CASE %WM_SIZE MoveWindow hRebar, 0, 0, LOWRD(CBLPARAM), HIWRD(CBLPARAM), %TRUE CASE %WM_NOTIFY ' Init pointer value pTOOLTIP = CBLPARAM IF @pTOOLTIP.hdr.code = %TTN_NEEDTEXT THEN ' Locate the tooltip text from the DATA FOR x = 1 TO DATACOUNT STEP 2 IF VAL(READ$(x)) = @pTOOLTIP.hdr.idFrom THEN szTipText = READ$(x + 1) @pTOOLTIP.lpszText = VARPTR(szTipText) FUNCTION = 1 EXIT FOR END IF NEXT x END IF END SELECT ' Data comprises the ID of toolbar button, followed by the tooltip description DATA 101, "Previous item" DATA 102, "Next item" DATA 103, "Create a new item" DATA 104, "Use an existing item" DATA 1, "Print current item" DATA 2, "Quit the application" END FUNCTION
------------------