AHKv2: Ventana con barras de desplazamiento [29/10/2016]

Esta sección es para compartir scripts, librerías y herramientas.
User avatar
Flipeador
Posts: 1019
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

AHKv2: Ventana con barras de desplazamiento [29/10/2016]

29 Oct 2016, 10:14

descargar AutoHotKey v2 y Archivos .bin (usar el compilador de la v1)
versión original por lexikos en el antiguo foro (versión reescrita para trabajar con AutoHotKey 2)
Nota: probado solo en WIN_10 x32

Añadir barras de desplazamiento horizontal y vertical a una ventana - útil para ventanas con muchos controles en pantallas pequeñas
Link: https://github.com/flipeador/AutoHotKey ... ollBar.ahk

Code: Select all

UpdateScrollBars(hWnd) {
	VarSetCapacity(RECT, 16, 0), DllCall("User32.dll\GetClientRect", "Ptr", hWnd, "Ptr", &RECT)
	, Width := NumGet(RECT, 8, "Int") - NumGet(RECT, 0, "Int"), Height := NumGet(RECT, 12, "Int") - NumGet(RECT, 4, "Int")

    , Left := Top := 9999, Right := Bottom := 0
	for Index, ControlId in WinGetControlsHwnd("ahk_id " hWnd)
		ControlGetPos(cx, cy, cw, ch,, "ahk_id " ControlId)
        , (cx < Left) ? Left := cx : ""
        , (cy < Top) ? Top := cy : ""
		, (cx + cw > Right) ? Right := cx + cw : ""
        , (cy + ch > Bottom) ? Bottom := cy + ch : ""
    Left -= SysGet(2) // 2, Top -= SysGet(2) // 2, Right += SysGet(2) // 2, Bottom += SysGet(2) // 2
    , ScrollWidth := Right-Left, ScrollHeight := Bottom-Top

	, NumPut(VarSetCapacity(SCROLLINFO, 7 * 4, 0), SCROLLINFO, 0, "UInt"), NumPut(1 | 2, SCROLLINFO, 4, "UInt")
	, NumPut(ScrollWidth, SCROLLINFO, 12, "Int"), NumPut(Width, SCROLLINFO, 16, "Int")
	, DllCall("User32.dll\SetScrollInfo", "Ptr", hWnd, "Int", 0, "Ptr", &SCROLLINFO, "Int", true)
	, NumPut(ScrollHeight, SCROLLINFO, 12, "Int"), NumPut(Height, SCROLLINFO, 16, "Int")
	, DllCall("User32.dll\SetScrollInfo", "Ptr", hWnd, "Int", 1, "Ptr", &SCROLLINFO, "Int", true)
	
    , (Left < 0 && Right < Width) ? (x := Abs(Left) > Width-Right ? Width-Right : Abs(Left)) : ""
    , (Top < 0 && Bottom < Height) ? (y := Abs(Top) > Height-Bottom ? Height-Bottom : Abs(Top)) : ""
    , (x || y) ? DllCall("User32.dll\ScrollWindowEx", "Ptr", hWnd, "Int", x, "Int", y, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "UInt", 1 | 2 | 4) : ""
}

