Jump to content

I need a scrollbar within a TabItem


Asder
 Share

Recommended Posts

Hello,

I need a vertical scrollbar within a tab item. I googled and there has to be a way with a dummy item, but somehow it creates a crash on my computer so i think i was doing it wrong. It would be kind if someone could help me here

My GUI code looks like this: (I marked the Tab that needs a scrollbar)

Global $gui_main

$gui_main = GUICreate("Mainwindoe",$screen_width,$screen_height-$screen_height_subtraction,10,10)

Global $gui_child_mieter_alphabet_tab

$gui_child_mieter_alphabet_tab = GUICreate("",$screen_width,$screen_height-$screen_height_subtraction,0,20,$WS_CHILD,-1,$gui_main);Child GUI mit Tabs

GUICtrlCreateTab(0,0,$screen_width,$screen_height-$screen_height_subtraction)

GUICtrlCreateTabItem("A-M")

GUICtrlCreateTabItem("N-Z")

GUISetState(@SW_HIDE)

Global $gui_child_haeuser_tab

$gui_child_haeuser_tab = GUICreate("",$screen_width,$screen_height-$screen_height_subtraction,0,20,$WS_CHILD,-1,$gui_main);Child GUI mit Tabs

GUICtrlCreateTab(0,0,$screen_width,$screen_height-$screen_height_subtraction)

GUICtrlCreateTabItem("1")

GUICtrlCreateTabItem("2")

GUICtrlCreateTabItem("3")

GUICtrlCreateTabItem("4")

GUICtrlCreateTabItem("5")

GUISetState(@SW_HIDE)

Global $gui_child_single_tab

$gui_child_single_tab = GUICreate("",$screen_width-$screen_width_subtraction,$screen_height-$screen_height-$screen_height_subtraction,0,20,$WS_CHILD,-1,$gui_main);Child GUI mit Tabs

Global $gui_MainTab

GUISwitch($gui_main)

$gui_MainTab = GUICtrlCreateTab(0,0,$screen_width,$screen_height-$screen_height_subtraction)

;######################################################

;######################################################

GUICtrlCreateTabItem("THIS ONE NEEDS A VERTICAL SCROLLBAR")

;######################################################

;######################################################

GUICtrlCreateTabItem("Tab2")

GUICtrlCreateTabItem("Tab3")

;GUICtrlCreateTabItem("")

GUISetState(@SW_SHOW)

Thank you very much in advance

Link to comment
Share on other sites

Here is the basic idea. You will have to implement the scrollbar functionality though as I've left that part out.

#include <WindowsConstants.au3>






$gp = GUICreate("parent")
$gc = GUICreate("child",293,175,13,32,BitOr($WS_CHILD, $WS_VSCROLL),-1,$gp)
$b1 = GUICtrlCreateButton("top",30,30)
$b2 = GUICtrlCreateButton("bottom",50,230)
GUISetBkColor(0xffff77,$gc)
GUISwitch($gp)
$tab1 = GUICtrlCreateTab(10,10,300,200)
$tabIt1 = GUICtrlCreateTabItem("one")
$tabIt2 = GUICtrlCreateTabItem("two")
GUICtrlCreateTabItem("")
GUISetState()

while 1
 $gm =    GUIGetMsg()
switch $gm
    case -3
        Exit
    case $tab1
        $tabNo = GUICtrlRead($tab1)
        switch $tabNo
            case 1
                GUISetState(@SW_SHOW,$gc)
            case 0
                GUISetState(@SW_HIDE,$gc)
        EndSwitch

EndSwitch

    sleep(30)
WEnd

It's better, at least for me, if you use autoit code tages, and post code which we can run. I prefer to modify someone's code than having to start from scratch. But I know you're new so welcome to the AutoIt forums Asder :D

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Hello Asder,

here a little Demoscript with a scrollable TabItem:

