'====================================================================
' Rebar example in modal dialog as main.
'====================================================================
$ filename "RebarDlg.exe"
'uses rtl32
'uses rtl64
'% review
uses dialogs
% TB_ADDBITMAP=1043
% TB_ADDBUTTONS=0x414
% TB_SETBUTTONSIZE=1055
% TB_AUTOSIZE=1057
% TB_GETBUTTONSIZE=1082
% TB_SETEXTENDEDSTYLE=1108
% CCS_NODIVIDER=64
% CCS_NORESIZE=4
% RBS_BANDBORDERS=1024
% RBS_VARHEIGHT=512
% RBBIM_BACKGROUND=128
% RBBIM_CHILD=16
% RBBIM_CHILDSIZE=32
% RBBIM_COLORS=2
% RBBIM_ID=256
% RBBIM_SIZE=64
% RBBIM_STYLE=1
% RBBIM_TEXT=4
% RBBS_CHILDEDGE=4
% RBBS_FIXEDBMP=32
% RBBS_NOVERT=16
% RBBS_BREAK=1
% RB_SETBARINFO=1028
% RB_INSERTBAND=1025
% HINST_COMMCTRL=-1
% IDB_STD_SMALL_COLOR=0
% STD_FILENEW=6
% STD_FILEOPEN=7
% STD_FILESAVE=8
% TBSTATE_ENABLED=4
% TBSTYLE_BUTTON=0
% TBSTYLE_FLAT=2048
% TBSTYLE_TOOLTIPS=256
% TB_BUTTONSTRUCTSIZE=1054
% TBSTYLE_EX_HIDECLIPPEDBUTTONS=16
type TBADDBITMAP
sys hInst
sys nID
end type
type TBBUTTON
int iBitmap
int idCommand
BYTE fsState
BYTE fsStyle
dword dwData
sys iString
end type
type REBARINFO
UINT cbSize
UINT fMask
sys himl
end type
type REBARBANDINFO
UINT cbSize
UINT fMask
UINT fStyle
uint clrFore 'COLORREF
uint clrBack 'COLORREF
char* lpText
UINT cch
int iImage
sys hwndChild 'HWND
UINT cxMinChild
UINT cyMinChild
UINT cx
sys hbmBack 'HBITMAP
UINT wID
UINT cyChild
UINT cyMaxChild
UINT cyIntegral
UINT cxIdeal
sys lParam 'LPARAM
UINT cxHeader
'RECT rcChevronLocation
'UINT uChevronState
end type
macro MakeLong(lo,hi) { ( (lo) or ( (hi)<<16 ) ) }
declare sub CreateRebar (sys hParent)
==============================================
'MAIN CODE
=============================================
sys hInstance = GetModuleHandle(null)
% ID_Rebar = 1001
% ID_Combobox = 1002
% ID_Toolbar = 1003
% ID_Button = 1004
% ID_FileNew = 1005
% ID_FileOpen = 1006
% ID_FileSave = 1007
init_common_controls()
sub winmain()
Dialog( 0, 0, 350, 200, "Rebar example in a Dialog using OxygenBasic",
WS_OVERLAPPEDWINDOW or DS_CENTER or DS_SETFONT,
10, "Arial")
Control("", ID_Rebar, "ReBarWindow32",
WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | RBS_VARHEIGHT | RBS_BANDBORDERS | CCS_NODIVIDER,
0,0,0,0)
Control( "", ID_Toolbar, "TOOLBARWINDOW32", WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT |
WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NORESIZE,
0, 0, 0, 0 )
DropDownList("", ID_Combobox, 0,0,0,100)
PushButton("A", ID_Button, 0,0,15,15)
LText("Clicking text of: Toolbar, Combobox, A Button will change width of Band", -1, 20,100, 250,20)
LText("Moving text of: Toolbar, Combobox, A Button will move Band", -1, 20,110, 250,20)
LText("to the left, right, up, down", -1, 20,120, 250,20)
CreateModalDialog( null, @DialogProc, 0)
end sub
winmain()
==========================================================
function DialogProc( sys hDlg, uint uMsg, sys wParam, lParam ) as sys callback
select case uMsg
case WM_INITDIALOG
CreateRebar (hDlg)
case WM_SIZE
sys hRebar=GetDlgItem(hDlg, ID_Rebar)
MoveWindow (hRebar, 0, 0, loword(lParam), hiword(lParam), true)
case WM_COMMAND
select case loword(wParam)
case IDCANCEL : EndDialog( hDlg, null )
case ID_Button : mbox "Button clicked"
case ID_FileNew, ID_FileOpen, ID_FileSave : mbox "Button in Toolbar clicked"
end select
case WM_CLOSE
EndDialog( hDlg, null )
end select
return 0
end function
function FillCombobox (sys hParent) as sys
sys hComboBox=GetDlgItem(hParent, ID_Combobox)
int i
for i = 1 to 10
SendMessage(hComboBox, CB_ADDSTRING, 0, "Item " + str(i))
next i
SendMessage(hComboBox, CB_SETCURSEL, 0, 0) 'index=1, zero-based
return hComboBox
end function
function FillToolbar (sys hParent) as sys
indexbase 0
' Toolbar variables
TBBUTTON tbb[2]
TBADDBITMAP tbab
sys hToolBar=GetDlgItem(hParent, ID_Toolbar)
' Set the buttons
SendMessage(hToolBar, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0)
SendMessage(hToolBar, TB_SETEXTENDEDSTYLE, 0, TBSTYLE_EX_HIDECLIPPEDBUTTONS)
tbab.hInst = HINST_COMMCTRL
tbab.nID = IDB_STD_SMALL_COLOR
SendMessage(hToolBar, TB_ADDBITMAP, 0, &tbab)
tbb[0].iBitmap = STD_FILENEW
tbb[0].fsState = TBSTATE_ENABLED
tbb[0].fsStyle = TBSTYLE_BUTTON
tbb[0].idCommand = ID_FileNew
tbb[1].iBitmap = STD_FILEOPEN
tbb[1].fsState = TBSTATE_ENABLED
tbb[1].fsStyle = TBSTYLE_BUTTON
tbb[1].idCommand = ID_FileOpen
tbb[2].iBitmap = STD_FILESAVE
tbb[2].fsState = TBSTATE_ENABLED
tbb[2].fsStyle = TBSTYLE_BUTTON
tbb[2].idCommand = ID_FileSave
SendMessage(hToolBar, TB_SETBUTTONSIZE, 0, MAKELONG(28, 28))
SendMessage(hToolBar, TB_ADDBUTTONS, countof(tbb), &tbb)
SendMessage(hToolBar, TB_AUTOSIZE, 0, 0)
return hToolBar
end function
sub CreateRebar (sys hParent)
REBARINFO rbi
REBARBANDINFO rbBand
RECT rc
sys hRebar=GetDlgItem(hParent, ID_Rebar)
' Initialize and send the REBARINFO structure
rbi.cbSize = sizeof(REBARINFO)
rbi.fMask = 0
rbi.himl = 0
if SendMessage(hRebar, RB_SETBARINFO, 0, &rbi) = 0 then
mbox "Cannot SendMessage RB_SETBARINFO"
end if
' Initialize REBARBANDINFO for all rebar bands
rbBand.cbSize = sizeof(REBARBANDINFO)
rbBand.fMask = RBBIM_COLORS | ' clrFore and clrBack are valid
RBBIM_CHILD | ' hwndChild is valid
RBBIM_CHILDSIZE | ' cxMinChild and cyMinChild are valid
RBBIM_STYLE | ' fStyle is valid
RBBIM_ID | ' wID is valid
RBBIM_SIZE | ' cx is valid
RBBIM_TEXT | ' lpText is valid
RBBIM_BACKGROUND ' hbmBack is valid
rbBand.fStyle = RBBS_NOVERT | ' do not display in vertical orientation
RBBS_CHILDEDGE |
RBBS_FIXEDBMP
rbBand.hbmBack = 0
sys hToolbar = FillToolbar(hParent)
dword dwBtnSize = SendMessage(hToolbar, TB_GETBUTTONSIZE, 0, 0)
rbBand.clrFore = BLUE
rbBand.clrBack = YELLOW
rbBand.lpText = "Toolbar"
rbBand.hwndChild = hToolbar
rbBand.wID = ID_Toolbar
rbBand.cxMinChild = 150 'rbBand.cxIdeal
rbBand.cyMinChild = hiword(dwBtnSize)
rbBand.cx = rbBand.cxIdeal
' Insert band into rebar
if SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand) = 0 then mbox "Cannot RB_INSERTBAND hToolbar"
sys hCombobox = FillCombobox(hParent)
rbBand.clrFore = RED
rbBand.clrBack = GREEN
rbBand.lpText = "ComboBox"
rbBand.hwndChild = hCombobox
rbBand.wID = ID_Combobox
GetWindowRect (hCombobox, &rc)
rbBand.cxMinChild = 150
rbBand.cyMinChild = rc.Bottom - rc.Top
rbBand.cx = rbBand.cxIdeal
' Insert band into rebar
if SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand) = 0 then mbox "Cannot RB_INSERTBAND hCombobox"
sys hButton1=GetDlgItem(hParent, ID_Button)
rbBand.clrFore = BLACK
rbBand.clrBack = GRAY
rbBand.lpText = "A Button "
rbBand.hwndChild = hButton1
rbBand.wID = ID_Button
GetWindowRect (hButton1, &rc)
rbBand.cxMinChild = 50
rbBand.cyMinChild = rc.Bottom - rc.Top
rbBand.cx = rbBand.cxIdeal
if SendMessage(hRebar, RB_INSERTBAND, -1, &rbBand) = 0 then mbox "Cannot RB_INSERTBAND hButton1"
end sub