Jump to content
Sign in to follow this  
Kip

Simple scrollbars

Recommended Posts

Kip

I know that there are more topics about this, but none of them have a clear answer.

Is there a simple scrollbar function? Like: _SetScrollbars($hGui, $aWidth, $aHeight)

Example: The window is 200x200 large, now I use that function:

_SetScrollbars($hGui, 200, 600)

So now I can scroll down 400 pixels.

I know that _GUIScrollBars exist, but thats complicated, it uses DllStructGet/SetData and ?device units?.

Isn't there an easier method?

Thnx, Kip

Edited by Kip

Share this post


Link to post
Share on other sites
Kip

I know how to get it it working, but I just don't know how to set the maximal scrollheight correctly.

Because if I enter something with _GUIScrollBars_SetScrollInfoMax(), well lets say that I enter 10,

It comes pretty close to what I want, but what does 10 mean? Where does it stand for?

Edited by Kip

Share this post


Link to post
Share on other sites
ProgAndy

I tried to write the _SimpleScrollbar Funcs. Also, a Func to get the bottom Y coordinate of your PropertiesList ( = Max Scroll pos :) )

//Edit: Still needs the GUIScrollbar.au3 and the WM_ funcs out of the HelpFile.

CODE
_SimpleScrollInit($GUI,1,0)

_SimpleScrollRange($GUI,$SB_VERT,_PropList_GetHeight($PropertiesList))

Func _SimpleScrollInit($GUI,$Vert = 1, $horz = 1)

_GUIScrollBars_EnableScrollBar($Gui)

_GUIScrollBars_Init($Gui)

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

If Not $Vert Then

_GUIScrollBars_ShowScrollBar($Gui, $SB_VERT, False)

_GUIScrollBars_ShowScrollBar($Gui, $SB_VERT, False)

Else

GUIRegisterMsg($WM_VSCROLL, "WM_"&"VSCROLL")

EndIf

If Not $horz Then

_GUIScrollBars_ShowScrollBar($Gui, $SB_HORZ, False)

_GUIScrollBars_ShowScrollBar($Gui, $SB_HORZ, False)

Else

GUIRegisterMsg($WM_VSCROLL, "WM_"&"HSCROLL")

EndIf

EndFunc

Func _SimpleScrollRange($GUI,$Bar, $ScrollPix)

If $Bar <> $SB_VERT And $Bar <> $SB_HORZ Then Return -1

Return _GUIScrollBars_SetScrollRange($Gui, $Bar, 0, Floor($ScrollPix/_GUIScrollBars_GetScrollUnits($Gui,$SB_VERT)))

EndFunc

;Prog@ndy

Func _GUIScrollBars_GetScrollUnits($hWnd,$Scroll)

Local $x, $s

Switch $Scroll

Case $SB_VERT

$s = 3

Case $SB_HORZ

$s = 2

Case Else

Return SetError(1,0,-1)

EndSwitch

For $x = 0 To UBound($aSB_WindowInfo) - 1

If $aSB_WindowInfo[$x][0] = $Hwnd Then

Return $aSB_WindowInfo[$x][$s]

ExitLoop

EndIf

Next

EndFunc

Func _PropList_GetHeight($Proplist)

Local $ItemID = UBound($Proplist) - 1, $pos

$Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_INPUT) Or BitAND($Style, $PL_LABEL) Then

$pos = ControlGetPos(GUICtrlGetHandle($Proplist[$ItemID][0]), "", "")

Else

$pos = ControlGetPos(GUICtrlGetHandle($Proplist[$ItemID][1]), "", "")

EndIf

;~ MsgBox(0, '', $pos[1] & " - " & $pos[3] & " - " & 2)

Return $pos[1] + $pos[3] + 2

EndFunc ;==>_PropList_GetHeight

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Kip

Still doesnt work perfectly.

I'm trying to get this function to work. It should work with your function, but it does not perfectly. Item 19 is only shown partly:

CODE
Func _PropList_Dropdown_Checklist($PropControl, $Proplist, $ItemID, $CheckItems, $PreferHeight=60, $PreferWidth=0, $BkColor=0)

$SelectionList = 1

