Another possible usage of the ReBar - you can create number of horizontaly movable bands. User can move bands up or down thus order the list of gui elements the way he wants. I created sample of this by using several Text controls wich can be moved up/down. This builds the menu in order you specify, that can be seen when you click the button. You can use anything you like, as a band content.
Code:
#singleinstance, force
Gui, +LastFound +ToolWindow
hwnd := WinExist()
;Gui, Add, comboBox, w200 hwndhCombo, 1|2|3||4
Gui, Font, s14 bold
Gui, Add, Text, w200 hidden hwndhText1 h25, Text 1
Gui, Add, Text, w200 hidden hwndhText2 h25, Text 2
Gui, Add, Text, w200 hidden hwndhText3 h25, Text 3
Gui, Add, Text, w200 hidden hwndhText4 h25, Text 4
Gui, Add, Text, w200 hidden hwndhText5 h25, Text 5
Gui, Add, Text, w200 hidden hwndhText6 h25, Text 6
Gui, Font, s10 bold
Gui, Add, Button, X30 Y160 gOnBtn, Show Me
Gui, Show, w140 h200
;Gui 2:+LastFound -Caption +ToolWindow
;h := WinExist()
;Gui 2:Add, button,x0,1
;Gui 2:Add, button,x+0 ,2
;Gui 2:Add, button,x+0 ,3
;Gui 2:Add, ComboBox, vACombo x0
;Gui 2:Add, ListView, vAList x0
;gui 2:show, autosize hide
;Rebar_Add(hwnd, hCombo, "Combo", true)
hBar := Rebar_Add(hwnd, hText1, "Text1", true)
Rebar_Add(hwnd, hText2, "Text2", true)
Rebar_Add(hwnd, hText3, "Text3", true)
Rebar_Add(hwnd, hText4, "Text4", true)
Rebar_Add(hwnd, hText5, "Text5", true)
Rebar_Add(hwnd, hText6, "Text6", true)
;Rebar_Add(hwnd, h, "Gui", true)
return
OnBtn:
Menu, showme, useerrorlevel
Menu, showme, delete,
loop, % RB_GetBandCount(hBar)
{
hTxt := RB_GetBandInfo(hBar, A_Index-1)
ControlGetText, txt, ,ahk_id %hTxt%
StringReplace, txt, txt, ,,A
Menu, showme, add, %txt%, Onmenu
}
Menu, showme, show
return
Onmenu:
msgbox You had to click ! Go away, n00b !
return
RB_GetBandCount(hCtrl) {
static RB_GETBANDCOUNT := 0x40C
SendMessage, RB_GETBANDCOUNT, 0, 0, , ahk_id %hCtrl%
return ErrorLevel
}
RB_GetBandInfo(hCtrl, idx, info="CHILD") {
static RBBIM_CHILD = 0x10, RBBIM_STYLE = 0x1, RBBIM_TEXT = 0x4, RBBIM_CHILDSIZE = 0x20,RBBIM_SIZE = 0x40
static RB_GETBANDINFO=0x405
f = RBBIM_%info%
VarSetCapacity( BAND, 80, 0 )
NumPut(80, BAND, 0)
NumPut(%f%, BAND, 4)
if f=RBBIM_TEXT
{
VarSetCapacity(Text, 64 )
NumPut(&Text,BAND, 20) ;lpText
NumPut(64,BAND, 24)
}
SendMessage, RB_GETBANDINFO, idx, &BAND,, ahk_id %hCtrl%
ifEqual, ErrorLevel, 0, return "Err: can't get band info"
;for now return only child
return NumGet(BAND, 32)
}
Rebar_Add(hGui, hCtrl, text, break = false) {
static ICC_COOL_CLASSES := 0x400, REBARCLASSNAME = "ReBarWindow32"
static WS_EX_TOOLWINDOW := 0x80, WS_CHILD := 0x40000000, WS_VISIBLE := 0x10000000, WS_CLIPSIBLINGS = 0x4000000, WS_CLIPCHILDREN = 0x2000000
static RBS_VARHEIGHT=0x200, CCS_NODIVIDER = 0x40, RBS_BANDBORDERS=0x400, RB_INSERTBAND = 0x401, RBS_AUTOSIZE=0x2000
static RBBIM_CHILD = 0x10, RBBIM_STYLE = 0x1, RBBIM_TEXT = 0x4, RBBIM_CHILDSIZE = 0x20,RBBIM_SIZE = 0x40
static RBBS_BREAK=1, RBBS_FIXEDBMP=0x20, RBBS_NOVERT=0x10, RBBS_CHILDEDGE=0x4, RBBS_USECHEVRON=0x200, RBBS_FIXEDSIZE=0x2, RBBS_GRIPPERALWAYS = 0x80, RBBS_HIDETITLE = 0x400, RBBS_NOGRIPPER = 0x100, RBBS_TOPALIGN = 0x800
static init, hReBar
DetecthiddenWindows, on
if !init
{
init := true
VarSetCapacity(ICCE, 8)
NumPut(8, ICCE, 0)
NumPut(ICC_COOL_CLASSES, ICCE, 4)
if !DllCall("comctl32.dll\InitCommonControlsEx", "uint", &ICCE)
return "Err: can't initialise common controls"
hRebar := DllCall("CreateWindowEx"
, "uint", WS_EX_TOOLWINDOW
, "str", REBARCLASSNAME
, "uint", 0
, "uint", WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | RBS_VARHEIGHT | CCS_NODIVIDER
, "uint", 0, "uint", 0, "uint", 0, "uint", 0
, "uint", hGui
, "uint", 0
, "uint", 0
, "uint", 0, "Uint")
ifEqual, hRebar, 0, return "Err: can't create rebar"
}
VarSetCapacity( BAND, 80, 0 )
NumPut(80,BAND, 0)
fMask := RBBIM_STYLE | RBBIM_TEXT | RBBIM_CHILD | RBBIM_CHILDSIZE | RBBIM_SIZE
; fStyle := RBBS_CHILDEDGE | RBBS_GRIPPERALWAYS ; | RBBS_FIXEDSIZE
fstyle := RBBS_HIDETITLE
fStyle |= break ? RBBS_BREAK : 0
NumPut(fMask, BAND, 4)
NumPut(fStyle, BAND, 8)
if DllCall("IsChild", "uint", hCtrl)
ControlGetPos, ,,,h, ,ahk_id %hCtrl%
else WinGetPos , ,,,h, ahk_id %hCtrl%
NumPut(&Text ,BAND, 20) ;lpText
NumPut(hCtrl ,BAND, 32) ;hwndChild
NumPut(1000 ,BAND, 36) ;cyMinChild
NumPut(h ,BAND, 40) ;cyMinChild
NumPut(1000 ,BAND, 44) ;cx
SendMessage, RB_INSERTBAND, -1, &BAND,, ahk_id %hReBar%
ifEqual, ErrorLevel, 0, return "Err: can't create band"
return hReBar
}