ChildGui+HScroll Topic is solved

Stelle Fragen zur Programmierung mit Autohotkey

Moderator: jNizM

effel
Posts: 542
Joined: 16 Jan 2018, 13:34

ChildGui+HScroll

Post by effel » 03 Dec 2021, 18:09

Hallo,
ich möchte wie in Pic 1 dargestellt, noch weitere Edit Felder hinzufügen.

Irgendwann sind sie natürlich nach rechts verschwunden und für den Benutzer nicht mehr vorhanden.

Gibt es eine Möglichkeit (im folgenden Beispiel habe ich es mit einer ChildGui versucht) hier einen +HScroll zu etablieren, sodass ich alle Edit's erreichen kann?


#2ChildGui+HScroll.png
#2ChildGui+HScroll.png (118.9 KiB) Viewed 994 times
ChildGui+HScroll.png
ChildGui+HScroll.png (8.13 KiB) Viewed 994 times

Code: Select all

Gui, Main:New
Gui, Child: New, +ParentMain +hwndhChildGui -caption ; +HScroll 
gui, add, edit, xm w100 h200 -VScroll -HScroll
gui, add, edit, x+2 w100 h200 -VScroll +HScroll
gui, add, edit, x+2 w100 h200 -VScroll -HScroll
gui, add, edit, x+2 w100 h200 -VScroll +HScroll
gui, add, edit, x+2 w100 h200 +VScroll +HScroll
gui, add, edit, x+2 w100 h200 -VScroll +HScroll
Gui, Color, Red
Gui, Show, x0 y0 w1200 h200
Gui, Main:Show, w500 h210
Return

effel
Posts: 542
Joined: 16 Jan 2018, 13:34

Re: ChildGui+HScroll

Post by effel » 03 Dec 2021, 21:31

Danke fürs lesen, ich habe eine Lösung gefunden.

https://www.autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/

Code: Select all


Gui, 2:default
; --- Lexikos script for scrollbars in gui ---
; http://www.autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/
#NoEnv

OnMessage(0x115, "OnScroll") ; WM_VSCROLL
OnMessage(0x114, "OnScroll") ; WM_HSCROLL

Gui, 2: +Resize +0x300000 ; WS_VSCROLL | WS_HSCROLL

Gui, 2:Add, Edit, xm H800 W100, Edit %A_Index%

Loop 18
    Gui, 2:Add, Edit, x+2 H800 W100, Edit %A_Index%
Gui, 2:Add, Button,, Do absolutely nothing
Gui, 2:Show, W800 H800

Gui, 2:+LastFound
GroupAdd, MyGui, % "ahk_id " . WinExist()

return

2GuiSize:
GuiSize:
    UpdateScrollBars(A_Gui, A_GuiWidth, A_GuiHeight)
return

2GuiClose:
ExitApp

#IfWinActive ahk_group MyGui
WheelUp::
WheelDown::
+WheelUp::
+WheelDown::
    ; SB_LINEDOWN=1, SB_LINEUP=0, WM_HSCROLL=0x114, WM_VSCROLL=0x115
    OnScroll(InStr(A_ThisHotkey,"Down") ? 1 : 0, 0, GetKeyState("Shift") ? 0x114 : 0x115, WinExist())
return
#IfWinActive

UpdateScrollBars(GuiNum, GuiWidth, GuiHeight)
{
    static SIF_RANGE=0x1, SIF_PAGE=0x2, SIF_DISABLENOSCROLL=0x8, SB_HORZ=0, SB_VERT=1
    
;    msgBox, %GuiNum%
    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 -= 8
    Top -= 8
    Right += 8
    Bottom += 8
    ScrollWidth := Right-Left
    ScrollHeight := Bottom-Top
    
    ; Initialize SCROLLINFO.
    VarSetCapacity(si, 28, 0)
    NumPut(28, si) ; cbSize
    NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask
    
    ; Update horizontal scroll bar.
    NumPut(ScrollWidth, si, 12) ; nMax
    NumPut(GuiWidth, si, 16) ; nPage
    DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_HORZ, "uint", &si, "int", 1)
    
    ; Update vertical scroll bar.
