Jump to content

Scrollable GUI's


GaryFrost
 Share

Recommended Posts

Vertical and Horizontal scrolling

Haven't tried it with another control that has a scrollbar, but I believe if used with one then will have to use $hwndScrollBar to determine correct scrollbar

Thanks to Holger for pointing me in the right direction and the code to start from

Edit: Removed original script

Test script (include script attached)

Added: Enable/Disable Scrollbars

Added: Hide/Show Scrollbars

Added: Set Scroll Position

Added: Get/Set Scroll Range

Modified: GuiScrollbars.au3 put #include-once in and seperated out the structs

Added: Structs.au3 required for GuiScrollbars.au3

Edited by GaryFrost
Removed Download Link

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • Replies 65
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

  • Moderators

Holy Shiznit! That opens up worlds of opportunities.

Thanks Gary (and Holger) !

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

refined it a little bit, horizontal scroll is smooth now and tested with listview

Enjoy!!!

Edit: see 1st post in thread

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

This is a really good idea. Lets small gui's hold alot more controls

My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop.
Link to comment
Share on other sites

@gafrost, I am planning on using this functionality with MDI children, and was wondering if there is a way to create or adjust the scrollbars according to the dimensions of the content?

Here is a (rudimentary) example of what I am doing now:

#include <GUIConstants.au3>
;Opt("MustDeclareVars", 1)
Global Const $WM_CREATE = 0x1
Global Const $WM_HSCROLL = 0x0114
Global Const $WM_VSCROLL = 0x0115
Global $NUMLINES = 50
#cs
    #define SB_CTL              2
    #define SB_BOTH             3
    
    /*
    * Scroll Bar Commands
    */
    #define SB_LEFT             6
    #define SB_RIGHT            7
    #define SB_ENDSCROLL        8
#ce


Global $cyChar, $cxChar, $iMaxWidth, $iVertPos = 0, $iHorzPos = 0
Global $hGUI
Global $tagSCROLLINFO = DllStructCreate("uint;uint;int;int;uint;int;int")

_Main()

Func _Main()
    Local $nFileMenu, $nExititem, $GUIMsg
    Local $listview, $button
    DllStructSetData($tagSCROLLINFO, 1, DllStructGetSize($tagSCROLLINFO))
    
    GUIRegisterMsg($WM_CREATE, "MY_WM_CREATE")
    GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

    $hGUI = GUICreate("Test", 800, 600, -1, -1, BitOr($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_CLIPCHILDREN, $WS_VSCROLL, $WS_HSCROLL))
    
    $nFileMenu = GUICtrlCreateMenu("File")
    $nExititem = GUICtrlCreateMenuitem("Exit", $nFileMenu)

    GUIRegisterMsg($WM_VSCROLL, "MY_WM_VSCROLL")
    GUIRegisterMsg($WM_HSCROLL, "MY_WM_HSCROLL")

    GUISetState()
    
    $PID    = Run(@WindowsDir & "\regedit.exe", "", @SW_HIDE)
    $hWnd    = 0
    $stPID    = DllStructCreate("int")

    Do
        $WinList = WinList()
        For $i = 1 To $WinList[0][0]
            If $WinList[$i][0] <> "" Then
                DllCall("user32.dll", "int", "GetWindowThreadProcessId", "hwnd", $WinList[$i][1], "ptr", DllStructGetPtr($stPID))
                If DllStructGetData($stPID, 1) = $PID Then
                    $hWnd = $WinList[$i][1]
                    ExitLoop
                EndIf
            EndIf
        Next
        Sleep(100)
    Until $hWnd <> 0

    $stPID = 0

    If $hWnd <> 0 Then
        $nExStyle = DllCall("user32.dll", "int", "GetWindowLong", "hwnd", $hWnd, "int", -20)
        $nExStyle = $nExStyle[0]
        DllCall("user32.dll", "int", "SetWindowLong", "hwnd", $hWnd, "int", -20, "int", BitOr($nExStyle, $WS_EX_MDICHILD))
        DllCall("user32.dll", "int", "SetParent", "hwnd", $hWnd, "hwnd", $hGUI)    
        WinSetState($hWnd, "", @SW_SHOW)
        WinMove($hWnd, "", 0, 0, 600, 400)
    EndIf

    While 1
        $GUIMsg = GUIGetMsg()
        Switch $GUIMsg
            Case $GUI_EVENT_CLOSE, $nExititem
                ExitLoop
        EndSwitch
    WEnd

    Exit