$Pos = _PropList_ItemGetValuePos($Proplist,$ItemID)

$win = WinGetPos($PropControl[6])

$hWnd = $PropControl[6]

$iWidth = _WinAPI_GetClientWidth($hWnd)

$iBorder = Int((_WinAPI_GetWindowWidth($hWnd)-$iWidth)/2)

$iHeight = _WinAPI_GetClientHeight($hWnd)

$iTitle = Int(_WinAPI_GetWindowHeight($hWnd)-$iHeight-$iBorder)

$X = $Pos[0]

$Y = $Pos[1]

$Width = $Pos[2]

$Height = $Pos[3]

ReDim $ChecklistItems[uBound($CheckItems)]

If not $PreferWidth Then

$Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_BROWSEBUTTON) Then

$Width += 19

EndIf

Else

$Width = $PreferWidth

EndIf

$SeparatorChar = Opt("GUIDataSeparatorChar")

$SelectionGui = GUICreate("",$Width-2, $PreferHeight, $win[0]+$x+$iBorder,$win[1]+$y+$iTitle+$Height, $WS_POPUPWINDOW,$WS_EX_TOPMOST, $hWnd)

If $BkColor Then

GUISetBkColor($BkColor)

EndIf

For $i = 0 to UBound($CheckItems)-1

$Split = StringSplit($CheckItems[$i],$SeparatorChar)

$State = $Split[1]

$Value = StringReplace($CheckItems[$i],$State&$SeparatorChar,"",1)

$ChecklistItems[$i] = GUICtrlCreateCheckbox($Value,3,3+($i*15),$Width-10,13)

If $State = "1" Then

GUICtrlSetState(-1,$GUI_CHECKED)

EndIf

Next

_SimpleScrollInit($SelectionGui,1,0)

_SimpleScrollRange($SelectionGui,$SB_VERT,((UBound($CheckItems)-1)*15-15))

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

GUISetState()

GUIRegisterMsg(0x0112,"SelectionCheckUpdate")

GUIRegisterMsg(0x0216,"SelectionCheckUpdate")

While 1

$cInfo = GUIGetCursorInfo($SelectionGui)

If not @error Then

If $cInfo[2] Then

If $cInfo[0] >= 0 and $cInfo[1] >= 0 and $cInfo[0] <= $Width And $cInfo[1] <= $PreferHeight Then ; If clicked inside the window

Else ; Outside the window

ExitLoop

EndIf

Else

If _IsPressed("0D",$User32) Then

ExitLoop

Else

If $SelectionList = 0 Then

ExitLoop

EndIf

EndIf

EndIf

Else

ExitLoop

EndIf

WEnd

dim $Return[uBound($CheckItems)]

for $i = 0 to UBound($CheckItems)-1

If GUICtrlGetState($ChecklistItems[$i]) = $GUI_CHECKED Then

$State = "1"

Else

$State = "0"

EndIf

$Value = GUICtrlRead($ChecklistItems[$i],1)

$Return[$i] = $State & $SeparatorChar & $Value

Next

GUIDelete($SelectionGui)

GUIRegisterMsg(0x0112,"")

GUIRegisterMsg(0x0216,"")

Return $Return

EndFunc

Use it like this:

ElseIf $ItemID = $Item_Style Then
    
    $Checklist[0] = "0|item1"; 0 = not checked
    $Checklist[1] = "1|item2"; 1 = checked
    $Checklist[2] = "1|item3"
    $Checklist[3] = "0|item4"
    $Checklist[4] = "1|item5"
    $Checklist[5] = "1|item5"
    $Checklist[6] = "1|item5"
    $Checklist[7] = "1|item5"
    $Checklist[8] = "1|item5"
    $Checklist[9] = "1|item5"
    $Checklist[10] = "1|item5"
    $Checklist[11] = "1|item5"
    $Checklist[12] = "1|item13"
    $Checklist[13] = "1|item14"
    $Checklist[14] = "1|item15"
    $Checklist[15] = "1|item5"
    $Checklist[16] = "1|item5"
    $Checklist[17] = "1|item13"
    $Checklist[18] = "1|item14"
    $Checklist[19] = "1|item19"

    
    _PropList_Dropdown_Checklist($PropertiesControl, $PropertiesList, $ItemID, $Checklist, 120)