#include <GUIConstantsEx.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>
#include <WindowsConstants.au3>
$hGui = GUICreate("Gui with scrollable TabItem ", 633, 350, 190, 220)
GUISetBkColor(0xFFFFFF)
$idTab = GUICtrlCreateTab(10, 10, 613, 300)
$idTab0 = GUICtrlCreateTabItem("tab0")
$hChild = GUICreate("Scrollbereich", 588, 255, 26, 45, $WS_POPUP, $WS_EX_MDICHILD, $hGui)
$x = 6 ; +22
$y = 8
Local $aInputs[15]
For $i = 0 To 14
$aInputs[$i]=GUICtrlCreateInput('', $x, $y, 21, 20)
$x += 22
$y += 21
Next
_GUIScrollBars_Init($hChild,-1)
_GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) ; horizontale Scrollbar verstecken
_GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 3, 30)
GUISetState(@SW_HIDE,$hChild)
GUISwitch($hGui)
$idTab1 = GUICtrlCreateTabItem("tab----1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
$idTab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon"); default Jon
$idTab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)
$idTab2 = GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $Gui_SHOW); will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
$idTab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)
GUICtrlCreateTabItem(""); end tabitem definition
$idBtnContinue = GUICtrlCreateButton("&Weiter", 448, 320, 100, 25)
$idBtnCancel = GUICtrlCreateButton("&Beenden", 264, 320, 100, 25)
$idBtnBack = GUICtrlCreateButton("&Zurück", 72, 320, 100, 25)
GUISetState(@SW_SHOW, $hGui)

GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $Gui_EVENT_CLOSE
   Exit
  Case $idTab
   $iActualTab = GUICtrlRead($idTab,1)
   if $iActualTab = $idTab0 Then
    GUISetState(@SW_SHOW,$hChild)
    ;GUISetState(@SW_SHOW,$hGui)
   Else
    GUISetState(@SW_HIDE,$hChild)
   endif
EndSwitch
WEnd
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $index = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos
    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $yChar = $aSB_WindowInfo[$index][2]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0
    ; Ermittelt alle Informationen der vertikalen Scrollbar
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    ; Speichert die y-Position für einen späteren Vergleich
    $Pos = $yPos
    ; Auswertung der vom System gemeldeten Scroll-Nachricht
    Switch $nScrollCode
        Case $SB_TOP ; Der Anwender klickte auf die "Pos1"-Taste
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM ; Der Anwender klickte auf die "Ende"-Taste
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP ; Der Anwender klickte auf den oberen Pfeil
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINEDOWN ; Der Anwender klickte auf den unteren Pfeil
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGEUP ; Der Anwender klickte oberhalb des Scrollbalkens
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN ; Der Anwender klickte unterhalb des Scrollbalkens
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK ; Der Anwender zog den Scrollbalken
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch
;~    // Setzt die neue Position und ermittelt sie danach erneut.
;~    // Abhängig von den Windows-Einstellungen kann es sein, dass die gelesenen Werte nicht die gleichen sind, wie die vorher gesetzten.
    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ; // Falls sich die y-Position der Scrollbar geändert hat, den Fensterbereich verschieben und aktualisieren
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_VSCROLL
Link to comment
Share on other sites

Hello, Thank you for the warm welcome, i tried to include your code but it is not working, now my complete window is invisble when i start the script. For better understanding i included a working script snippet

Where is my mistake?

#include <WindowsConstants.au3>
Opt('MustDeclareVars', 1)
Global $screen_width = 1280-20
Global $screen_height = 1024
Global $screen_width_subtraction = 40
Global $screen_height_subtraction = 40
Global $gp
$gp=GUICreate("parent")
Global $gui_main
$gui_main = GUICreate("Mainwindow",$screen_width,$screen_height-$screen_height_subtraction,BitOr($WS_CHILD, $WS_VSCROLL),-1,$gp)
GUISwitch($gp)
Global $gui_child_mieter_alphabet_tab
$gui_child_mieter_alphabet_tab = GUICreate("",$screen_width,$screen_height-$screen_height_subtraction,0,20,$WS_CHILD,-1,$gui_main);Child GUI mit Tabs
GUICtrlCreateTab(0,0,$screen_width,$screen_height-$screen_height_subtraction)
GUICtrlCreateTabItem("A-M")
GUICtrlCreateTabItem("N-Z")
GUISetState(@SW_HIDE)
Global $gui_child_haeuser_tab
$gui_child_haeuser_tab = GUICreate("",$screen_width,$screen_height-$screen_height_subtraction,0,20,$WS_CHILD,-1,$gui_main);Child GUI mit Tabs
GUICtrlCreateTab(0,0,$screen_width,$screen_height-$screen_height_subtraction)
GUICtrlCreateTabItem("1")
GUICtrlCreateTabItem("2")
GUICtrlCreateTabItem("3")
GUICtrlCreateTabItem("4")
GUICtrlCreateTabItem("5")
GUISetState(@SW_HIDE)
Global $gui_child_single_tab
$gui_child_single_tab = GUICreate("",$screen_width-$screen_width_subtraction,$screen_height-$screen_height-$screen_height_subtraction,0,20,$WS_CHILD,-1,$gui_main);Child GUI mit Tabs
Global $gui_MainTab
GUISwitch($gui_main)
$gui_MainTab = GUICtrlCreateTab(0,0,$screen_width,$screen_height-$screen_height_subtraction)
;######################################################
;######################################################
GUICtrlCreateTabItem("THIS ONE NEEDS A VERTICAL SCROLLBAR")
;######################################################
;######################################################

