Sign in to follow this  
Followers 0
MikahS

Auto Resizing of ListView in GUI Window

8 posts in this topic

#1 ·  Posted (edited)

Hello AutoIt community,

I have a question for you. I have 3 separate ListViews which need to be auto sized to the GUI width / height. I've looked around the forum for a day or two and have tried using the WM_SIZE method, which after playing with it, I've realized that not everyone's screen is the same and hardcoding it could be troublesome.

So, I'm thinking I need to come up with a better way of resizing my ListViews to my GUI. Does anyone have any suggestions on different ways of achieving this goal?

Example script:

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=
#AutoIt3Wrapper_Outfile=
#AutoIt3Wrapper_Res_Comment=
#AutoIt3Wrapper_Res_Description=
#AutoIt3Wrapper_Res_Fileversion=
#AutoIt3Wrapper_Run_Au3Stripper=y
#Au3Stripper_Parameters=/so
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****



#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>
#include <Constants.au3>
#include <GUIListBox.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <ButtonConstants.au3>
#include <ScrollBarConstants.au3>
#include <Misc.au3>
#include <GuiScrollBars.au3>
;~ #include <GUIListViewEx.au3>

Local $List1, $List2, $List3, $List4, $lp_Buffer = 0
Local $List1Ex, $List2Ex, $List3Ex

GUI()

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Quit()
    EndSwitch
WEnd

;END MAIN LINE


Func Quit()
    Exit
EndFunc   ;==>Quit


Func GUI()
    Local $Index, $LV1, $LV2, $LV3
    $GUIhandle = GUICreate("tester", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    GUICtrlSetResizing(-1, $GUI_DOCKAUTO) ;;allows resizing of full window
    $List1 = _GUICtrlListView_Create($GUIhandle, "Computer Name", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ;;$ES_READONLY incase you don't want to be able to select text
;~  $List1Ex = _GUIListViewEx_Init($List1, "")
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $List2 = _GUICtrlListView_Create($GUIhandle, "Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
;~  $List1Ex = _GUIListViewEx_Init($List2, "")
    $List3 = _GUICtrlListView_Create($GUIhandle, "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
;~  $List1Ex = _GUIListViewEx_Init($List3, "")
    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window
    For $Index = 0 To 100 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI

;===========MAXIMIZE THE WINDOW TO SEE HOW THIS TRULY FUNCTIONS===============;
Func WM_SIZE($hWnd, $msg, $wParam, $lParam)
    $iWidth = BitAND($lParam, 0xFFFF) ; _WinAPI_LoWord
    $iHeight = BitShift($lParam, 16) ; _WinAPI_HiWord
    If $lParam > $lp_Buffer Then
        _WinAPI_MoveWindow($List1, 20, 35, $iWidth - 1200, 900)
    Else
        _WinAPI_MoveWindow($List1, 20, 35, $iWidth - 400, 448)
    EndIf
    $lp_Buffer = $lParam
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Any reply is much appreciated. :)

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites



MikahS,

I would create disabled labels behind the ListViews which resize automatically and then resize the ListViews to fit the labels:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiScrollBars.au3>
#include <GUIListViewEx.au3>
#include <EditConstants.au3>

Local $List1, $List2, $List3, $List4, $lp_Buffer = 0
Local $List1Ex, $List2Ex, $List3Ex

Global $GUIhandle, $cLabel_1, $cLabel_2, $cLabel_3

GUI()

GUIRegisterMsg($WM_SIZE, "WM_SIZE")

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Quit()
    EndSwitch
WEnd

;END MAIN LINE


Func Quit()
    Exit
EndFunc   ;==>Quit


Func GUI()
    Local $Index, $LV1, $LV2, $LV3
    $GUIhandle = GUICreate("tester", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO) ;;allows resizing of full window
    $List1 = _GUICtrlListView_Create($GUIhandle, "Computer Name", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ;;$ES_READONLY incase you don't want to be able to select text
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1,$GUI_DOCKAUTO )
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    $List2 = _GUICtrlListView_Create($GUIhandle, "Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2,$GUI_DOCKAUTO )
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = _GUICtrlListView_Create($GUIhandle, "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3,$GUI_DOCKAUTO )
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)

    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window

    For $Index = 0 To 100 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI


Func WM_SIZE($hWnd, $msg, $wParam, $lParam)

    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])

    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE
Any use? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Any use? :huh:

M23

 

 

You are one smart cookie Melba ;)

It works perfectly as expected. Only, one minor detail.

If the window is maximized it will stay the same, and will only change sizes when you are manually resizing the window. Any thoughts?


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

MikahS,

 

You are one smart cookie Melba

Thanks. :blush:

As to the "minor detail" - I suggest looking for the maximize and restore messages and running the same function when they occur. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I tried using GUIRegisterMsg($WM_SYSCOMMAND, 'WM_SIZE'). It does the same behavior for maximizing, but tries to expand everything when it is then restored.

I must be missing something.. :geek:

EDIT: Also tried

GUIRegisterMsg(0xF030, "WM_SIZE")
GUIRegisterMsg(0xF020, "WM_SIZE")
GUIRegisterMsg(0xF120, "WM_SIZE")
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

MikahS,

Try this - you need to wait until the window has been maximized/restored before you resize which is why I use a flag in the idle loop: ;)

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiScrollBars.au3>
#include <GUIListViewEx.au3>
#include <EditConstants.au3>