EndIf

Edit: And declare $Checklist somewhere at the beginning of your script

Edited by Kip

Share this post


Link to post
Share on other sites
ProgAndy

Use a TreeView with Checkbox Style :) Then it's easier, Because you don't have to think about the Scrolling

Requires

#include <TreeViewConstants.au3>

#include <GUITreeView.au3>

CODE
Func _PropList_Dropdown_Checklist($PropControl, $Proplist, $ItemID, $CheckItems, $PreferHeight = 60, $PreferWidth = 0, $BkColor = 0)

Local $Style, $pos, $win, $y,$Width,$Height,$OK,$Return,$ChecklistItems,$State

$pos = _PropList_ItemGetValuePos($Proplist, $ItemID)

$win = WinGetPos($PropControl[6])

$hWnd = $PropControl[6]

Local $Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_INPUT) Or BitAND($Style, $PL_LABEL) Then

Local $win = WinGetPos(GUICtrlGetHandle($Proplist[$ItemID][0]))

Else

Local $win = WinGetPos(GUICtrlGetHandle($Proplist[$ItemID][1]))

EndIf

$y = $pos[3]

$Width = $pos[2]

$Height = $pos[3]

Local $ChecklistItems[uBound($CheckItems)]

Local $Return[uBound($CheckItems)]

If Not $PreferWidth Then

$Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_BROWSEBUTTON) Then

$Width += 19

EndIf

Else

$Width = $PreferWidth

EndIf

$SeparatorChar = Opt("GUIDataSeparatorChar")

$SelectionGui = GUICreate("", $Width - 2, $PreferHeight, $win[0] , $win[1] + $y , $WS_POPUPWINDOW, $WS_EX_TOPMOST, $hWnd)

$OK = GUICtrlCreateButton("OK",1,0,$Width-2,16,$BS_DEFPUSHBUTTON)

Local $Tree = GUICtrlCreateTreeView(0, 16, $Width, $PreferHeight-16, BitOR($TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS ), $WS_EX_CLIENTEDGE)

If $BkColor Then

GUISetBkColor($BkColor)

_GUICtrlTreeView_SetBkColor($Tree,$BkColor)

EndIf

For $i = 0 To UBound($CheckItems) - 1

$Split = StringSplit($CheckItems[$i], $SeparatorChar)

$State = $Split[1]

$Value = StringReplace($CheckItems[$i], $State & $SeparatorChar, "", 1)

$Return[$i] = $Value

$ChecklistItems[$i] = GUICtrlCreateTreeViewItem($Value,$Tree)

If $State = "1" Then

GUICtrlSetState(-1, $GUI_CHECKED)

EndIf

Next

GUISetState()

While WinActive($SelectionGui)

$cInfo = GUIGetCursorInfo($SelectionGui)

$nMsg = GUIGetMsg(1)

Select

;~ Case $cInfo[2]

Case $nMsg[1] = $SelectionGui And $nMsg[0] = $OK

ExitLoop

Case _IsPressed("0D", $User32)

ExitLoop

Case $nMsg[0] = $GUI_EVENT_CLOSE

ExitLoop

Case $nMsg[1] > 0 And $nMsg[1] <> $SelectionGui

ExitLoop

EndSelect

WEnd

For $i = 0 To UBound($CheckItems) - 1

If BitAND(GUICtrlRead($ChecklistItems[$i]),$GUI_CHECKED) = $GUI_CHECKED Then

$State = "1"

Else

$State = "0"

EndIf

$Value = $Return[$i]

$Return[$i] = $State & $SeparatorChar & $Value

Next

GUIDelete($SelectionGui)

Return $Return

EndFunc ;==>_PropList_Dropdown_Checklist

//Edit: And the _SimpleScroll would work, if you used (UBound($CheckItems)*15)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
ProgAndy
:) Now you could add an optional StartIndex Parameter, so we can use StringSplit to Fill the OptionList from the Field.

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Kip

Now you could add an optional StartIndex Parameter, so we can use StringSplit to Fill the OptionList from the Field.

