Sign in to follow this  
Followers 0
wolf9228

VSCROLL_GUICreate

1 post in this topic

#1 ·  Posted (edited)

VSCROLL_GUICreate.zip

VSCROLL_GUICreate.au3

#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Global $CLLArray = 0

Func VSCROLL_GUICreate($W,$H,$L,$T,$Title = "",$Style = 0,$ExStyle = 0 ,$Parent = 0)

if Not IsArray($CLLArray) Then
Dim $CLLArray[2][6]
Else
ReDim $CLLArray[UBound($CLLArray) + 1][6]
EndIf

if Not $Parent Then
if $Style = 0 Then $Style = _
BitOR($WS_MINIMIZEBOX,$WS_SYSMENU,$WS_CAPTION _
,$WS_POPUP,$WS_POPUPWINDOW,$WS_GROUP,$WS_BORDER, _
$WS_CLIPSIBLINGS , $WS_VSCROLL)
If $ExStyle = 0 Then $ExStyle = $WS_EX_WINDOWEDGE
If Not BitAND($Style,$WS_VSCROLL) = $WS_VSCROLL Then $Style += $WS_VSCROLL
$Gui = GUICreate($Title,$W,$H,$L,$T,$Style,$ExStyle)
$CLLArray[UBound($CLLArray) - 1][0] = $Gui
Else
if $Style = 0 Then $Style = $WS_CHILD + $WS_VSCROLL
If $ExStyle = 0 Then $ExStyle = $WS_EX_CLIENTEDGE
If Not BitAND($Style,$WS_CHILD) = $WS_CHILD Then $Style += $WS_CHILD
If Not BitAND($Style,$WS_VSCROLL) = $WS_VSCROLL Then $Style += $WS_VSCROLL
$Gui = GUICreate($Title,$W,$H,$L,$T,$Style,$ExStyle,$Parent)
$CLLArray[UBound($CLLArray) - 1][0] = $Gui
EndIf

GUIRegisterMsg($WM_SIZE,"MessageProc")
GUIRegisterMsg($WM_VSCROLL,"MessageProc")

$NewPos = 0
$CLLArray[UBound($CLLArray) - 1][1] = $NewPos
$SatartPos = 0
$CLLArray[UBound($CLLArray) - 1][2] = $SatartPos
$SizeOfScrollMove = 5
$CLLArray[UBound($CLLArray) - 1][3] = $SizeOfScrollMove
$ScrollHeight = $H
$CLLArray[UBound($CLLArray) - 1][4] = $ScrollHeight

Return $Gui
EndFunc

Func VSCROLL_SetOptions($Hwnd,$ScrollHeight,$SizeOfScrollMove = 10)
Local $SB_VSVERT = 1
$Element = ArraySearch($Hwnd)
If $Element = -1 Then Return False
$ClientHeight = _WinAPI_GetClientHeight($Hwnd)
$CLLArray[$Element][3] = $SizeOfScrollMove
$CLLArray[$Element][4] = $ScrollHeight
$CLLArray[$Element][5] = $ClientHeight
$ScrollHeight -= $ClientHeight
If SetScrollInfo($Hwnd,$SB_VSVERT,0,$ScrollHeight) Then
Return True
Else
Return False
EndIf
EndFunc

Func VSCROLL_GUIDelete($Hwnd)
$Element = ArraySearch($Hwnd)
If $Element = -1 Then Return False
Local $TempArray[UBound($CLLArray) - 1][6] ,$j = 0
For $i = 0 To UBound($CLLArray) - 1
If $Element <> $i Then
$TempArray[$j][0] = $CLLArray[$i][0]
$TempArray[$j][1] = $CLLArray[$i][1]
$TempArray[$j][2] = $CLLArray[$i][2]
$TempArray[$j][3] = $CLLArray[$i][3]
$TempArray[$j][4] = $CLLArray[$i][4]
$TempArray[$j][5] = $CLLArray[$i][5]
$j += 1
Else
GUIDelete($CLLArray[$i][0])
EndIf
Next
$CLLArray = $TempArray
Return True
EndFunc