Local $List1, $List2, $List3, $List4, $lp_Buffer = 0
Local $List1Ex, $List2Ex, $List3Ex

Global $GUIhandle, $cLabel_1, $cLabel_2, $cLabel_3

Global $bSysMsg = False

GUI()

GUIRegisterMsg($WM_SIZE, "_WM_SIZE")
GUIRegisterMsg($WM_SYSCOMMAND, "_WM_SYSCOMMAND")

_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List2), $SB_BOTH, $ESB_DISABLE_BOTH)
_GUIScrollBars_EnableScrollBar(ControlGetHandle("", "", $List3), $SB_BOTH, $ESB_DISABLE_BOTH)


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $GUI_EVENT_CLOSE
            Quit()
    EndSwitch

    If $bSysMsg Then
        $bSysMsg = False
        _Resize_ListViews()
    EndIf

WEnd

;END MAIN LINE


Func Quit()
    Exit
EndFunc   ;==>Quit


Func GUI()
    Local $Index, $LV1, $LV2, $LV3
    $GUIhandle = GUICreate("tester", 680, 575, -1, -1, $WS_SIZEBOX + $WS_SYSMENU + $WS_MAXIMIZEBOX + $WS_MINIMIZEBOX) ;creates the parent window
    ;GUICtrlSetResizing(-1, $GUI_DOCKAUTO) ;;allows resizing of full window
    $List1 = _GUICtrlListView_Create($GUIhandle, "Computer Name", 20, 35, 300, 448, -1, $LVS_EX_DOUBLEBUFFER) ;;$ES_READONLY incase you don't want to be able to select text
    _GUICtrlListView_SetExtendedListViewStyle($List1, $LVS_EX_TWOCLICKACTIVATE)
    $cLabel_1 = GUICtrlCreateLabel("", 20, 35, 300, 448)
    GUICtrlSetState($cLabel_1, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_1,$GUI_DOCKAUTO )
    GUICtrlSetBkColor($cLabel_1, $GUI_BKCOLOR_TRANSPARENT)
    $List2 = _GUICtrlListView_Create($GUIhandle, "Date/Time", 355, 35, 190, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_2 = GUICtrlCreateLabel("", 355, 35, 190, 450)
    GUICtrlSetState($cLabel_2, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_2,$GUI_DOCKAUTO )
    GUICtrlSetBkColor($cLabel_2, $GUI_BKCOLOR_TRANSPARENT)
    $List3 = _GUICtrlListView_Create($GUIhandle, "Speed", 574, 35, 95, 450, -1, BitOR($LVS_EX_DOUBLEBUFFER, $LVS_EX_FLATSB))
    $cLabel_3 = GUICtrlCreateLabel("", 574, 35, 95, 450)
    GUICtrlSetState($cLabel_3, $GUI_DISABLE)
    GUICtrlSetResizing($cLabel_3,$GUI_DOCKAUTO )
    GUICtrlSetBkColor($cLabel_3, $GUI_BKCOLOR_TRANSPARENT)

    GUICtrlCreateLabel("Additional Info", 20, 489) ;creates the label for $List4
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    $List4 = GUICtrlCreateList("", 20, 512, 635, 40, BitOR($WS_BORDER, $WS_VSCROLL), $ES_READONLY)
    GUICtrlSetResizing($List4, $GUI_DOCKAUTO)
    GUICtrlCreateLabel("Active Connections: ", 525, 487) ;creates the label for the active connections
    GUICtrlSetResizing(-1, $GUI_DOCKSIZE)
    GUISetState(@SW_SHOW) ;shows the GUI window

    For $Index = 0 To 100 Step 1
        $LV1 = _GUICtrlListView_AddItem($List1, " ") ;adds a default value into $List1
        $LV2 = _GUICtrlListView_AddItem($List2, " ") ;adds a default value into $List2
        $LV3 = _GUICtrlListView_AddItem($List3, " ") ;adds a default value into $List3
    Next
EndFunc   ;==>GUI


Func _WM_SIZE($hWnd, $msg, $wParam, $lParam)
    _Resize_ListViews()
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_SIZE

Func _WM_SYSCOMMAND($hWnd, $msg, $wParam, $lParam)

    Const $SC_MAXIMIZE = 0xF030
    Const $SC_RESTORE = 0xF120

    Switch $wParam
        Case $SC_MAXIMIZE, $SC_RESTORE
            $bSysMsg = True
    EndSwitch

EndFunc

Func _Resize_ListViews()
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_1)
    WinMove($List1, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_2)
    WinMove($List2, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
    $aRet = ControlGetPos($GUIhandle, "", $cLabel_3)
    WinMove($List3, "", $aRet[0], $aRet[1], $aRet[2], $aRet[3])
EndFunc
M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Ah, hit the nail square on the head. ;)