a small explanation of that, please :)

Share this post


Link to post
Share on other sites
ProgAndy

OK, I'll try:

We have a string in your propertylist. ( "0|item1}|{1|item2}|{0|item3"

This string should be the Array. Now we use StringSplit to split the Strign to the Array:

$Array = StringSplit($Value,"}|{",1)

Now $Array[0] is no Item, but the Count of items. In the ControlDropdown, this shouldN#t be shown

--> Optional Parameter $StartIndex, Default = 0

--> Call DropDown_List with $StartIndex = 1

--> For $i = StartIndex To Ubound($Array)-1

--> We can now skip the fisrt Parameter, if it is no Option

On return of the Array:

$String = ""

For $i = 1 To Ubound($Return)-1

$String &= $Return[$i] & "}|{"

Next

$String = StringTrimRight($String,3)

_Property_SetValue($String)

####

That's it :)

Edited by ProgAndy

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites
Kip

like:

Func _PropList_Dropdown_Checklist($PropControl, $Proplist, $ItemID, $CheckItems, $PreferHeight = 60, $PreferWidth = 0, $BkColor = 0)
Local $Style, $pos, $win, $y,$Width,$Height,$OK,$Return,$ChecklistItems,$State
$pos = _PropList_ItemGetValuePos($Proplist, $ItemID)
$win = WinGetPos($PropControl[6])

$hWnd = $PropControl[6]
Local $Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_INPUT) Or BitAND($Style, $PL_LABEL) Then
Local $win = WinGetPos(GUICtrlGetHandle($Proplist[$ItemID][0]))
Else
Local $win = WinGetPos(GUICtrlGetHandle($Proplist[$ItemID][1]))
EndIf

$y = $pos[3]
$Width = $pos[2]
$Height = $pos[3]

Local $ChecklistItems[UBound($CheckItems)]
Local $Return[UBound($CheckItems)-$StartIndex]

If Not $PreferWidth Then

$Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_BROWSEBUTTON) Then
$Width += 19
EndIf

Else

$Width = $PreferWidth

EndIf

$SeparatorChar = Opt("GUIDataSeparatorChar")

$SelectionGui = GUICreate("", $Width, $PreferHeight, $win[0] , $win[1] + $y , $WS_POPUP, $WS_EX_TOPMOST, $hWnd)

Local $Tree = GUICtrlCreateTreeView(0, 0, $Width, $PreferHeight, BitOR($TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS ), $WS_EX_CLIENTEDGE)

If $BkColor Then
GUISetBkColor($BkColor)
_GUICtrlTreeView_SetBkColor($Tree,$BkColor)
EndIf

For $i = $StartIndex To UBound($CheckItems) - 1

$Split = StringSplit($CheckItems[$i], $SeparatorChar)

$State = $Split[1]
$Value = StringReplace($CheckItems[$i], $State & $SeparatorChar, "", 1)
$Return[$i] = $Value
$ChecklistItems[$i] = GUICtrlCreateTreeViewItem($Value,$Tree)
If $State = "1" Then
GUICtrlSetState(-1, $GUI_CHECKED)
EndIf

Next

GUISetState()

GUIRegisterMsg(0x0216,"MovingList")


While WinActive($SelectionGui)

$cInfo = GUIGetCursorInfo($SelectionGui)
$nMsg = GUIGetMsg(1)

Select
;~ Case $cInfo[2]
Case $nMsg[1] = $SelectionGui And $nMsg[0] = $OK
ExitLoop
Case _IsPressed("0D", $User32)
ExitLoop
Case $nMsg[0] = $GUI_EVENT_CLOSE
ExitLoop
Case $nMsg[1] > 0 And $nMsg[1] <> $SelectionGui
ExitLoop
EndSelect
WEnd


For $i = $StartIndex To UBound($CheckItems) - 1
If BitAND(GUICtrlRead($ChecklistItems[$i]),$GUI_CHECKED) = $GUI_CHECKED Then
$State = "1"
Else
$State = "0"
EndIf

$Value = $Return[$i]

$Return[$i] = $State & $SeparatorChar & $Value
Next

