Example:
I mean, keep from the yellow lines up static/unscrollable, and scroll starting from the red lines.
Code: Select all
SetBatchLines, -1
OnMessage(0x115, "OnScroll") ; WM_VSCROLL
;OnMessage(0x020A, "WM_MOUSEWHEEL")
; 0x00200000 = WS_VSCROLL
Gui, -DPIScale +Resize +0x00200000
Gui, Color, 0
Gui, Font, s20, Consolas
Gui, Add, Text, xm ym cYellow , =====================
Gui, Add, Text, xm y+10 cYellow, KEEP THIS LINE STATIC
Gui, Add, Text, xm y+10 cYellow, =====================
Gui, Font, s12, Consolas
Loop, 50
Gui, Add, Text, xm y+10 w150 cRed , %A_Index%
Gui, Show, w400 h300, Debug
Return
GuiSize:
UpdateScrollBars(A_Gui, A_GuiWidth, A_GuiHeight)
Return
;---------------------------------------------------------------------------
; OnScroll and UpdateScrollBars by Lexikos made x64/x32 compatible by jeeswg.
; https://www.autohotkey.com/boards/viewtopic.php?p=237412#p237412
OnScroll(wParam, lParam, msg, hwnd) {
Static SCROLL_STEP=30
bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
VarSetCapacity(si, 28, 0)
NumPut(28, si, 0, "uint") ; cbSize
NumPut(0x17, si, 4, "uint") ; fMask
if !DllCall("GetScrollInfo", "ptr", hwnd, "int", bar, "ptr", &si)
return
VarSetCapacity(rect, 16)
DllCall("GetClientRect", "ptr", hwnd, "ptr", &rect)
new_pos := NumGet(si, 20, "int") ; nPos
action := wParam & 0xFFFF
if action = 0 ; SB_LINEUP
new_pos -= SCROLL_STEP
else if action = 1 ; SB_LINEDOWN
new_pos += SCROLL_STEP
else if action = 2 ; SB_PAGEUP
new_pos -= NumGet(rect, 12, "int") - SCROLL_STEP
else if action = 3 ; SB_PAGEDOWN
new_pos += NumGet(rect, 12, "int") - SCROLL_STEP
else if (action = 5 || action = 4) ; SB_THUMBTRACK || SB_THUMBPOSITION
new_pos := wParam>>16
else if action = 6 ; SB_TOP
new_pos := NumGet(si, 8, "int") ; nMin
else if action = 7 ; SB_BOTTOM
new_pos := NumGet(si, 12, "int") ; nMax
else
return
min := NumGet(si, 8, "int") ; nMin
max := NumGet(si, 12, "int") - NumGet(si, 16, "uint") ; nMax-nPage
new_pos := new_pos > max ? max : new_pos
new_pos := new_pos < min ? min : new_pos
old_pos := NumGet(si, 20, "int") ; nPos
x := y := 0
if bar = 0 ; SB_HORZ
x := old_pos-new_pos
else
y := old_pos-new_pos
; Scroll contents of window and invalidate uncovered area.
DllCall("ScrollWindow", "ptr", hwnd, "int", x, "int", y, "ptr", 0, "ptr", 0)
; Update scroll bar.
NumPut(new_pos, si, 20, "int") ; nPos
DllCall("SetScrollInfo", "ptr", hwnd, "int", bar, "ptr", &si, "int", 1)
}
UpdateScrollBars(GuiNum, GuiWidth, GuiHeight) {
Static SIF_RANGE=0x1, SIF_PAGE=0x2, SIF_DISABLENOSCROLL=0x8, SB_HORZ=0, SB_VERT=1
Gui, %GuiNum%:Default
Gui, +LastFound
; Calculate scrolling area.
Left := Top := 9999
Right := Bottom := 0
WinGet, ControlList, ControlList
Loop, Parse, ControlList, `n
{
GuiControlGet, c, Pos, %A_LoopField%
if (cX < Left)
Left := cX
if (cY < Top)
Top := cY
if (cX + cW > Right)
Right := cX + cW
if (cY + cH > Bottom)
Bottom := cY + cH
}
Left -= 0
Top -= 0
Right += 0
Bottom += 0
ScrollWidth := 0 ;Right-Left
ScrollHeight := Bottom-Top
; Initialize SCROLLINFO.
VarSetCapacity(si, 28, 0)
NumPut(28, si, 0, "uint") ; cbSize
NumPut(SIF_RANGE | SIF_PAGE, si, 4, "uint") ; fMask
; Update horizontal scroll bar.
NumPut(ScrollWidth, si, 12, "int") ; nMax
NumPut(GuiWidth, si, 16, "uint") ; nPage
DllCall("SetScrollInfo", "ptr", WinExist(), "int", SB_HORZ, "ptr", &si, "int", 1)
; Update vertical scroll bar.
; NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4, "uint") ; fMask
NumPut(ScrollHeight, si, 12, "int") ; nMax
NumPut(GuiHeight, si, 16, "uint") ; nPage
DllCall("SetScrollInfo", "ptr", WinExist(), "int", SB_VERT, "ptr", &si, "int", 1)
if (Left < 0 && Right < GuiWidth)
x := Abs(Left) > GuiWidth-Right ? GuiWidth-Right : Abs(Left)
if (Top < 0 && Bottom < GuiHeight)
y := Abs(Top) > GuiHeight-Bottom ? GuiHeight-Bottom : Abs(Top)
if (x || y)
DllCall("ScrollWindow", "ptr", WinExist(), "int", x, "int", y, "ptr", 0, "ptr", 0)
}
I was reading the Microsoft docs about ScrollWindow:
https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-scrollwindow
Type: const RECT*
Pointer to the RECT structure specifying the portion of the client area to be scrolled. If this parameter is NULL, the entire client area is scrolled.
Then i tried to specify the rect starting from Y50:
Code: Select all
VarSetCapacity(RECT, 16, 0)
WinGetPos,,, W, H, Debug
NumPut(0, RECT, 0, "Float")
NumPut(50, RECT, 4, "Float")
NumPut(W, RECT, 8, "Float")
NumPut(H, RECT, 12, "Float")
; Scroll contents of window and invalidate uncovered area.
DllCall("ScrollWindow", "ptr", hwnd, "int", x, "int", y, "ptr", &Rect, "ptr", 0)
; Update scroll bar.
NumPut(new_pos, si, 20, "int") ; nPos
DllCall("SetScrollInfo", "ptr", hwnd, "int", bar, "ptr", &si, "int", 1)