;     NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask
    NumPut(ScrollHeight, si, 12) ; nMax
    NumPut(GuiHeight, si, 16) ; nPage
    DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_VERT, "uint", &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", "uint", WinExist(), "int", x, "int", y, "uint", 0, "uint", 0)
}

OnScroll(wParam, lParam, msg, hwnd)
{
    static SIF_ALL=0x17, SCROLL_STEP=10
    
    bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
    
    VarSetCapacity(si, 28, 0)
    NumPut(28, si) ; cbSize
    NumPut(SIF_ALL, si, 4) ; fMask
    if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si)
        return
    
    VarSetCapacity(rect, 16)
    DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
    
    new_pos := NumGet(si, 20) ; 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) ; 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", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
    
    ; Update scroll bar.
    NumPut(new_pos, si, 20, "int") ; nPos
    DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1)
}
ChildGuiHScroll.png
ChildGuiHScroll.png (38.38 KiB) Viewed 964 times

effel
Posts: 542
Joined: 16 Jan 2018, 13:34

Re: ChildGui+HScroll

Post by effel » 04 Dec 2021, 06:32

Ich bekomme ich es nicht hin, die ChildGui an den Tab csvEdit zu 'binden'. Sie ist auf allen Tabs präsent

Es fühlt sich 'nah dran' an ;)
v.lex.png
v.lex.png (74.94 KiB) Viewed 923 times

Code: Select all

;Scrollbare GUI  Proof of Concept  Skripte und Funktionen   und 2 weitere Seiten  Persönlich  Microsoft Edge
;https://www.autohotkey.com/board/topic/26033-scrollable-gui-proof-of-concept/
#SingleInstance force
#NoEnv
#Persistent
FileEncoding, UTF-8
SetBatchLines, -1
SetTitleMatchMode, 2
SetKeyDelay 20
SetWorkingDir, %A_ScriptDir%

Gui, main:new
;Gui, main:default
Gui, main:Add, Tab,% "W" (A_ScreenWidth-200) "H" (A_ScreenHeight-200) " Buttons +0x8 vResizeTab", Json2AhkObject|ObjectEdit|Json|csvListView|csvEdit|a_script|browser
Gui, main:Tab, csvEdit,, exact
Gui, child: new
Gui, Child: +ParentMain +hwndhChildGui -caption 
Gui, Child: +Resize +0x300000 ; WS_VSCROLL | WS_HSCROLL
OnMessage(0x115, "OnScroll") ; WM_VSCROLL
OnMessage(0x114, "OnScroll") ; WM_HSCROLL
    Gui, Child: Add, Edit, xm h800 W90 h800 vEdit1, 90`nEdit 1
Loop 20
{
random, rand, 60, 200
    Gui, Child: Add, Edit,% "x+10 h800 W" rand " h800 vEdit" (A_index + 1) " -VSCROLL",% rand "`nEdit" (A_Index+1)
}
Gui, child:Show,% "x0 y25 W" (A_ScreenWidth-200-40) "H" (A_ScreenHeight-200-60)
Gui, main:Show,% "W" (A_ScreenWidth-200) "H" (A_ScreenHeight-200)
Gui, Child: +LastFound
GroupAdd, MyGui, % "ahk_id " . WinExist()
return

GuiSize:
    UpdateScrollBars(A_Gui, A_GuiWidth, A_GuiHeight)
return

GuiClose:
ExitApp

#IfWinActive ahk_group MyGui
WheelUp::
WheelDown::
+WheelUp::
+WheelDown::
    ; SB_LINEDOWN=1, SB_LINEUP=0, WM_HSCROLL=0x114, WM_VSCROLL=0x115
    OnScroll(InStr(A_ThisHotkey,"Down") ? 1 : 0, 0, GetKeyState("Shift") ? 0x114 : 0x115, WinExist())