GUIDelete($SelectionGui)

Return $Return

EndFunc;==>_PropList_Dropdown_Checklist
? :) Edited by Kip

Share this post


Link to post
Share on other sites
ProgAndy

Not complete: I meant it like this:

CODE
Func _PropList_Dropdown_Checklist($PropControl, $Proplist, $ItemID, $CheckItems, $PreferHeight = 60, $PreferWidth = 0, $BkColor = 0,$StartIndex=0) ; <===== Here Start Index as Parameter

Local $Style, $pos, $win, $y,$Width,$Height,$OK,$Return,$ChecklistItems,$State

$pos = _PropList_ItemGetValuePos($Proplist, $ItemID)

$win = WinGetPos($PropControl[6])

$hWnd = $PropControl[6]

Local $Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_INPUT) Or BitAND($Style, $PL_LABEL) Then

Local $win = WinGetPos(GUICtrlGetHandle($Proplist[$ItemID][0]))

Else

Local $win = WinGetPos(GUICtrlGetHandle($Proplist[$ItemID][1]))

EndIf

$y = $pos[3]

$Width = $pos[2]

$Height = $pos[3]

Local $ChecklistItems[uBound($CheckItems)];<===== Not Here

Local $Return[uBound($CheckItems)] ;<===== Not Here

If Not $PreferWidth Then

$Style = _PropList_ItemGetStyle($Proplist, $ItemID)

If BitAND($Style, $PL_BROWSEBUTTON) Then

$Width += 19

EndIf

Else

$Width = $PreferWidth

EndIf

$SeparatorChar = Opt("GUIDataSeparatorChar")

$SelectionGui = GUICreate("", $Width - 2, $PreferHeight, $win[0] , $win[1] + $y , $WS_POPUPWINDOW, $WS_EX_TOPMOST, $hWnd)

$OK = GUICtrlCreateButton("OK",1,0,$Width-2,16,$BS_DEFPUSHBUTTON)

Local $Tree = GUICtrlCreateTreeView(0, 16, $Width, $PreferHeight-16, BitOR($TVS_CHECKBOXES, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS ), $WS_EX_CLIENTEDGE)

If $BkColor Then

GUISetBkColor($BkColor)

_GUICtrlTreeView_SetBkColor($Tree,$BkColor)

EndIf

For $i = $StartIndex To UBound($CheckItems) - 1 ;<===== Start Index used Here

$Split = StringSplit($CheckItems[$i], $SeparatorChar)

$State = $Split[1]

$Value = StringReplace($CheckItems[$i], $State & $SeparatorChar, "", 1)

$Return[$i] = $Value

$ChecklistItems[$i] = GUICtrlCreateTreeViewItem($Value,$Tree)

If $State = "1" Then

GUICtrlSetState(-1, $GUI_CHECKED)

EndIf

Next

GUISetState()

While WinActive($SelectionGui)

$cInfo = GUIGetCursorInfo($SelectionGui)

$nMsg = GUIGetMsg(1)

Select

;~ Case $cInfo[2]

Case $nMsg[1] = $SelectionGui And $nMsg[0] = $OK

ExitLoop

Case _IsPressed("0D", $User32)

ExitLoop

Case $nMsg[0] = $GUI_EVENT_CLOSE

ExitLoop

Case $nMsg[1] > 0 And $nMsg[1] <> $SelectionGui

ExitLoop

EndSelect

WEnd

For $i = $StartIndex To UBound($CheckItems) - 1 ;<===== Start Index used Here

If BitAND(GUICtrlRead($ChecklistItems[$i]),$GUI_CHECKED) = $GUI_CHECKED Then

$State = "1"

Else

$State = "0"

EndIf

$Value = $Return[$i]

$Return[$i] = $State & $SeparatorChar & $Value

Next

GUIDelete($SelectionGui)

Return $Return

EndFunc ;==>_PropList_Dropdown_Checklist

I made comments in the lines where to use :) And You shouldn't use it here: Local $Return[uBound($CheckItems)-$StartIndex]

And the GUIRegisterMsg(0x0216,"MovingList") can be placed in the Creation of the Properties List, so it's only called once. :(


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.