EndFunc   ;==>_Main

Func MY_WM_CREATE($hWnd, $Msg, $wParam, $lParam)
    Local $hdc = DllCall("user32.dll", "int", "GetDC", "hwnd", $hGUI)
    $hdc = $hdc[0]
    Local $TEXTMETRIC = DllStructCreate("int;int;int;int;int;int;int;int;int;int;int;char;char;char;char;byte;byte;byte;byte;byte")
    DllCall("gdi32.dll", "int", "GetTextMetrics", "int", $hdc, "ptr", DllStructGetPtr($TEXTMETRIC))
    $cxChar = DllStructGetData($TEXTMETRIC, 6)
    Local $cxCaps = DllStructGetData($TEXTMETRIC, 19) * $cxChar / 2
    $cyChar = DllStructGetData($TEXTMETRIC, 1) + DllStructGetData($TEXTMETRIC, 5)
    DllCall("user32.dll", "int", "ReleaseDC", "hwnd", $hGUI, "int", $hdc)
    $iMaxWidth = 40 * $cxChar + 22 * $cxCaps
;~  GUIRegisterMsg($WM_CREATE,"")
    Return 0
EndFunc   ;==>MY_WM_CREATE

Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    Local Const $SIF_PAGE = 0x2
    Local Const $SIF_RANGE = 0x1
    Local Const $SB_HORZ = 0
    Local Const $SB_VERT = 1
    Local $cxClient = BitAND($lParam, 0x0000FFFF)
    Local $cyClient = BitShift($lParam, 16)
    DllStructSetData($tagSCROLLINFO, 2, BitOR($SIF_RANGE, $SIF_PAGE))
    DllStructSetData($tagSCROLLINFO, 3, 0)
    DllStructSetData($tagSCROLLINFO, 4, $NUMLINES - 1)
    DllStructSetData($tagSCROLLINFO, 5, $cyClient / $cyChar)
    DllCall("user32.dll", "int", "SetScrollInfo", "hwnd", $hGUI, "int", $SB_VERT, "ptr", DllStructGetPtr($tagSCROLLINFO), "int", True)
    DllStructSetData($tagSCROLLINFO, 4, 2 + $iMaxWidth / $cxChar)
    DllStructSetData($tagSCROLLINFO, 5, $cxClient / $cxChar)
    DllCall("user32.dll", "int", "SetScrollInfo", "hwnd", $hGUI, "int", $SB_HORZ, "ptr", DllStructGetPtr($tagSCROLLINFO), "int", True)
    Return 0
EndFunc   ;==>MY_WM_SIZE

Func MY_WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    Local Const $SB_VERT = 1
    Local Const $SIF_POS = 0x4
    Local Const $SIF_PAGE = 0x2
    Local Const $SIF_RANGE = 0x1
    Local Const $SIF_TRACKPOS = 0x10
    Local Const $SIF_ALL = BitOR($SIF_RANGE, $SIF_PAGE, $SIF_POS, $SIF_TRACKPOS)
    Local Const $SB_LINEUP = 0
    Local Const $SB_LINEDOWN = 1
    Local Const $SB_PAGEUP = 2
    Local Const $SB_PAGEDOWN = 3
    Local Const $SB_THUMBTRACK = 5
    Local Const $SB_TOP = 6
    Local Const $SB_BOTTOM = 7
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $hwndScrollBar = $lParam

    DllStructSetData($tagSCROLLINFO, 2, $SIF_ALL)
    DllCall("user32.dll", "int", "GetScrollInfo", "hwnd", $hGUI, "int", $SB_VERT, "ptr", DllStructGetPtr($tagSCROLLINFO))
    Local $nMin = DllStructGetData($tagSCROLLINFO, 3)
    Local $nMax = DllStructGetData($tagSCROLLINFO, 4)
    Local $nPage = DllStructGetData($tagSCROLLINFO, 5)
    Local $nPos = DllStructGetData($tagSCROLLINFO, 6)
    Local $nTrackPos = DllStructGetData($tagSCROLLINFO, 7)

    Switch $nScrollCode
        Case $SB_TOP
            DllStructSetData($tagSCROLLINFO, 6, $nMin)

        Case $SB_BOTTOM
            DllStructSetData($tagSCROLLINFO, 6, $nMax)

        Case $SB_LINEUP
            DllStructSetData($tagSCROLLINFO, 6, $nPos - 1)

        Case $SB_LINEDOWN
            DllStructSetData($tagSCROLLINFO, 6, $nPos + 1)

        Case $SB_PAGEUP
            DllStructSetData($tagSCROLLINFO, 6, $nPos - $nPage)

        Case $SB_PAGEDOWN
            DllStructSetData($tagSCROLLINFO, 6, $nPos + $nPage)

        Case $SB_THUMBTRACK
            DllStructSetData($tagSCROLLINFO, 6, $nTrackPos)
    EndSwitch