return
#IfWinActive

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 -= 8
    Top -= 8
    Right += 8
    Bottom += 8
    ScrollWidth := Right-Left
    ScrollHeight := Bottom-Top
    
    ; Initialize SCROLLINFO.
    VarSetCapacity(si, 28, 0)
    NumPut(28, si) ; cbSize
    NumPut(SIF_RANGE | SIF_PAGE, si, 4) ; fMask
    
    ; Update horizontal scroll bar.
    NumPut(ScrollWidth, si, 12) ; nMax
    NumPut(GuiWidth, si, 16) ; nPage
    DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_HORZ, "uint", &si, "int", 1)
    
    ; Update vertical scroll bar.
;     NumPut(SIF_RANGE | SIF_PAGE | SIF_DISABLENOSCROLL, si, 4) ; fMask
    NumPut(ScrollHeight, si, 12) ; nMax
    NumPut(GuiHeight, si, 16) ; nPage
    DllCall("SetScrollInfo", "uint", WinExist(), "uint", SB_VERT, "uint", &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", "uint", WinExist(), "int", x, "int", y, "uint", 0, "uint", 0)
}

OnScroll(wParam, lParam, msg, hwnd)
{
    static SIF_ALL=0x17, SCROLL_STEP=10
    
    bar := msg=0x115 ; SB_HORZ=0, SB_VERT=1
    
    VarSetCapacity(si, 28, 0)
    NumPut(28, si) ; cbSize
    NumPut(SIF_ALL, si, 4) ; fMask
    if !DllCall("GetScrollInfo", "uint", hwnd, "int", bar, "uint", &si)
        return
    
    VarSetCapacity(rect, 16)
    DllCall("GetClientRect", "uint", hwnd, "uint", &rect)
    
    new_pos := NumGet(si, 20) ; 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) ; 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", "uint", hwnd, "int", x, "int", y, "uint", 0, "uint", 0)
    
    ; Update scroll bar.
    NumPut(new_pos, si, 20, "int") ; nPos
    DllCall("SetScrollInfo", "uint", hwnd, "int", bar, "uint", &si, "int", 1)
}

just me
Posts: 9423
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: ChildGui+HScroll  Topic is solved

Post by just me » 05 Dec 2021, 07:31

Moin effel,

mit dem 'nah dran' bin ich nicht so sicher. Zuerst einmal läuft der Code von lexikos nur mit 32-bit AHK. Dazu kommt, dass Du zwar ein AHK-Fenster (Gui) zu einem Kindfenster eines anderen Fensters machen kannst, es wird damit aber nicht zu einem AHK-Control und damit auch keinem Tab zugeordnet. Es gibt m.E. nur zwei Optionen:

  1. Du erstellst ein AHK-Control (z.B. Text) und machst das zum Parent des Fensters. Das bringt aber zusätzliche Probleme bei der Zuordnung der Nachrichten.
  2. Du überwachst die Aktivierung der Tabs und blendest das Fenster entsprechend ein bzw. aus.
Die zweite Option sollte keine neuen Probleme mit sich bringen.

Ich habe übrigens selbst einmal ein ScrollGui-Skript geschrieben: viewtopic.php?f=6&t=6316. Das ist aber auch eher für eine direkte Zuordnung von Kind- zu Elternfenster gedacht.

effel
Posts: 542
Joined: 16 Jan 2018, 13:34

Re: ChildGui+HScroll

Post by effel » 08 Dec 2021, 13:23

just me wrote:
05 Dec 2021, 07:31
Ich habe übrigens selbst einmal... viewtopic.php?f=6&t=6316
Hallo Just Me, das ist genau das was ich brauche. Alle Macken von "Proof of Concept" sind wie weggezaubert

Ich habe die TabLeiste Gui, Add, Tab2, % "x0 y30 hide", 1|2|3|4 ausgeblendet und navigiere mit GuiControl , Choose , systabcontrol321 , 1 durch die Tabs

Vielen Dank fürs teilen

scrollGui1.png
scrollGui1.png (60.06 KiB) Viewed 793 times

Post Reply

Return to “Ich brauche Hilfe”