Func SetScrollInfo($Hwnd,$nBar,$nMin,$nMax,$nPage = 0 ,$nPos = 0,$nTrackPos = 0)
Local _
$tagSCROLLINFO = "UINT cbSize;UINT fMask;int nMin;int nMax;" & _
"int nPage;int nPos;int nTrackPos" , _
$SIF_VSRANGE = 0x0001 , _
$SIF_VSPAGE = 0x0002 , _
$SIF_VSPOS = 0x0004 , _
$SIF_VSDISABLENOSCROLL = 0x0008 , _
$SIF_VSTRACKPOS = 0x0010
Local $SIF_VSALL = ($SIF_VSRANGE + $SIF_VSPAGE + $SIF_VSPOS + $SIF_VSTRACKPOS)
$SCROLLINFO = DllStructCreate($tagSCROLLINFO)
DllStructSetData($SCROLLINFO,"cbSize",DllStructGetSize($SCROLLINFO))
DllStructSetData($SCROLLINFO,"fMask",$SIF_VSALL)
DllStructSetData($SCROLLINFO,"nMin",$nMin)
DllStructSetData($SCROLLINFO,"nMax",$nMax)
DllStructSetData($SCROLLINFO,"nPage",$nPage)
DllStructSetData($SCROLLINFO,"nPos",$nPos)
DllStructSetData($SCROLLINFO,"nTrackPos",$nTrackPos)
$lpsi = DllStructGetPtr($SCROLLINFO)
$PrePos = DllCall("User32.dll","int","SetScrollInfo","HWND",$hWnd _
,"int",$nBar,"ptr",$lpsi,"int",True)
if @error Then Return ""
Return $PrePos[0]
EndFunc

Func MessageProc($hWnd, $Msg, $wParam, $lParam)
Local $SB_VSVERT = 1

$Element = ArraySearch($Hwnd)
If $Element = -1 Then Return $GUI_RUNDEFMSG

$Hwnd = $CLLArray[$Element][0]
$NewPos = $CLLArray[$Element][1]
$SatartPos = $CLLArray[$Element][2]
$SizeOfScrollMove = $CLLArray[$Element][3]
$ScrollHeight = $CLLArray[$Element][4]
$ClientHeight = $CLLArray[$Element][5]
$ScrollHeight -= $ClientHeight

Select
Case $Msg = $WM_SIZE
$NewClientHeight = BitShift($lParam,16)
$ClientHeight = $CLLArray[$Element][5]
$ScrollHeight = $CLLArray[$Element][4]
$NewScrollHeight = Round($NewClientHeight / $ClientHeight * $ScrollHeight,0)
$CLLArray[$Element][5] = $NewClientHeight
$CLLArray[$Element][4] = $NewScrollHeight
$NewPos = 0
$SatartPos = 0
$CLLArray[$Element][1] = $NewPos
$CLLArray[$Element][2] = $SatartPos
$NewScrollHeight -= $NewClientHeight
SetScrollInfo($Hwnd,$SB_VSVERT,0,$NewScrollHeight,$SizeOfScrollMove)

Case $Msg = $WM_VSCROLL
Local _
$SB_VSBOTTOM = 7 , _
$SB_VSENDSCROLL = 8 , _
$SB_VSLINEDOWN = 1 , _
$SB_VSLINEUP = 0 , _
$SB_VSPAGEDOWN = 3 , _
$SB_VSPAGEUP = 2 , _
$SB_VSTHUMBPOSITION = 4 , _
$SB_VSTHUMBTRACK    = 5 , _
$SB_VSTOP = 6
$nScrollCode = BitAND($wParam,0x0000FFFF) ;lowr
$currentposition = BitShift($wParam,16)
Switch $nScrollCode
Case $SB_VSLINEDOWN
$YAmount = Min($SizeOfScrollMove,$ScrollHeight - $NewPos)
$NewPos += $YAmount
SetScrollPos($hWnd,$SB_VSVERT,$NewPos)
ScrollWindow($hWnd,- $YAmount)
Case $SB_VSLINEUP
$YAmount = Min($SizeOfScrollMove,$NewPos)
$NewPos -= $YAmount
SetScrollPos($hWnd,$SB_VSVERT,$NewPos)
ScrollWindow($hWnd,$YAmount)
Case $SB_VSPAGEDOWN
$YAmount = Min($SizeOfScrollMove,$ScrollHeight - $NewPos)
$NewPos += $YAmount
SetScrollPos($hWnd,$SB_VSVERT,$NewPos)
ScrollWindow($hWnd,- $YAmount)
Case $SB_VSPAGEUP
$YAmount = Min($SizeOfScrollMove,$NewPos)
$NewPos -= $YAmount
SetScrollPos($hWnd,$SB_VSVERT,$NewPos)
ScrollWindow($hWnd,$YAmount)
Case $SB_VSTHUMBTRACK
If $currentposition > $NewPos Then
$YAmount = ($currentposition - $NewPos)
SetScrollPos($hWnd,$SB_VSVERT,$NewPos)
ScrollWindow($hWnd,- $YAmount)
$NewPos = $currentposition
Else
$YAmount = ($NewPos - $currentposition)
SetScrollPos($hWnd,$SB_VSVERT,$NewPos)
ScrollWindow($hWnd,$YAmount)
$NewPos = $currentposition
EndIf
EndSwitch