GUICtrlCreateTabItem("Tab2")
GUICtrlCreateTabItem("Tab3")
;GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)
Local $msg
While 1 * Sleep(20)
    $msg = GUIGetMsg()
        Switch $msg
            Case $gui_MainTab
                Switch GUICtrlRead($gui_MainTab)
     Case 0 ;Mieteinnahmen
      GUISetState(@SW_HIDE, $gui_child_haeuser_tab)
                        GUISetState(@SW_HIDE, $gui_child_mieter_alphabet_tab)
      GUISetState(@SW_SHOW, $gui_child_single_tab)
      GUISetState(@SW_HIDE, $gui_MainTab)
                    Case 1 ;Häuser
                        GUISetState(@SW_HIDE, $gui_child_single_tab)
                        GUISetState(@SW_HIDE, $gui_child_mieter_alphabet_tab)
      GUISetState(@SW_SHOW, $gui_child_haeuser_tab)
      GUISetState(@SW_SHOW, $gui_MainTab)
                    Case 2 ;Mieter
                        GUISetState(@SW_HIDE, $gui_child_single_tab)
      GUISetState(@SW_HIDE, $gui_child_haeuser_tab)
                        GUISetState(@SW_SHOW, $gui_child_mieter_alphabet_tab)
      GUISetState(@SW_SHOW, $gui_MainTab)

                EndSwitch
            ;Case $GUI_EVENT_CLOSE
            ;    Exit
  EndSwitch
;Next
WEnd
Link to comment
Share on other sites

Here is the basic idea. You will have to implement the scrollbar functionality though as I've left that part out.

[...code...]

It's better, at least for me, if you use autoit code tages, and post code which we can run. I prefer to modify someone's code than having to start from scratch. But I know you're new so welcome to the AutoIt forums Asder :D

Btw i just realised your code isnt working in your example, its impossible to scroll down to the bottom button
Link to comment
Share on other sites

Btw i just realised your code isnt working in your example, its impossible to scroll down to the bottom button

I know, I said

Here is the basic idea. You will have to implement the scrollbar functionality though as I've left that part out.

But AutoBerty was more helpful and gave you a complete example.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

  • 2 months later...

:) He forgot to close his autoit tag didn't he. But that doesn't explain why the code cuts half way through, surely.

He didn't forget to close it, it's there. The post cuts because of non-english (unicode?) character in the AutoIt tags. Quote him and all is there.
Link to comment
Share on other sites

I hope this time it's complete:

