Scroll feature

Ask for help, how to use AHK_H, etc.
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Scroll feature

02 Apr 2017, 08:43

I like a Scroll feature in Ahk_H. However, scroll bar partially covers the controls like in the case below. Is there a way to detect when scroll bar is visible to increase the window width in such cases?

Code: Select all

loop 50
	gui, add, edit, w200
gui, +vscroll
gui, show
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Scroll feature

02 Apr 2017, 13:55

You could increase Margin:

Code: Select all

SysGet,SM_CXVSCROLL,2
Gui,Margin,% SM_CXVSCROLL
Otherwise you can increase the size of Gui:

Code: Select all

loop 50
	gui, add, edit, w200
gui, +vscroll
gui, show, Hide
Gui,+LastFound
GetWindowRect(Winexist(),(rc:=Struct("l,t,r,b"))[])
Gui, Show,% "w" rc.r-rc.l+5
Return
GuiClose:
ExitApp
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Scroll feature

02 Apr 2017, 14:26

Thanks. Would it be possible to increase the margin only if scroll bar exists? Both examples increase a margin even if the loop is smaller, like Loop 10.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Scroll feature

02 Apr 2017, 15:44

?

Code: Select all

loop 10
	gui, add, edit, w200
gui, +vscroll
gui, show, Hide
Gui,+LastFound
; define structures for GetWindowRect and GetScrollBarInfo
RECT:="left,top,right,bottom",SCROLLBARINFO:="DWORD cbSize;RECT rcScrollBar;int dxyLineButton;int xyThumbTop;int xyThumbBottom;int reserved;DWORD rgstate[6]"

; Create a SCROLLBARINFO structure and set its size
si:=Struct(SCROLLBARINFO,{cbSize:sizeof(SCROLLBARINFO)})

; Get information about scrollbar to check if it exist
GetScrollBarInfo(WinExist(),-5, si[])

; Check if Scrollbar is visible (0x8000 = STATE_SYSTEM_INVISIBLE)
if (si.rgstate[1] & 0x8000)
	Gui, Show ; if not visible just show Gui
else { ; if Scrollbar is visible, get size of Gui and increase it by 5 pixels to fit in Scrollbar
	rc:=Struct(RECT)
	GetWindowRect(Winexist(),rc[])
	Gui, Show,% "w" rc.right-rc.left+5
}
Return
GuiClose:
ExitApp
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Scroll feature

03 Apr 2017, 12:25

Thanks although I don't understand the code :-)
Is there a simpler way? I tried to check the window height against ScreenHeight but it didn't work - Gui, Autosize cancels the Scroll.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: Scroll feature

03 Apr 2017, 16:51

I have added explanation above, you can make it a function so it is easier to use:

Code: Select all

loop 100
	gui, add, edit, w200
gui, +vscroll
ResizeFitVScroll()
Gui,Show
Return
GuiClose:
ExitApp



ResizeFitVScroll(Gui:=1){
	gui, %Gui%:show, Hide
	Gui,%Gui%:+LastFound
	; define structures for GetWindowRect and GetScrollBarInfo
	RECT:="left,top,right,bottom",SCROLLBARINFO:="DWORD cbSize;RECT rcScrollBar;int dxyLineButton;int xyThumbTop;int xyThumbBottom;int reserved;DWORD rgstate[6]"

	; Create a SCROLLBARINFO structure and set its size
	si:=Struct(SCROLLBARINFO,{cbSize:sizeof(SCROLLBARINFO)})

	; Get information about scrollbar to check if it exist
	GetScrollBarInfo(WinExist(),-5, si[])

	; Check if Scrollbar is visible (0x8000 = STATE_SYSTEM_INVISIBLE)
	if (si.rgstate[1] & 0x8000)
		Gui, Show ; if not visible just show Gui
	else { ; if Scrollbar is visible, get size of Gui and increase it by 5 pixels to fit in Scrollbar
		rc:=Struct(RECT)
		GetWindowRect(Winexist(),rc[])
		Gui, Show,% "w" rc.right-rc.left+5
	}
}
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Scroll feature

04 Apr 2017, 11:00

Thanks HotKeyit, very kind.
think
Posts: 136
Joined: 09 Feb 2014, 05:20

Re: Scroll feature

08 Apr 2017, 11:04

Alternative - what do you think, any disadvantage?

Code: Select all

loop 50
	gui, add, edit, w200
gui, show, Hide, MyWIndow
DetectHiddenWindows, On
WinGetPos,,,, H, MyWIndow
if (H>=A_ScreenHeight-40)
	Gui, +vScroll
Gui,Show
Return
GuiClose:
ExitApp

Return to “Ask for Help”

Who is online

Users browsing this forum: No registered users and 17 guests