OnScroll(wParam, lParam, Message, hWnd) {
	ScrollBars := {0x114: "WM_HSCROLL", 0x115: "WM_VSCROLL"}
	, ScrollBarTypes := {0: "SB_HORZ", 1: "SB_VERT"				,				WM_HSCROLL: 0, WM_VSCROLL: 1}
	
	, Action := wParam & 0xFFFF
	, ScrollBar := ScrollBars[Message]					;WM_HSCROLL	= barra horizontal								|						WM_VSCROLL	= barra vertical
	, ScrollBarType := ScrollBarTypes[ScrollBar]	;0							= barra horizontal								|						1							= barra vertical

    , NumPut(VarSetCapacity(SCROLLINFO, 7 * 4, 0), SCROLLINFO, 0, "UInt"), NumPut(1 | 2 | 4, SCROLLINFO, 4, "UInt")
	, DllCall("User32.dll\GetScrollInfo", "Ptr", hWnd, "Int", ScrollBarType, "Ptr", &SCROLLINFO)
	
    , VarSetCapacity(RECT, 16, 0)
	, DllCall("User32.dll\GetClientRect", "Ptr", hWnd, "Ptr", &RECT)

    , (Action = 0) ? Pos := NumGet(SCROLLINFO, 20, "Int") - 10 : Pos := NumGet(SCROLLINFO, 20, "Int")
    , (Action = 1) ? Pos += 10 : ""
    , (Action = 2) ? Pos -= NumGet(rect, 12, "Int") - 10 : ""
    , (Action = 3) ? Pos += NumGet(rect, 12, "Int") - 10 : ""
    , (Action = 5 || action = 4) ? Pos := wParam >> 16 : ""
    , (Action = 6) ? Pos := NumGet(SCROLLINFO, 8, "Int") : ""
    , (Action = 7) ? Pos := NumGet(SCROLLINFO, 12, "Int") : ""
	if (!(Action >= 0) && !(Action < 8)) || (Action = 4)
		return
	(Pos > NumGet(SCROLLINFO, 12, "Int") - NumGet(SCROLLINFO, 16, "UInt")) ? Pos := NumGet(SCROLLINFO, 12, "Int") - NumGet(SCROLLINFO, 16, "UInt") : ""
	, (Pos < NumGet(SCROLLINFO, 8, "Int")) ? Pos := NumGet(SCROLLINFO, 8, "Int") : ""
    , (ScrollBarType = 0) ? (y := 0) . (x := NumGet(SCROLLINFO, 20, "Int") - Pos) : (x := 0) . (y := NumGet(SCROLLINFO, 20, "Int") - Pos)

	, DllCall("User32.dll\ScrollWindowEx", "Ptr", hWnd, "Int", x, "Int", y, "Ptr", 0, "Ptr", 0, "Ptr", 0, "Ptr", 0, "UInt", 1 | 2 | 4)
    
	, NumPut(Pos, SCROLLINFO, 20, "Int")
	, DllCall("User32.dll\SetScrollInfo", "Ptr", hWnd, "Int", ScrollBarType, "Ptr", &SCROLLINFO, "Int", true)
}

Ejemplo (revisión 22/04/2018):

Code: Select all

; registrar los mensajes enviados cuando el usuario interactua con la barra de desplazamiento de la ventana
OnMessage(0x115, "OnScroll") ;WM_VSCROLL
OnMessage(0x114, "OnScroll") ;WM_HSCROLL

; creamos gui 1
Gui := GuiCreate("+Resize +0x300000")
Loop 8
    Gui.AddEdit("R5 W400", "Edit #" . A_Index)
Gui.AddButton(, "Hola soy un botón")

; creamos gui 2
Gui2 := GuiCreate("+Resize +0x300000")
Tab := Gui2.AddTab3("w999 h999 -Wrap", "a|e|i|u|o")
Loop 20
{
    Tab.UseTab(A_Index = 6 ? "" : A_Index)
    Gui2.AddListView("w999 h999", "a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z|1|2|3|4|5|6|7|8|9|0")
}
Gui2.Show("y200 h150 w200")
Gui.Show("y0 h150 w200")

Gui.OnEvent("Size", (g) => UpdateScrollBars(g.hwnd))
Gui2.OnEvent("Size", (g) => UpdateScrollBars(g.hwnd))
Gui.OnEvent("Close", "ExitApp")
Gui2.OnEvent("Close", "ExitApp")

; Habilitar la rueda del mouse para desplazar la barra
#If ( WinActive("ahk_id" . Gui.Hwnd) )
WheelUp::
WheelDown::
+WheelUp:: ;mantener SHIFT precionado para mover la barra horizontal
+WheelDown::
OnScroll(!!InStr(A_ThisHotkey,"Down"), 0, GetKeyState("Shift") ? 0x114 : 0x115, gui.hWnd)
OnScroll(!!InStr(A_ThisHotkey,"Down"), 0, GetKeyState("Shift") ? 0x114 : 0x115, gui2.hWnd)
return
#If

Return to “Scripts y Funciones”

Who is online

Users browsing this forum: No registered users and 3 guests