Thank you for all your help Melba!

As always, much appreciated. :D


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

MikahS,

My pleasure as always. :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  
Followers 0

  • Similar Content

    • Jibberish
      By Jibberish
      Hi,
      I am automating the testing of a video player. I search a file for ".mp4" and want to create a GUI with radio buttons to select what video to play. The number of videos can change based on the user's library so this must be created automatically.  I have searched for how to accomplish this and there are several posts out there that help a little but I can't figure out the solution. I pulled the offending code from my main script and created the file below to make this easier to read. I am sure one of our experts here can help!
      #include <MsgBoxConstants.au3> #include <StringConstants.au3> #include <array.au3> #include <File.au3> #include <GUIConstantsEx.au3> Local $sMediaFile = "D:\MediaFiles\MediaFiles.txt" Local $iStrReturn = 0 Local $aText Local $aArrayFile Local $iMax = 6 ;Default number of Videos - 1 for the array counter Local $aVideoName[$iMax] = [0] Local $sCheckBox1 Local $iT = 0, $iVideoCount = 0, $iCount Local $ix = 0 Local $iy = 0 Local $idClose1 Const $iL = 10 ; Count from Left for GUI so all buttons line up ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Read a list of video file names and create a GUI with Radio Buttons to select a single video. ; Problem: We don't know how many video names will be in the text file, so we can't hard code Case Statements & their variables ; Put the Video File Names into an Array _FileReadToArray($sMediaFile, $aArrayFile) For $a = 1 To $aArrayFile[0] ; Step through the array looking for .mp4 If StringInStr($aArrayFile[$a], ".mp4") Then $iVideoCount = $iVideoCount + 1 $aText = StringSplit($aArrayFile[$a],"\\") ; This video player reads double backslashes For $a1 = 1 to $aText[0] ; Check that the array is big enough If StringInStr($aText[$a1], ".mp4") Then ;MsgBox(0,"","Video is " & $aText[$a1]) If UBound($aVideoName) = $iVideoCount Then ; Resize the array when $iCount is equal to the element count in the array to prevent subscript error ReDim $aVideoName[$aVideoName[0] + $iMax] EndIf $aVideoName[$iVideoCount] = $aText[$a1]; add data to new index element $aVideoName[0] = $a1 ; update the index count for future reference ; The idea is to create a GUI width to accommodate long video file names $it = StringLen($aVideoName[$iVideoCount]) If $iT > $ix Then $ix = $iT EndIf EndIf Next EndIf Next ; Move backwards through the array deleting blank rows For $iCount = UBound($aVideoName) - 1 To 0 Step -1 If $aVideoName[$iCount] = "" Then _ArrayDelete($aVideoName, $iCount) EndIf Next ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Create the GUI - Names and Radio Button counts will vary - How do I do this? ; ;_ArrayDisplay($aVideoName) ;Local $aVarName[$aVideoName[0]] Local $iRows = UBound($aVideoName, $UBOUND_ROWS) $iRows = $iRows -1 $aVideoName[0] = $iRows ; Prep the GUI to display the FileNames with Radio Buttons - Can only select one at a time. $a = 0 $ix = $ix + 200 $iy = ($aVideoName[0] * 30) + 60 $hGUI = GUICreate("Videos", $ix, $iy) ;$iT = $iT+30 ; Create the variable names for the Case statement - Video count may change so Video Names displayed and GUICtrlCreateRadio count may change. ;~ For $a = 1 to $aVarName[0] ;~ If UBound($aVarName) = $aVarName Then ;~ ; Resize the array when $iCount is equal to the element count in the array to prevent subscript error ;~ ReDim $aVarName[$aVarName[0] + $iMax] ;~ EndIf ;~ Assign("$bVideoName" & $a, $a) ;~ Local $aVarName[$a] = Eval($bVideoName[$a]) ;~ ; $aVarName[$a] = GUICtrlCreateRadio($aVarName[$a], $iL, $iT) ;~ Next $iCount = 1 ;MsgBox(0,"","VideoName[0] is "&$aVideoName[0]) ;_ArrayDisplay($aVideoName) Local $bVideoName1 If $iCount < $aVideoName[0] Then $bVideoName1 = GUICtrlCreateRadio($aVideoName[$iCount], $iL, $iT) GUICtrlSetState($bVideoName1, $GUI_CHECKED) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName2 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName3 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0]) Then Local $bVideoName4 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName5 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName6 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iCount = $iCount + 1 If $iCount <= ($aVideoName[0] -1) Then Local $bVideoName7 = GUICtrlCreateRadio($aVideoName[$iCount],$iL,$iT) $iT = $iT+30 EndIf $iT = $iT + 30 $idClose1 = GUICtrlCreateButton("Go!", $iL, $iT) GUISetState(@SW_SHOW) ;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ; ; Switch Statement ; ;Local $nMsg = "" While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $bVideoName1 Case $bVideoName2 Case $bVideoName3 Case $bVideoName4 Case $bVideoName5 ;Case $bVideoName6 <- Fails because there are only 5 videos - Need variable $bVideoNames ;Case $bVideoName7 <- Fails because there are only 5 videos Case $idClose1 $bVideoName1 = GUICtrlRead($bVideoName1) $bVideoName2 = GUICtrlRead($bVideoName2) $bVideoName3 = GUICtrlRead($bVideoName3) $bVideoName4 = GUICtrlRead($bVideoName4) $bVideoName5 = GUICtrlRead($bVideoName5) ;$bVideoName6 = GUICtrlRead($bVideoName6) ;$bVideoName7 = GUICtrlRead($bVideoName7) ExitLoop EndSwitch WEnd GUIDelete($nMsg) MsgBox(0,"","Case " & $nMsg & " was selected.") ; Always returns 8. ??? This is the "MediaFiles.txt" file I am reading:
      D:\\MediaFiles\\BigBuckBunny.mp4 D:\\MediaFiles\\BigBuckBunny60fps.mp4 D:\\MediaFiles\\Sintel.mp4 D:\\MediaFiles\\sintel-2048-surround.mp4 D:\\MediaFiles\\TearsOfSteel.mp4 D:\\MediaFiles\\tearsofsteel_4K.mp4 I'm sure I have several mistakes (or poor coding methods) in my AutoIt file.
    • AndyS19
      By AndyS19
      I have a listview with 3 columns and I want to set the 3rd column's color based on the item's 'Param' value, but even though I set up for the 3rd column, the entire row always gets the color.
      My test code is below, but here is the pertinent code:
      Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg
      Here is the full test code:
      #include-once ;#cs #NoTrayIcon #AutoIt3Wrapper_UseUpx=n #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #AutoIt3Wrapper_UseX64=N Opt("GUICloseOnESC", 1) ; ESC closes GUI? (0 = no, 1 = yes) Opt("GUIOnEventMode", 1) ; Change to OnEvent mode Opt('MustDeclareVars', 1) OnAutoItExitRegister("_test_exit") Opt("GUIEventOptions", 1) ;0=default, 1=just notification, 2=GuiCtrlRead tab index Opt("WinTitleMatchMode", -2) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase #include <GuiListBox.au3> #include <ListViewConstants.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <GUIConstantsEx.au3> #include <ColorConstants.au3> Global $__MCP_obj, $__MCP_GUI_hWnd, $idListView, $hListView Global $hMainWin test() Exit Func test() $hMainWin = GUICreate("Test window", 120, 100, @DesktopWidth / 2, -1) GUICtrlCreateButton("Hwnd", 10, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_1stTEST_btn") GUICtrlCreateButton("ID", 50, 10, 40, 20) GUICtrlSetOnEvent(-1, "handle_2ndTEST_btn") GUISetOnEvent($GUI_EVENT_CLOSE, "_test_exit") GUISetState(@SW_SHOW) While (1) Sleep(17) WEnd EndFunc ;==>test Func _myColorPicker($obj) logmsg("+++: $obj = 0x" & Hex($obj) & @CRLF) Local $flags = 0 Local $ww, $wh, $x, $y, $w, $h $__MCP_obj = $obj $ww = 350 $wh = 500 $x = 200 $y = 150 $__MCP_GUI_hWnd = GUICreate("myColorPicker", $ww, $wh, $x, $y, $flags) $x = 10 $y = 10 $w = 150 $h = 20 GUICtrlCreateButton("Set caller's color", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_SetColor_btn") $y += $h + 5 $w = $ww - 25 $h = $wh - 100 $idListView = GUICtrlCreateListView("", $x, $y, $w, $h, -1, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT)) $hListView = GUICtrlGetHandle($idListView) $x = $ww / 2 - 50 $y = $wh - 60 $w = 100 $h = 25 GUICtrlCreateButton("Quit Popup", $x, $y, $w, $h) GUICtrlSetOnEvent(-1, "__MCP_handle_QUIT_btn") GUICtrlSetFont($idListView, 8.5, -1, -1, "courier new") _GUICtrlListView_AddColumn($idListView, "Name", 100) _GUICtrlListView_AddColumn($idListView, "Value", 100) _GUICtrlListView_AddColumn($idListView, "Sample", 100) _GUICtrlListView_SetColumnWidth($idListView, 0, 100) _GUICtrlListView_SetColumnWidth($idListView, 1, 80) logmsg("+++: $idListView = " & $idListView) logmsg("+++: $hListView = 0x" & Hex($hListView)) __MCP_populateListView($hListView) GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW, $__MCP_GUI_hWnd) EndFunc ;==>_myColorPicker Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam, $ilParam Local $hWndFrom, $iCode, $tNMHDR $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hListView Switch $iCode Case $NM_CUSTOMDRAW Local $iDrawStage, $tCustDraw $tCustDraw = DllStructCreate($tagNMLVCUSTOMDRAW, $ilParam) $iDrawStage = DllStructGetData($tCustDraw, 'dwDrawStage') Switch $iDrawStage Case BitOR(0, $CDDS_ITEMPREPAINT) ;, $CDDS_SUBITEM) setItemColor($tCustDraw, $hWndFrom) Return $CDRF_NOTIFYSUBITEMDRAW EndSwitch EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func setItemColor($tCustDraw, $hWnd) Local $iIndex, $color, $iSubitem $iIndex = DllStructGetData($tCustDraw, 'dwItemSpec') ; item number $color = _GUICtrlListView_GetItemParam($hWnd, $iIndex) $iSubitem = DllStructGetData($tCustDraw, 'iSubItem') ; Here, I want to only change the color of the 3rd col, and not the 1st and 2nd cols DllStructSetData($tCustDraw, 'iSubItem', 2) ; always use the 3rd column (the 'sample' col) logmsg("+++: setItemColor($tCustDraw, 0x" & Hex($hWnd) & ") entered ... " _ & ", $iIndex = " & $iIndex & ", $iSubItem = " & $iSubitem & ", $color = " & Hex($color)) DllStructSetData($tCustDraw, 'clrText', $color) ; set the Text color DllStructSetData($tCustDraw, 'clrTextBk', bitnot($color)) ; set the background color EndFunc ;==>setItemColor Func logmsg($msg, $lnum = @ScriptLineNumber) ConsoleWrite("+++:" & $lnum & ": " & $msg & @CRLF) EndFunc ;==>logmsg Func __MCP_exit() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_exit Func __MCP_handle_SetColor_btn() If (IsHWnd($__MCP_obj)) Then GUISetBkColor($COLOR_BLUE, $__MCP_obj) Else GUICtrlSetBkColor($__MCP_obj, $COLOR_BLUE) EndIf EndFunc ;==>__MCP_handle_SetColor_btn Func __MCP_populateListView($hWnd) Local $text, $parts, $iIndex Local Static $aItems[] = [ _ "BLACK | " & $CLR_BLACK & "|" & "", _ "BLUE | " & $CLR_BLUE & "|" & "", _ "RED | " & $CLR_RED & "|" & "", _ "WHITE | " & $CLR_WHITE & "|" & "", _ "YELLOW | " & $CLR_YELLOW & "|" & "" _ ] _GUICtrlListView_BeginUpdate($hWnd) _GUICtrlListView_DeleteAllItems($hWnd) For $ndx = 0 To UBound($aItems) - 1 $text = $aItems[$ndx] $parts = StringSplit($text, "|", 2) $parts[0] = StringStripWS($parts[0], 3) $parts[2] = StringStripWS($parts[2], 3) $iIndex = _GUICtrlListView_AddItem($hWnd, $parts[0], -1, $parts[1]) _GUICtrlListView_AddSubItem($hWnd, $iIndex, Hex($parts[1]), 1) _GUICtrlListView_AddSubItem($hWnd, $iIndex, $parts[0], 2) Next _GUICtrlListView_EndUpdate($hWnd) EndFunc ;==>__MCP_populateListView Func __MCP_handle_QUIT_btn() GUIDelete($__MCP_GUI_hWnd) EndFunc ;==>__MCP_handle_QUIT_btn Func handle_1stTEST_btn() _myColorPicker($hMainWin) EndFunc ;==>handle_1stTEST_btn Func handle_2ndTEST_btn() _myColorPicker(@GUI_CtrlId) EndFunc ;==>handle_2ndTEST_btn Func _test_exit() Exit EndFunc ;==>_test_exit  
    • Skeletor
      By Skeletor
      Hi All,
      I know many newbies search for this feature.
      I decided to share this piece of code with everyone.
      Basically its a "splash screen" that has a transparent image.
      In a nutshell - Gui with a transparent gif.
      Enjoy...
      Download attachment....
       
      Splash Screen GUI.zip
    • Skeletor
      By Skeletor
      Hi Developers,
       
      While trying to find a way to actually style/skin the GUICtrlCreateTabItem, I read the help file and stated:
      My question to you guys is will this be updated? or am I hoping for something that will never come to pass?
      I've seen scripts between 2007 to 2009 allowing the tabs to be modified
      Reason for my question is I'm trying to make my GUI Tabs look more modern.
      Thanks in advance for reading my post.
       
    • Jibberish
      By Jibberish
      I am trying to get the results of a radio button selection. I have tried implementing sample scripts but to no avail.
      Can someone tell / show me what I am doing wrong?
      #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> Local $bSelect1 Local $bSelect2 Local $bSelect3 SelectButton() ;The results of SelectButton is not being returned MsgBox(0,"","Select1 is "& $bSelect1 & ". Select2 is "& $bSelect2 & ". Select3 is "& $bSelect3 & ".") Func SelectButton() Local $hGUI = GUICreate("SGX4CP Tests", 300, 300) GUISetState() Local $bSelect1 = GUICtrlCreateRadio("Select 1", 10, 160) Local $bSelect2 = GUICtrlCreateRadio("Select 2", 10, 190) Local $bSelect3 = GUICtrlCreateRadio("Select 3", 10, 220) ; Set TestSelectForever as the default radio button GUICtrlSetState($bSelect1, $GUI_CHECKED) Local $idClose = GUICtrlCreateButton("Start", 120,250) Local $idMsg While 1 $idMsg = GUIGetMsg() Select Case $idMsg = $GUI_EVENT_CLOSE Or $idMsg = $idClose ExitLoop Case $idMsg = $bSelect1 And BitAND(GUICtrlRead($bSelect1), $GUI_CHECKED) = $GUI_CHECKED MsgBox(0,"","Select1") Case $idMsg = $bSelect2 And BitAND(GUICtrlRead($bSelect2), $GUI_CHECKED) = $GUI_CHECKED MsgBox(0,"","Select2") Case $idMsg = $bSelect3 And BitAND(GUICtrlRead($bSelect3), $GUI_CHECKED) = $GUI_CHECKED MsgBox(0,"","Select3") ; GUICtrlRead($hGUI) EndSelect WEnd MsgBox(0,"","Select1 is "& $bSelect1 & ". Select2 is "& $bSelect2 & ". Select3 is "& $bSelect3 & ".") ; Why is this returning numbers? EndFunc