Jump to content

button placement relative to tabs


Overkill
 Share

Recommended Posts

I haven't had a chance to explore relative coords as much as i would have liked, and I'm a stickler for dead-reckoning with my autoit apps...less moving parts on a machine means there's less that can break.

Anyway...I've got a GUI with a variable number of tabs, and I want to have the button move if a 2nd/3rd/nth row of tabs is added. Is there a way to do that?

IE:

<--Tab Row 1-->

<--Button-->

<--Tab Row 1-->

<--Tab Row 2-->

<--Button-->

Right now the button just overlaps the tabs.

Edited by Overkill
Link to comment
Share on other sites

I haven't had a chance to explore relative coords as much as i would have liked, and I'm a stickler for dead-reckoning with my autoit apps...less moving parts on a machine means there's less that can break.

Anyway...I've got a GUI with a variable number of tabs, and I want to have the button move if a 2nd/3rd/nth row of tabs is added. Is there a way to do that?

IE:

<--Tab Row 1-->

<--Button-->

<--Tab Row 1-->

<--Tab Row 2-->

<--Button-->

Right now the button just overlaps the tabs.

Can you show some code?

It makes it difficult to reply to these sorts of questions otherwise IMO. That way we can see if you really mean tabs or tab items for example, and we don't need to waste our time writing an example only to be told that's not what was meant (one of my favourites :) ).

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

Here's the code I've built so far...problem is moving the file lists to match the pos of the tabs.

I've changed the format of my GUI, so instead of a button, now we're looking at a listview.

EDIT: Code fixed for testing

#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<TabConstants.au3>
#Include<GuiListView.au3>

Opt("GUIResizeMode",$GUI_DOCKBORDERS)

Dim $A[6]
$A[0]=5
$A[1]="One"
$A[2]="Two"
$A[3]="Three"
$A[4]="Four"
$A[5]="Five"

GUICreate("Directory List",622,482,Default,Default,BitOr($GUI_SS_DEFAULT_GUI,$WS_MAXIMIZEBOX,$WS_SIZEBOX))
    $TAB = GUICtrlCreateTab(1,1,620,480,BitOr($GUI_SS_DEFAULT_TAB,$TCS_MULTILINE,$TCS_RIGHTJUSTIFY))

Dim $L[1]
    For $I=1 to $A[0]
        $J=$I-1
        GUICtrlCreateTabItem($A[$I])
        Dim $B[2]
        $B[0]=1
        $B[1]="Item in tab " & $I
        $L[$J]=GUICtrlCreateListView("",2,140,615,335)
        _GUICtrlListView_SetExtendedListViewStyle($L[$J], BitOR($LVS_EX_BORDERSELECT , $LVS_EX_CHECKBOXES ))
        _GUICtrlListView_InsertColumn($L[$J], 0, "Filelist", 610)
            For $n = 1 to $B[0]
            Dim $T[$B[0]+1]
            $T[$N] = _GUICtrlListView_AddItem($L[$J], $B[$N], $N - 1)
            Next
        GUICtrlSetResizing($L[$J],BitOr($GUI_DOCKBORDERS,$GUI_DOCKTOP))
        ReDim $L[$I+1]
    Next

GUICtrlCreateTabItem("")
GUISetState(@SW_SHOW)

While 1
    $m = GUIGetMsg()
    If $m = $GUI_EVENT_CLOSE THEN Exit
WEnd
Edited by Overkill
Link to comment
Share on other sites

  • Moderators

Overkill,

A (partial) solution to your problem. It works IF you do not apply the $WS_SIZEBOX to your GUI, because it sets a value for the top of the ListBox which is only valid for a specific tab layout - which is determined by the GUI width. If you change the size of the GUI, the everything resizes with it - except the top of the ListView. Just replace the GUI creation part of your code with this:

$GUIDepth = 482

GUICreate("Directory List", 622, $GUIDepth, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX))
$TAB = GUICtrlCreateTab(1, 1, 620, 430, BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))

;~ Dim $LISTVIEW[2]
Dim $STORE[$ARTISTLIST[0] + 1][1]

; Create all the tabitems
$start = GUICtrlCreateDummy()
For $I = 1 To $ARTISTLIST[0]
    $TabItem = GUICtrlCreateTabItem($ARTISTLIST[$I])
Next
$end = GUICtrlCreateDummy()

; Measure the client area of the tab
$aPos = _GUICtrlTab_GetDisplayRect(ControlGetHandle("Directory List", "", $TAB))