#include <GUIConstantsEx.au3>
#include <ScrollBarConstants.au3>
#include <GuiScrollBars.au3>
#include <WindowsConstants.au3>
#Include <GuiTab.au3>
$hGui = GUICreate("Gui with scrollable TabItem ", 633, 350, 190, 220)
GUISetBkColor(0xFFFFFF)
$idTab = GUICtrlCreateTab(10, 10, 613, 300)
$idTab0 = GUICtrlCreateTabItem("tab0")
$hChild = GUICreate("Scrollbereich", 588, 255, 26, 45, $WS_POPUP, $WS_EX_MDICHILD, $hGui)
$x = 6 ; +22
$y = 8
Local $aInputs[15]
For $i = 0 To 14
$aInputs[$i]=GUICtrlCreateInput('', $x, $y, 21, 20)
$x += 22
$y += 21
Next
_GUIScrollBars_Init($hChild,-1)
_GUIScrollBars_ShowScrollBar($hChild, $SB_HORZ, False) ; horizontale Scrollbar verstecken
_GUIScrollBars_SetScrollRange($hChild, $SB_VERT, 3, 30)
GUISetState(@SW_HIDE,$hChild)
GUISwitch($hGui)
$idTab1 = GUICtrlCreateTabItem("tab----1")
GUICtrlCreateLabel("label1", 30, 80, 50, 20)
$idTab1combo = GUICtrlCreateCombo("", 20, 50, 60, 120)
GUICtrlSetData(-1, "Trids|CyberSlug|Larry|Jon|Tylo", "Jon"); default Jon
$idTab1OK = GUICtrlCreateButton("OK1", 80, 50, 50, 20)
$idTab2 = GUICtrlCreateTabItem("tab2")
GUICtrlSetState(-1, $Gui_SHOW); will be display first
GUICtrlCreateLabel("label2", 30, 80, 50, 20)
$idTab2OK = GUICtrlCreateButton("OK2", 140, 50, 50)
GUICtrlCreateTabItem(""); end tabitem definition
$idBtnBack = GUICtrlCreateButton("&Zurueck",72,320,100,25)
$idBtnCancel = GUICtrlCreateButton("&Beenden", 264, 320, 100, 25)
$idBtnContinue = GUICtrlCreateButton("&Weiter", 448, 320, 100, 25)
GUISetState()
GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL")

While 1
$nMsg = GuiGetMsg()
Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
  Case $idTab
   $iTab = _GUICtrlTab_GetCurSel($idTab)
   Switch $iTab
    case 0
     GUISetState(@SW_SHOW, $hChild)
    case 1
     GUISetState(@SW_HIDE, $hChild)
   EndSwitch
    EndSwitch
WEnd
Func WM_VSCROLL($hWnd, $Msg, $wParam, $lParam)
    #forceref $Msg, $wParam, $lParam
    Local $nScrollCode = BitAND($wParam, 0x0000FFFF)
    Local $index = -1, $yChar, $yPos
    Local $Min, $Max, $Page, $Pos, $TrackPos
    For $x = 0 To UBound($aSB_WindowInfo) - 1
        If $aSB_WindowInfo[$x][0] = $hWnd Then
            $index = $x
            $yChar = $aSB_WindowInfo[$index][3]
            ExitLoop
        EndIf
    Next
    If $index = -1 Then Return 0

    ; Get all the vertial scroll bar information
    Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_VERT)
    $Min = DllStructGetData($tSCROLLINFO, "nMin")
    $Max = DllStructGetData($tSCROLLINFO, "nMax")
    $Page = DllStructGetData($tSCROLLINFO, "nPage")
    ; Save the position for comparison later on
    $yPos = DllStructGetData($tSCROLLINFO, "nPos")
    $Pos = $yPos
    $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos")
    Switch $nScrollCode
        Case $SB_TOP ; user clicked the HOME keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Min)
        Case $SB_BOTTOM ; user clicked the END keyboard key
            DllStructSetData($tSCROLLINFO, "nPos", $Max)
        Case $SB_LINEUP ; user clicked the top arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1)
        Case $SB_LINEDOWN ; user clicked the bottom arrow
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1)
        Case $SB_PAGEUP ; user clicked the scroll bar shaft above the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page)
        Case $SB_PAGEDOWN ; user clicked the scroll bar shaft below the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $Pos + $Page)
        Case $SB_THUMBTRACK ; user dragged the scroll box
            DllStructSetData($tSCROLLINFO, "nPos", $TrackPos)
    EndSwitch
;~    // Set the position and then retrieve it.  Due to adjustments
;~    //   by Windows it may not be the same as the value set.
    DllStructSetData($tSCROLLINFO, "fMask", $SIF_POS)
    _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    _GUIScrollBars_GetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)
    ;// If the position has changed, scroll the window and update it
    $Pos = DllStructGetData($tSCROLLINFO, "nPos")
    If ($Pos <> $yPos) Then
        _GUIScrollBars_ScrollWindow($hWnd, 0, $yChar * ($yPos - $Pos))
        $yPos = $Pos
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_VSCROLL

download-link: http://dl.dropbox.com/u/26788176/scrollable%20TabItem.au3

Link to comment
Share on other sites

  • 4 weeks later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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