;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

    DllStructSetData($tagSCROLLINFO, 2, $SIF_POS)
    DllCall("user32.dll", "int", "SetScrollInfo", "hwnd", $hGUI, "int", $SB_VERT, "ptr", DllStructGetPtr($tagSCROLLINFO), "int", True)
    DllCall("user32.dll", "int", "GetScrollInfo", "hwnd", $hGUI, "int", $SB_VERT, "ptr", DllStructGetPtr($tagSCROLLINFO))
    ;// If the position has changed, scroll the window and update it
    $nPos = DllStructGetData($tagSCROLLINFO, 6)

    If ($nPos <> $iVertPos) Then
        DllCall("user32.dll", "int", "ScrollWindow", "hwnd", $hGUI, "int", 0, "int", $cyChar * ($iVertPos - $nPos), "ptr", 0, "ptr", 0)
;~         DllCall("user32.dll", "int", "UpdateWindow", "hwnd", $hGUI)
        $iVertPos = $nPos
    EndIf

    Return 0

EndFunc   ;==>MY_WM_VSCROLL

Func MY_WM_HSCROLL($hWnd, $Msg, $wParam, $lParam)
    Local Const $SB_HORZ = 0
    Local Const $SIF_POS = 0x4
    Local Const $SIF_PAGE = 0x2
    Local Const $SIF_RANGE = 0x1
    Local Const $SIF_TRACKPOS = 0x10
    Local Const $SIF_ALL = BitOR($SIF_RANGE, $SIF_PAGE, $SIF_POS, $SIF_TRACKPOS)
    Local Const $SB_LINELEFT = 0
    Local Const $SB_LINERIGHT = 1
    Local Const $SB_PAGELEFT = 2
    Local Const $SB_PAGERIGHT = 3
;~     Local Const $SB_THUMBPOSITION = 4
    Local Const $SB_THUMBTRACK = 5
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $hwndScrollBar = $lParam

    DllStructSetData($tagSCROLLINFO, 2, $SIF_ALL)
    DllCall("user32.dll", "int", "GetScrollInfo", "hwnd", $hGUI, "int", $SB_HORZ, "ptr", DllStructGetPtr($tagSCROLLINFO))
    Local $nMin = DllStructGetData($tagSCROLLINFO, 3)
    Local $nMax = DllStructGetData($tagSCROLLINFO, 4)
    Local $nPage = DllStructGetData($tagSCROLLINFO, 5)
    Local $nPos = DllStructGetData($tagSCROLLINFO, 6)
    Local $nTrackPos = DllStructGetData($tagSCROLLINFO, 7)

    Switch $nScrollCode

        Case $SB_LINELEFT
            DllStructSetData($tagSCROLLINFO, 6, $nPos - 1)

        Case $SB_LINERIGHT
            DllStructSetData($tagSCROLLINFO, 6, $nPos + 1)

        Case $SB_PAGELEFT
            DllStructSetData($tagSCROLLINFO, 6, $nPos - $nPage)

        Case $SB_PAGERIGHT
            DllStructSetData($tagSCROLLINFO, 6, $nPos + $nPage)

;~         Case $SB_THUMBPOSITION
;~             DllStructSetData($tagSCROLLINFO, 6, $nTrackPos)
        Case $SB_THUMBTRACK
            DllStructSetData($tagSCROLLINFO, 6, $nTrackPos)
    EndSwitch