; Delete the dummy tabitems
For $I = $start To $end
    GUICtrlDelete($I)
Next

; Create the real tabitems
For $I = 1 To $ARTISTLIST[0]

    $TabItem = GUICtrlCreateTabItem($ARTISTLIST[$I])
    $SONGLIST = FileList($MUSICDIR & "\" & $ARTISTLIST[$I], 1, $EXT)

    $LISTVIEW = GUICtrlCreateListView("Filelist", 2, $aPos[1], 615, $GUIDepth - $aPos[1] - 50, -1, $LVS_EX_CHECKBOXES)
    _GUICtrlListView_SetColumnWidth($LISTVIEW, 0, $LVSCW_AUTOSIZE_USEHEADER)

    For $n = 1 To $SONGLIST[0]
        If $SONGLIST[0] + 1 > UBound($STORE, 2) Then ReDim $STORE[$ARTISTLIST[0] + 1][$SONGLIST[0] + 1]
        $STORE[$I][0] = $SONGLIST[0]
        $STORE[$I][$n] = GUICtrlCreateListViewItem($SONGLIST[$n], $LISTVIEW)

    Next

    GUICtrlSetResizing($LISTVIEW, BitOR($GUI_DOCKBORDERS, $GUI_DOCKTOP))
Next

GUICtrlCreateTabItem("")

$BUTTON = GUICtrlCreateButton("Button", 10, $GUIDepth - 40, 120, 30)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKWIDTH, $GUI_DOCKHEIGHT, $GUI_DOCKBOTTOM))

GUISetState(@SW_SHOW)

The comments should make clear what the code does - it is a bit of fudge, but it works! I also fixed the button in size and position.

By the way, be careful using similar upper and lowercase variables (like $TAB and $tab). I believe AutoIt uppercases everything when you run/compile, which would make these variables the same and which could well lead to problems later in the code. I try to keep all my variables as distinct as possible.

I think I might be able to fix the resizing problem, but that will mean using a custom $WM_SIZE function and that will take a bit more work. And as my golf club should be open again tomorrow after all the snow we had recently........

Enjoy!

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

I'll give this a test as soon as I have my dual-monitor setup back (I'm currently reinstalling Windows on a box that was 'bricked' by a failed SP3 install on the other monitor).

Also, the whole goal was to get reposition it with the window resize :/ I suppose I could add a button to do it for me...but that would be messy...not to mention not automated!

Have fun golfing ^.^

Link to comment
Share on other sites

  • Moderators

Overkill,

Course is now waterlogged! But at least I have a full solution for you. This code resizes the listboxes to fit under the tabs regardless of how many layers there are:

#include<GUIConstantsEx.au3>
#include<WindowsConstants.au3>
#include<TabConstants.au3>
#include<GuiListView.au3>
#include <GuiTab.au3>

Opt("GUIResizeMode", $GUI_DOCKBORDERS)

; When window is resized, run this function
GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE")

Global $iGUIWidth = 800, $iGUIHeight = 500, $fResized = False

$MainGUI = GUICreate("Directory List", $iGUIWidth, $iGUIHeight, Default, Default, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX))
$TAB = GUICtrlCreateTab(1, 1, $iGUIWidth - 2, $iGUIHeight - 50, BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))

; Set number of TabItems   ------------  In your script this value is $ARTISTLIST[0]
Global $iTabNumber = 15

; Create array holding dummy tabitem titles   ---------------  In your script this array is $ARTISTLIST
Global $aTitles[$iTabNumber + 1]
For $i = 1 To $iTabNumber
    $aTitles[$i] = ""
    For $j = 1 To Random(4, 10, 1)
        $aTitles[$i] &= String($i) & " "
    Next
Next
    
; Determine initial TabTop value
$iTabTop = Tab_Sizer($iTabNumber, $aTitles)

; Create array to hold ListView handles
Global $aListView[$iTabNumber + 1] = [$iTabNumber]

; Create tabitems
For $i = 1 To $iTabNumber

    GUICtrlCreateTabItem($aTitles[$i])
    $aListView[$i] = GUICtrlCreateListView("Filelist", 10, $iTabTop, $iGUIWidth - 22, $iGUIHeight - $iTabTop - 50, -1, $LVS_EX_CHECKBOXES)
        _GUICtrlListView_SetColumnWidth($aListView[$i], 0, $LVSCW_AUTOSIZE_USEHEADER)
        _GUICtrlListView_SetBkColor($aListView[$i], 0xFF0000); Just to show the size
        GUICtrlSetResizing($aListView[$i], BitOR($GUI_DOCKBORDERS, $GUI_DOCKLEFT))