EndSelect

$CLLArray[$Element][1] = $NewPos
$CLLArray[$Element][2] = $SatartPos

Return $GUI_RUNDEFMSG
EndFunc

Func ArraySearch($Hwnd)
if Not IsArray($CLLArray) Then Return -1
For $Element = 0 To UBound($CLLArray) - 1
If $CLLArray[$Element][0] = $Hwnd Then Return $Element
Next
Return -1
EndFunc

Func SetScrollPos($hWnd,$nBar,$nPos,$bRedraw = True)
$PrePos = DllCall("User32.dll","int","SetScrollPos","HWND",$hWnd _
,"int",$nBar,"int",$nPos,"int",$bRedraw)
if @error Then Return ""
Return $PrePos[0]
EndFunc

Func ScrollWindow($hWnd,$YAmount)
$BOOL = DllCall("User32.dll","int","ScrollWindow","HWND",$hWnd _
,"int",0,"int",$YAmount,"ptr",0,"ptr",0)
if @error Then Return 0
Return $BOOL[0]
EndFunc

Func Min($NO1,$NO2)
if $NO1 < $NO2 Then
Return $NO1
Else
Return $NO2
EndIf
EndFunc
 

Example
Downloader Progress

#include <VSCROLL_GUICreate.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

HotKeySet("{ESC}", "Terminate")

$Parent = GUICreate("Downloader Progress",650,350,100,10)
GUISetState()
$GUI1 = VSCROLL_GUICreate(590,140,30,10,"",0,0,$Parent)
For $i = 0 To 100
GUICtrlCreateProgress(190,$i * 30,200,20)
GUICtrlCreateLabel("Label " & $i,10,$i * 30,170,20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1,10,600,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlCreateLabel("Slow movement",400,$i * 30,170,20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1,10,600,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,0xFFFFFF)
Next
GUISetState()
VSCROLL_SetOptions($GUI1,($i * 30),1) ;$SizeOfScrollMove = 1 Very Slow movement
; ScrollHeight = ($i * 30)
$GUI2 = VSCROLL_GUICreate(590,140,30,175,"",0,0,$Parent)
For $i = 0 To 100
GUICtrlCreateProgress(190,$i * 30,200,20)
GUICtrlCreateLabel("Label " & $i,10,$i * 30,170,20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1,10,600,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlCreateLabel("Fast Movement",400,$i * 30,170,20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1,10,600,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,0xFFFFFF)
Next
GUISetState()
VSCROLL_SetOptions($GUI2,($i * 30),30) ;$SizeOfScrollMove = 30 Fast Movement
; ScrollHeight = ($i * 30)
$GUI3 = VSCROLL_GUICreate(590,140,100,10,"Downloader Progress")
For $i = 0 To 1000
GUICtrlCreateProgress(190,$i * 30,200,20)
GUICtrlCreateLabel("Label " & $i,10,$i * 30,170,20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1,10,600,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,0xFFFFFF)
GUICtrlCreateLabel("Fast Movement",400,$i * 30,170,20,BitOR($SS_CENTER,$WS_BORDER))
GUICtrlSetFont(-1,10,600,0,"MS Sans Serif")
GUICtrlSetBkColor(-1,0xFFFFFF)
Next
GUISetState()
VSCROLL_SetOptions($GUI3,($i * 30),40) ;$SizeOfScrollMove = 40 Fast Movement
; ScrollHeight = ($i * 30)

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func Terminate()
    Exit 0
EndFunc
Edited by wolf9228

صرح السماء كان هنا

 

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  
Followers 0