;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.

    DllStructSetData($tagSCROLLINFO, 2, $SIF_POS)
    DllCall("user32.dll", "int", "SetScrollInfo", "hwnd", $hGUI, "int", $SB_HORZ, "ptr", DllStructGetPtr($tagSCROLLINFO), "int", True)
    DllCall("user32.dll", "int", "GetScrollInfo", "hwnd", $hGUI, "int", $SB_HORZ, "ptr", DllStructGetPtr($tagSCROLLINFO))
    ;// If the position has changed, scroll the window and update it
    $nPos = DllStructGetData($tagSCROLLINFO, 6)
    If ($nPos <> $iHorzPos) Then
        DllCall("user32.dll", "int", "ScrollWindow", "hwnd", $hGUI, "int", $cxChar * ($iHorzPos - $nPos), "int", 0, "ptr", 0, "ptr", 0)
;~   DllCall("user32.dll", "int", "UpdateWindow", "hwnd", $hGUI)
        $iHorzPos = $nPos
    EndIf
    Return 0
EndFunc   ;==>MY_WM_HSCROLL

My problem is when a part of regedit is moved outside the boundries of the inner portion of the window. I would like to have a gui that creates scrollbars as needed when the internal window boundries exceed the internal dimensions of the gui window.

EDIT: even this example is unfinished, but it gives you an idea of what I am trying to achieve.

Edited by this-is-me
Who else would I be?
Link to comment
Share on other sites

Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    Local Const $SIF_PAGE = 0x2
    Local Const $SIF_RANGE = 0x1
    Local Const $SB_HORZ = 0
    Local Const $SB_VERT = 1
    Local $cxClient = BitAND($lParam, 0x0000FFFF)
    Local $cyClient = BitShift($lParam, 16)
    DllStructSetData($tagSCROLLINFO, 2, BitOR($SIF_RANGE, $SIF_PAGE))
    DllStructSetData($tagSCROLLINFO, 3, 0)

;*************************************************************
; sets vertical scrollbar, change $NUMLINES
;*************************************************************
    DllStructSetData($tagSCROLLINFO, 4, $NUMLINES - 1)
;*************************************************************

    DllStructSetData($tagSCROLLINFO, 5, $cyClient / $cyChar)
    DllCall("user32.dll", "int", "SetScrollInfo", "hwnd", $hGUI, "int", $SB_VERT, "ptr", DllStructGetPtr($tagSCROLLINFO), "int", True)

;*************************************************************
; sets horizontal scrollbar, you'll have to figure out what you want here
;*************************************************************
    DllStructSetData($tagSCROLLINFO, 4, 2 + $iMaxWidth / $cxChar)
;*************************************************************

    DllStructSetData($tagSCROLLINFO, 5, $cxClient / $cxChar)
    DllCall("user32.dll", "int", "SetScrollInfo", "hwnd", $hGUI, "int", $SB_HORZ, "ptr", DllStructGetPtr($tagSCROLLINFO), "int", True)
    Return 0
EndFunc   ;==>MY_WM_SIZE

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thanx Gary. This gives me enough to go on. I can test from this point.

yw, would of been nice to know how to do this when I was creating some other scripts

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Thanx Gary. This gives me enough to go on. I can test from this point.

there's probably a good way to calculate the number of lines and columns I just haven't researched it yet

but here's something you could look at

Edit: remove the long drawn out code, see 1st post

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Cleaned up the thread and put a test script and an attachement in 1st post:

Anyone can make improvements glad to have the help

Enjoy!!!!

Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Added: Get/Set Scroll Range

If anyone can come up with a better way of calculating the size of the scrollbars needed would be greatly appreciated.

See 1st post for example and attachment

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Modified: GuiScrollbars.au3 put #include-once in and seperated out the structs

Added: Structs.au3 required for GuiScrollbars.au3

see 1st post for attachements and example

comments/suggestions/bugs Feed back appreciated

Enjoy!!!!

Gary

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

  • 3 weeks later...
  • Moderators

Surprised there doesn't seem to be much interest in this one.

Still if anyone can help make it better I'll gladly accept the help.

After I'm done with my work project Gary, I'll upload the RSS Feed reader I did with it... came in handy since we can't currently use Hyperlinks in the Edit controls themselves.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

I'm very interested alright, although I don't feel like posting just to say so ;)

When I saw that you posted this I was thinking of adding it to my current project,

but with the speed I'm currently at it won't be finished before close to Christmas.

I think the basic reason for that is upgraded internet, sickness and pure laziness.

I'll probably post it here some day...if it's ever gets finished that is :whistle:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...