; Fill ListView with some items -------------  In your script use the song titles
    For $j = 1 To 25
        GUICtrlCreateListViewItem("Item " & $j & " - ListView " & $i & "    Blahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblahblah", $aListView[$i])
    Next

Next

; Close Tab definiton
GUICtrlCreateTabItem("")

; Create button
$hButton = GUICtrlCreateButton("Button", 10, $iGUIHeight - 40, 120, 30)
GUICtrlSetResizing(-1, BitOR($GUI_DOCKWIDTH, $GUI_DOCKHEIGHT, $GUI_DOCKBOTTOM))

GUISetState(@SW_SHOW)

While 1
    
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hButton
    ; Put your button press code here
    EndSwitch

; Look for resize message
    If $fResized Then

; Determine new TabTop value
        $iTabTop = Tab_Sizer($iTabNumber, $aTitles)
; Resize all Listviews to fit new Tab dimensions
        For $i = 1 To $aListView[0]
            GUICtrlSetPos($aListView[$i], 10, $iTabTop, $iGUIWidth - 22, $iGUIHeight - $iTabTop - 50)
            _GUICtrlListView_SetColumnWidth($aListView[$i], 0, $LVSCW_AUTOSIZE_USEHEADER)
        Next
; Reset flag
        $fResized = False
    EndIf

WEnd

Func Tab_Sizer($iTabTotal, $aTabTitles)
    
; Create test GUI
    $TestGUI = GUICreate("", $iGUIWidth, 500)
; Create test Tab
    $TestTAB = GUICtrlCreateTab(1, 1, $iGUIWidth - 2, 500, BitOR($GUI_SS_DEFAULT_TAB, $TCS_MULTILINE, $TCS_RIGHTJUSTIFY))
; Create correct number of TabItems
    For $i = 1 To $iTabTotal
        GUICtrlCreateTabItem($aTabTitles[$i])
    Next
; Measure the client area of the Tab
    $aPos = _GUICtrlTab_GetDisplayRect(ControlGetHandle($TestGUI, "", $TestTAB))
; Delete test GUI
    GUIDelete($TestGUI)
; Return new TabTop value
    Return $aPos[1]
    
EndFunc
    
Func MY_WM_SIZE($hWnd, $Msg, $wParam, $lParam)
    
    $iGUIWidth = BitAND($lParam, 0xFFFF)
    $iGUIHeight = BitShift($lParam, 16)
; Set flag
    $fResized = True
        
    Return $GUI_RUNDEFMSG
    
EndFunc ;==>WM_SIZE

How does it work? You need to know this to fit it into your code because I simplified it a lot for testing purposes.

You start with the GUIRegisterMsg($WM_SIZE, "MY_WM_SIZE") line which tells AutoIt to run this function when it gets the $WM_SIZE message after a window resize.

Then when you have determined the number of tabs and their titles you run the function Tab_Sizer which tells you where the user area of the tabs starts.

Now you can create the tabs and place the ListViews at the right place. Note that you must pass the number of tabs and their titles to the Tab_Sizer function, otherwise your tabs will not be the same as in the GUI you are creating.

Then in your While...WEnd loop you look for the $fResized flag to be set by the MY_WM_SIZE function when you resize the window. The MY_WM_SIZE function also resets the width and height values of the GUI to their new values.

If the flag is set, we call the Tab_Sizer function again to get the new location for the ListViews. Then we resize the ListViews and reset the column width so that they fit the new GUI size. Finally we reset the $fResized flag until the next resize.

Ask if you are unsure about anything - although I have given you some hints as to what you need to change to fit this into your code.

M23

Edited by Melba23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

Refran,

Thank you for the typo catch (that is what happens when you try and edit the code slightly while writing the reply!) and the kind comments. Much of the credit must go the the AutoIt team for providing such a good language to use - if they did not offer the possibilities, we could not produce such interesting (and I hope useful) scripts.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Brain isn't quite ready to absorb this at 6:45AM so I'll come back later.

I wish you better luck tomorrow M =)

While $ballinhole=False
    MsgBox(48,"Warning","FORE!!!")
    HitBall($club,$power,$direction)
Wend
Edited by Overkill
Link to comment
Share on other sites

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...