b3vad Posted April 2, 2012 Posted April 2, 2012 (edited) I have: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $cl = GUICreate("Cliplog", 500, 730, 513, 10, BitOR($WS_SIZEBOX,$WS_POPUP)) $c1 = GUICtrlCreateRadio("c1", 5, 20, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c1, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c2 = GUICtrlCreateRadio("c2", 5, 40, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c2, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c3 = GUICtrlCreateRadio("c3", 5, 60, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c3, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c4 = GUICtrlCreateRadio("c4", 5, 80, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c4, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c5 = GUICtrlCreateRadio("c5", 5, 100, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c5, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c6 = GUICtrlCreateRadio("c6", 5, 120, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c6, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c7 = GUICtrlCreateRadio("c7", 5, 140, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c7, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c8 = GUICtrlCreateRadio("c8", 5, 160, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c8, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c9 = GUICtrlCreateRadio("c9", 5, 180, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c9, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) $c10 = GUICtrlCreateRadio("c10", 5, 200, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing($c10, $GUI_DOCKRIGHT+$GUI_DOCKWIDTH) GUISetState(@SW_SHOW) WinSetOnTop($cl,"",1) While 1 sleep(100) WEnd and I wonder if its posible to create them within a loop? the problem is creating diffrent variables and had no chance with arrays either any idea will be cool Edited April 9, 2012 by b3vad [center]My language! gets the job done![/center]
Moderators Melba23 Posted April 2, 2012 Moderators Posted April 2, 2012 b3vad,Welcome to the AutoIt forum. You need to use an array like this: #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> Global $aRadios[11] $hGUI = GUICreate("Cliplog", 500, 730, 513, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) For $i = 1 To UBound($aRadios) - 1 $aRadios[$i] = GUICtrlCreateRadio("c" & $i, 5, 20 * $i, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next GUISetState(@SW_SHOW) WinSetOnTop($hGUI,"",1) While 1 Sleep(100) WEndNote you were using the same variable ($c1) for both the GUI and the first radio - not a good idea. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
b3vad Posted April 3, 2012 Author Posted April 3, 2012 b3vad, Welcome to the AutoIt forum. thank you You need to use an array like this: I always had a hard time understanding the arrays as far as i got: Global $aRadios[11] " I have to declare the number of things (I don't know the name of them) in my array " UBound($aRadios) - 1 "means end of the things and it starts with 0" Note you were using the same variable ($c1) for both the GUI and the first radio - not a good idea. M23 actually GUI was cl (L) but i got the point an will try to use better name for variables [center]My language! gets the job done![/center]
Moderators Melba23 Posted April 3, 2012 Moderators Posted April 3, 2012 b3vad,I recommend the Arrays tutorial in the Wiki. As far as this script goes:; Declare an array with 11 elements (0,1,2,3,4,5,6,7,8,9,10) Global $aRadios[11] $hGUI = GUICreate("Cliplog", 500, 730, 513, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) ; We now run our loop starting at 1 and continuing until 10 ; because UBound returns the number of elements (11) and we only want the index to go up to 10 ; as arrays in Autoit (like many other languages) start at element [0] For $i = 1 To UBound($aRadios) - 1 ; Here we fill the $i element of the array with the ControlID of that Radio ; and use that index to increase the Y-coordinate (20 * $i) $aRadios[$i] = GUICtrlCreateRadio("c" & $i, 5, 20 * $i, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) NextDoes that make it clearer? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
b3vad Posted April 4, 2012 Author Posted April 4, 2012 b3vad, I recommend the Arrays tutorial in the Wiki. will do sir Does that make it clearer? M23 Cristal clear ---------------------------------- Now it's time for new problem : Getting clipboard and put in control data here is the code #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $lc = "empty" $clip = "empty" $cnum = 0 $ans = "" Global $x[21] $hGUI = GUICreate("Cliplog", 500, 730, -513, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) For $i = 1 To UBound($x) - 1 $x[$i] = GUICtrlCreateRadio("c" & $i, 5, 20 * $i, 490, 17, BitOR($BS_RIGHT,$BS_RIGHTBUTTON)) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next GUISetState(@SW_SHOW) WinSetOnTop($hGUI,"",1) While 1 $nMsg = GUIGetMsg() $clip = ClipGet() if $clip <> $lc Then $cnum = $cnum+1 GUICtrlSetData($x[$cnum], $clip) $lc = $clip if $cnum >= UBound($x) - 1 Then $cnum = 0 EndIf EndIf ;~ if $nMsg = $GUI_EVENT_CLOSE Then ;~ Exit ;~ Else ;~ $ans = GUICtrlRead($x[1], 1) ;~ ClipPut($ans) ;~ $lc = $ans ;~ EndIf WEnd my code have 2 problems 1- when I removeor move down "$nMsg = GUIGetMsg()" from line 22 it seems "GUICtrlSetData($x[$cnum], $clip)" does an extra move and sets 2 control 2- second part that is in comment right now causes first part stop working ty for help [center]My language! gets the job done![/center]
b3vad Posted April 4, 2012 Author Posted April 4, 2012 I got my second problem GUI always sends messages (I think a 0 on each loop) and now i need a way to find my messages between them (and an short one because i don't want to creat a long case ) any idea? [center]My language! gets the job done![/center]
Moderators Melba23 Posted April 4, 2012 Moderators Posted April 4, 2012 b3vad, Take a look at this: expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> $lc = "empty" $clip = "empty" $cnum = 0 $ans = "" Global $x[21] $hGUI = GUICreate("Cliplog", 500, 730, 513, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) For $i = 1 To UBound($x) - 1 $x[$i] = GUICtrlCreateRadio("c" & $i, 5, 20 * $i, 490, 17, BitOR($BS_RIGHT, $BS_RIGHTBUTTON)) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next GUISetState(@SW_SHOW) WinSetOnTop($hGUI, "", 1) While 1 ; Read the clipboard and store the content if it has changed $clip = ClipGet() If $clip <> $lc Then $cnum = Mod($cnum, UBound($x) - 1) + 1 ; Clever way to get the index to return to 1 when it gets too high <<<<<<<< ConsoleWrite($cnum & @CRLF) GUICtrlSetData($x[$cnum], $clip) $lc = $clip ;If $cnum >= UBound($x) - 1 Then ; And then you do not need these lines <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< ; $cnum = 1 ; because we are not using element [0] ;EndIf EndIf ; Read the event queue $nMsg = GUIGetMsg() ; Loop through the radio ControlIDs For $i = 1 To UBound($x) - 1 If $nMsg = $x[$i] Then ; Found one - so add the content $ans = GUICtrlRead($x[$i], 1) ClipPut($ans) ; And confirm for testing ConsoleWrite("Clipboard set to: " & $ans & @CRLF) ; Reset the check variable $lc = $ans ; No point in looking any further ExitLoop EndIf Next WEnd I have commented the important bits - but please ask if you have any questions. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JailDoctor Posted April 5, 2012 Posted April 5, 2012 (edited) Hi Melba & b3vad,I want to send my directories (folders) not files to an array. I looked at your example and changed *.exe for ""#include <array.au3> Dim $ComboRobot1CmdSet, $data, $Loc Dim $Myarray[1] $Loc = 0 FileChangeDir(@MyDocumentsDir) ComboRobotCmdSetChange() While 1 $a_RobotCmdSetFile = FileFindNextFile($search) If @error Then ExitLoop ;~ $data &= @WorkingDir & "" & $a_RobotCmdSetFile & @CR _ArrayInsert($Myarray, $Loc, @WorkingDir & "" & $a_RobotCmdSetFile) $Loc = $Loc + 1 WEnd[/sup] It works and lists the folders, but it also lists some text files and other strange files without extension (like when you save an au3 file and forget to type the .au3).How can I list only the folders?I am working on a project to have the form expand or shrink based on the number of folders and assign each folder to a radio button. I just can't get only the folders list.Your help is appreciated. Edited April 5, 2012 by JailDoctor
Moderators Melba23 Posted April 5, 2012 Moderators Posted April 5, 2012 JailDoctor, If that code works then I would be very surprised. I would do it like this: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <File.au3> ; Let us use the AutoIt folder $sPath = StringReplace(@AutoItExe, "AutoIt3.exe", "") ; List the folders in the folder - parameter 2 $aList = _FileListToArray($sPath, "*", 2) ; Create the radio array to match the number of folders Global $aRadios[$aList[0] + 1] = [$aList[0]] ; Create the GUI $hGUI = GUICreate("Folder List", 500, 730, 513, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) ; Add the radios For $i = 1 To $aRadios[0] $aRadios[$i] = GUICtrlCreateRadio($aList[$i], 5, 20 * $i, 490, 17, BitOR($BS_RIGHT, $BS_RIGHTBUTTON)) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next GUISetState(@SW_SHOW) While 1 ; Read the event queue $nMsg = GUIGetMsg() ; Loop through the radio ControlIDs For $i = 1 To $aRadios[0] If $nMsg = $aRadios[$i] Then ; Found one! MsgBox(0, "Pressed", GUICtrlRead($aRadios[$i], 1)) ; No point in looking any further ExitLoop EndIf Next WEnd Please ask if anything is not clear. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JailDoctor Posted April 5, 2012 Posted April 5, 2012 (edited) Wow! You are amazing! You even solved the next problem I would have. How to do a case select to find out what the user selected. Your approach is so much simpler and efficient. I was thinking of counting how many folders end up in the array, then pass the folders' names to buttons, keep track of the height of the GUI and change the "left" position of the button after a specified "top" value is reached. You rock! All this came about because some colleagues want to print patient education material they have in some folders "on the fly." Instead of calling on the IT department to change the mega-huge electronic medical record, and wait for a couple of months, they came to me. I suggested to make a "floating semi-transparent" form (topmost) listing the subfolders where the documents reside. Based on the folder they choose, they will get a list of relevant documents. For example if they select diabetes from the GUI, a second GUI listing all the documents in that folder pops up and they just click to print. It would be much fancier if the GUI only shows as a tab on the side of the screen and appears on mouse hovering. I will look at the help file for some information on this. Using your technique will save a lot of headaches when they add or delete files or subfolders. Thank you so much! You have made my day! Edited April 5, 2012 by JailDoctor
BrewManNH Posted April 5, 2012 Posted April 5, 2012 It would be much fancier if the GUI only shows as a tab on the side of the screen and appears on mouse hovering. I will look at the help file for some information on this.You should take a look at playlet's for hints on how to do this, or even to integrate this into it. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
Moderators Melba23 Posted April 5, 2012 Moderators Posted April 5, 2012 JailDoctor, Glad I could help. You know where we are if you run into difficulties with the next stage. M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
b3vad Posted April 7, 2012 Author Posted April 7, 2012 I'm back (week ends)I got the whole code awesome work just the Mode part is some math monster i can't understand the whole thing and don't bother to explain it I spend 4 hrs Google and wiki it but its way above 2+2 that i can understand ty for help I'll try to find more problems to ask [center]My language! gets the job done![/center]
JailDoctor Posted April 9, 2012 Posted April 9, 2012 (edited) I got the GUI to show the folders, then another GUI to show the files of the selected folder. One click prints the selected file. I added a radiobutton to the array to create Exit and Cancel choices. Even played with the size of the windows based on the number for folders or files as well as the length of their names. Looks and feels nice. Two Problems: 1) I have some folders with a lot of files, that is why I add the scroll bar if the number of files will not fit within the @DesktopHeight - 100, the scroll bar will not show all the files (or folders) to the end of the list. How do I make the GUI display all the files or folders? 2) How do I delete the GUI when the user presses the X? I tried If $nMsg = $GUI_EVENT_CLOSE then Exit EndIf but it did not work. Here is the entire code: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIButton.au3> #include <File.au3> #include <array.au3> ;for scroll bars #include <StructureConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> HotKeySet("{ESC}", "MyExit") dim $whichfolder, $scrollmarker, $scrollmarker2 Global $NewWidth[1], $NewGUIWidth[1] ; Set the working folder ;~ $sPath = @MyDocumentsDir $sPath = FileSelectFolder("Choose a folder.", "") & "" MyFolderChoice() Func MyFolderChoice() ; List the folders in the folder - parameter 2 $aList = _FileListToArray($sPath, "*", 2) _ArrayAdd($aList, "Exit") $aList[0] = $aList[0] + 1 ;Set GUI height based on number of folders $GuiHeight = $aList[0] *22 If $GuiHeight > @DesktopHeight Then $scrollmarker = True ; to show or not the sroll bars $GuiHeight = @DesktopHeight - 100 EndIf ;Set the GUI width based on the longest folder name For $a = 1 to $aList[0] $FolderNameLength = $aList[$a] $FolderNameLength2 =StringLen($FolderNameLength) _ArrayAdd($NewWidth, $FolderNameLength2) Next ;~ $NewWidth2 = _ArrayMax($NewWidth,0,1) $NewWidthSize = _ArrayMax($NewWidth) $GuiWidth = $NewWidthSize * 8 If $GuiWidth < 200 Then ;Make sure it isn't too thin $GuiWidth = 200 EndIf ; Create the radio array to match the number of folders Global $aRadios[$aList[0] + 1] = [$aList[0]] ; Create the GUI $hGUI = GUICreate("Folder List", $GuiWidth, $GuiHeight, 500, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) ; Add the radios For $i = 1 To $aRadios[0] $aRadios[$i] = GUICtrlCreateRadio($aList[$i], 20, 20 * $i, 490, 17) Next GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") GUISetState() If $scrollmarker = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI) EndIf While 1 ; Read the event queue $nMsg = GUIGetMsg() ; Loop through the radio ControlIDs For $i = 1 To $aRadios[0] If $nMsg = $aRadios[$i] Then If GUICtrlRead($aRadios[$i], 1) = "Exit" Then Exit EndIf ; Found one! ;~ MsgBox(0, "Pressed", GUICtrlRead($aRadios[$i], 1)) ; No point in looking any further $whichfolder = $sPath & "" & GUICtrlRead($aRadios[$i], 1) ; Set the path to show files _GUICtrlButton_SetCheck($nMsg, $BST_UNCHECKED) GUIDelete();Delete the gui MyFileChoice(); Call the file selection function ExitLoop EndIf Next WEnd EndFunc Func MyFileChoice() $aList2 = _FileListToArray($whichfolder, "*", 1);file names to array If $aList2 = 0 Then ;empty folder check MsgBox(0,"Error","There are no files to print in " & $whichfolder) MyFolderChoice() EndIf _ArrayAdd($aList2, "Cancel") ;add an extra button for cancelling file selection $aList2[0] = $aList2[0] + 1 ;Fix the number of elements to include the cancel button in the gui ; Create the radio array to match the number of folders Global $aRadios2[$aList2[0] + 1] = [$aList2[0]] ;Set GUI height based on number of folders $GuiHeight2 = $aList2[0] * 22 If $GuiHeight2 > @DesktopHeight Then $scrollmarker2 = True ; to show or not the sroll bars $GuiHeight2 = @DesktopHeight - 100 ElseIf $GuiHeight2 < 150 Then $GuiHeight2 = 150 EndIf ;Set the GUI width based on the longest folder name For $b = 1 to $aList2[0] $FileNameLength = $aList2[$b] $FileNameLength2 =StringLen($FileNameLength) _ArrayAdd($NewGUIWidth, $FileNameLength2) Next ;~ $NewWidth3 = _ArrayMax($NewGUIWidth,0,1) $NewWidthSize2 = _ArrayMax($NewGUIWidth) $GuiWidth2 = $NewWidthSize2 * 8 If $GuiWidth2 < 200 Then $GuiWidth2 = 200 EndIf ; Create the GUI $hGUI2 = GUICreate("Files List", $GuiWidth2, $GuiHeight2 , 160, 10, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)) ; Add the radios For $i = 1 To $aRadios2[0] $aRadios2[$i] = GUICtrlCreateRadio($aList2[$i],20, 20 * $i, 490, 17) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUISetState() If $scrollmarker2 = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI2) EndIf While 1 ; Read the event queue $nMsg2 = GUIGetMsg() ; Loop through the radio ControlIDs For $i = 1 To $aRadios2[0] If $nMsg2 = $aRadios2[$i] Then If GUICtrlRead($aRadios2[$i], 1) = "Cancel" Then GUIDelete() MyFolderChoice() ;build the other window again ExitLoop EndIf ; Found one! MsgBox(0, "Pressed", GUICtrlRead($aRadios2[$i], 1)) ;~ _FilePrint(GUICtrlRead($aRadios2[$i], 1));Print the selected file. GUIDelete() MyFolderChoice() ;build the other window again ExitLoop EndIf Next WEnd EndFunc Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xClientMax = $aSB_WindowInfo[$index][1] $xChar = $aSB_WindowInfo[$index][2] $yChar = $aSB_WindowInfo[$index][3] $ivMax = $aSB_WindowInfo[$index][7] ExitLoop EndIf Next If $index = -1 Then Return 0 Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) ; Retrieve the dimensions of the client area. $xClient = BitAND($lParam, 0x0000FFFF) $yClient = BitShift($lParam, 16) $aSB_WindowInfo[$index][4] = $xClient $aSB_WindowInfo[$index][5] = $yClient ; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) ;~ DllStructSetData($tSCROLLINFO, "nMax", $ivMax) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ; Set the horizontal scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $xChar, $xPos Local $Min, $Max, $Page, $Pos, $TrackPos For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xChar = $aSB_WindowInfo[$index][2] ExitLoop EndIf Next If $index = -1 Then Return 0 ;~ ; Get all the horizontal scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $xPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $xPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") #forceref $Min, $Max Switch $nScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of 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_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0) Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL 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 Func MyExit() Exit EndFunc ;==>MyExit Thanks for your help Edited April 9, 2012 by JailDoctor
Moderators Melba23 Posted April 9, 2012 Moderators Posted April 9, 2012 JailDoctor,- 1. Use my GUIScrollbars_Size UDF (look in my sig for the link) which will let you set the scroll bars to the correct size for the number of radios.- 2. The only GUI with a closure [X] is $hGUI2, so you need to add the $GUI_EVENT_CLOSE to that loop.Here is the relevant bit of your script: ; Create the GUI $hGUI2 = GUICreate("Files List", $GuiWidth2, $GuiHeight2, 160, 10, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)) ; Add the radios For $i = 1 To $aRadios2[0] $aRadios2[$i] = GUICtrlCreateRadio($aList2[$i], 20, 20 * $i, 490, 17) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; You have already registered these once ;GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") ; so no need to do it again GUISetState() If $scrollmarker2 = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI2) $aRet = _GUIScrollbars_Size(0, $aRadios2[0] * 20, $GuiWidth2, $GuiHeight2) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoPage($hGUI2, $SB_VERT, $aRet[2]) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoMax($hGUI2, $SB_VERT, $aRet[3]) ; <<<<<<<<<<<<<<<<<< EndIf While 1 ; Read the event queue $nMsg2 = GUIGetMsg() If $nMsg2 = $GUI_EVENT_CLOSE Then Exit ; <<<<<<<<<<<<<<<<<< ; Loop through the radio ControlIDs For $i = 1 To $aRadios2[0]You will need to add the GUIScrollbars_Size file as an include of course. All clear? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JailDoctor Posted April 10, 2012 Posted April 10, 2012 (edited) Melba23,I got this error:>Running AU3Check (1.54.19.0) from:C:Program FilesAutoIt3C:Program FilesAutoIt3IncludeGUIScrollbars_Size.au3(239,65) : ERROR: _GUIScrollbars_Restore() already defined.Func _GUIScrollbars_Restore($hWnd, $fVert = True, $fHorz = True)~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^I commented out this function in your GUIScrollbars_Size.au3 file but it didn't help.Current Problem (commenting out the Func _GUIScrollbars_Restore($hWnd, $fVert = True, $fHorz = True) from the C:\Program Files\AutoIt3\Include\GUIScrollbars_Size.au3 file:If the folder contains less then about 56 sub folders, there is no problem displaying all folders and see them scrolling down in the GUI..When a folder contains a gazillion subfolders (like my users will probably have), the scroll bar does not show all of them. It seems to stop listing folders after the 56th folder.Here is the code. I wrote a little routine to show the window only when the user moves the mouse off the right edge of the desktop.expandcollapse popup#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..My H drivelogo.ico #AutoIt3Wrapper_outfile=H:My DocumentsPopUpTest.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIButton.au3> #include <File.au3> #include <array.au3> ;for scroll bars #include <StructureConstants.au3> #include <GUIScrollBars.au3> #include <ScrollBarConstants.au3> #include "GUIScrollbars_Ex.au3" #include "GUIScrollbars_Size.au3" ;for "peekaboo effect" right screen show function. Move mouse to the right side of the screen to show the window. #include <GDIPlus.au3> #include <Misc.au3> HotKeySet("{ESC}", "MyExit") dim $whichfolder, $scrollmarker, $scrollmarker2 Global $NewWidth[1], $NewGUIWidth[1] ; Set the working folder ;~ $sPath = @MyDocumentsDir $sPath = FileSelectFolder("Choose a folder.", "") & "" ToolTip("Move your mouse to the rigth margin of the screen to select pamphlets",300,300,"Patient Education Program",2,4) Sleep(2000) Tooltip("") HideTheGUI() Func HideTheGUI() While 1 $mpos = MouseGetPos() Select Case $mpos[0] > @DesktopWidth-50 MyFolderChoice() EndSelect WEnd EndFunc Func MyFolderChoice() ; List the folders in the folder - parameter 2 $aList = _FileListToArray($sPath, "*", 2) _ArrayAdd($aList, "Exit") $aList[0] = $aList[0] + 1 ;Set GUI height based on number of folders $GuiHeight = $aList[0] *22 If $GuiHeight > @DesktopHeight Then $scrollmarker = True ; to show or not the sroll bars $GuiHeight = @DesktopHeight - 100 EndIf ;Set the GUI width based on the longest folder name For $a = 1 to $aList[0] $FolderNameLength = $aList[$a] $FolderNameLength2 =StringLen($FolderNameLength) _ArrayAdd($NewWidth, $FolderNameLength2) Next ;~ $NewWidth2 = _ArrayMax($NewWidth,0,1) $NewWidthSize = _ArrayMax($NewWidth) $GuiWidth = $NewWidthSize * 8 If $GuiWidth < 200 Then ;Make sure it isn't too thin $GuiWidth = 200 EndIf ; Create the radio array to match the number of folders Global $aRadios[$aList[0] + 1] = [$aList[0]] ; Create the GUI $hGUI = GUICreate("Folder List", $GuiWidth, $GuiHeight, 500, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) ; Add the radios For $i = 1 To $aRadios[0] $aRadios[$i] = GUICtrlCreateRadio($aList[$i], 20, 20 * $i, 490, 17) Next GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") GUISetState() If $scrollmarker = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI) EndIf While 1 ; Read the event queue $nMsg = GUIGetMsg() ; Loop through the radio ControlIDs For $i = 1 To $aRadios[0] If $nMsg = $aRadios[$i] Then If GUICtrlRead($aRadios[$i], 1) = "Exit" Then Exit EndIf ; Found one! ;~ MsgBox(0, "Pressed", GUICtrlRead($aRadios[$i], 1)) ; No point in looking any further $whichfolder = $sPath & "" & GUICtrlRead($aRadios[$i], 1) ; Set the path to show files _GUICtrlButton_SetCheck($nMsg, $BST_UNCHECKED) GUIDelete();Delete the gui MyFileChoice(); Call the file selection function ExitLoop EndIf Next WEnd EndFunc Func MyFileChoice() $aList2 = _FileListToArray($whichfolder, "*", 1);file names to array If $aList2 = 0 Then ;empty folder check MsgBox(0,"Error","There are no files to print in " & $whichfolder) MyFolderChoice() EndIf _ArrayAdd($aList2, "Cancel") ;add an extra button for cancelling file selection $aList2[0] = $aList2[0] + 1 ;Fix the number of elements to include the cancel button in the gui ; Create the radio array to match the number of folders Global $aRadios2[$aList2[0] + 1] = [$aList2[0]] ;Set GUI height based on number of folders $GuiHeight2 = $aList2[0] * 22 If $GuiHeight2 > @DesktopHeight Then $scrollmarker2 = True ; to show or not the sroll bars $GuiHeight2 = @DesktopHeight - 100 ElseIf $GuiHeight2 < 150 Then $GuiHeight2 = 150 EndIf ;Set the GUI width based on the longest folder name For $b = 1 to $aList2[0] $FileNameLength = $aList2[$b] $FileNameLength2 =StringLen($FileNameLength) _ArrayAdd($NewGUIWidth, $FileNameLength2) Next $NewWidthSize2 = _ArrayMax($NewGUIWidth) $GuiWidth2 = $NewWidthSize2 * 8 If $GuiWidth2 < 200 Then ;GUI is too thin $GuiWidth2 = 200 EndIf ; Create the GUI $hGUI2 = GUICreate("Files List", $GuiWidth2, $GuiHeight2 , 160, 10, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)) ; Add the radios For $i = 1 To $aRadios2[0] $aRadios2[$i] = GUICtrlCreateRadio($aList2[$i],20, 20 * $i, 490, 17) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next GUISetState() If $scrollmarker2 = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI2) $aRet = _GUIScrollbars_Size(0, $aRadios2[0] * 20, $GuiWidth2, $GuiHeight2) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoPage($hGUI2, $SB_VERT, $aRet[2]) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoMax($hGUI2, $SB_VERT, $aRet[3]) ; <<<<<<<<<<<<<<<<<< EndIf ;~ If $scrollmarker2 = True Then ;We need the scroll bars ;~ _GUIScrollBars_Init($hGUI2) ;~ $aRet = _GUIScrollbars_Size(0, $aRadios2[0] * 20, $GuiWidth2, $GuiHeight2) ; <<<<<<<<<<<<<<<<<< ;~ _GUIScrollBars_SetScrollInfoPage($hGUI2, $SB_VERT, $aRet[2]) ; <<<<<<<<<<<<<<<<<< ;~ _GUIScrollBars_SetScrollInfoMax($hGUI2, $SB_VERT, $aRet[3]) ; <<<<<<<<<<<<<<<<<< ;~ EndIf While 1 ; Read the event queue $nMsg2 = GUIGetMsg() If $nMsg2 = $GUI_EVENT_CLOSE Then GUIDelete() HideTheGUI() ;Hide the window ExitLoop EndIf ; Loop through the radio ControlIDs For $i = 1 To $aRadios2[0] If $nMsg2 = $aRadios2[$i] Then If GUICtrlRead($aRadios2[$i], 1) = "Cancel" Then GUIDelete() HideTheGUI() ;Hide the window ExitLoop EndIf ; Found one! ;~ MsgBox(0, "Pressed", GUICtrlRead($aRadios2[$i], 1)) _FilePrint(GUICtrlRead($aRadios2[$i], 1));Print the selected file. GUIDelete() ;~ MyFolderChoice() ;build the other window again HideTheGUI() ExitLoop EndIf Next WEnd EndFunc Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xClientMax = $aSB_WindowInfo[$index][1] $xChar = $aSB_WindowInfo[$index][2] $yChar = $aSB_WindowInfo[$index][3] $ivMax = $aSB_WindowInfo[$index][7] ExitLoop EndIf Next If $index = -1 Then Return 0 Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) ; Retrieve the dimensions of the client area. $xClient = BitAND($lParam, 0x0000FFFF) $yClient = BitShift($lParam, 16) $aSB_WindowInfo[$index][4] = $xClient $aSB_WindowInfo[$index][5] = $yClient ; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) ;~ DllStructSetData($tSCROLLINFO, "nMax", $ivMax) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ; Set the horizontal scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $xChar, $xPos Local $Min, $Max, $Page, $Pos, $TrackPos For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xChar = $aSB_WindowInfo[$index][2] ExitLoop EndIf Next If $index = -1 Then Return 0 ;~ ; Get all the horizontal scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $xPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $xPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") #forceref $Min, $Max Switch $nScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of 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_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0) Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL 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 Func MyExit() Exit EndFunc ;==>MyExitComment:The function Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) makes a solid scroll bar occupying the entire window, so I edited it like this:; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) ;~ DllStructSetData($tSCROLLINFO, "nMax", $ivMax) <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO)Very confused now Edited April 10, 2012 by JailDoctor
Moderators Melba23 Posted April 10, 2012 Moderators Posted April 10, 2012 JailDoctor,That sounds as if you included both of the UDFs - you only need the one: This works perfectly for me: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <GUIButton.au3> #include <File.au3> #include <array.au3> ;for scroll bars #include <StructureConstants.au3> #include <GUIScrollBars.au3> #include <GUIScrollbars_Size.au3> ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include <ScrollBarConstants.au3> HotKeySet("{ESC}", "MyExit") Dim $whichfolder, $scrollmarker, $scrollmarker2 Global $NewWidth[1], $NewGUIWidth[1] ; Set the working folder ;~ $sPath = @MyDocumentsDir $sPath = FileSelectFolder("Choose a folder.", "") & "" MyFolderChoice() Func MyFolderChoice() ; List the folders in the folder - parameter 2 $aList = _FileListToArray($sPath, "*", 2) _ArrayAdd($aList, "Exit") $aList[0] = $aList[0] + 1 ;Set GUI height based on number of folders $GuiHeight = $aList[0] * 22 If $GuiHeight > @DesktopHeight Then $scrollmarker = True ; to show or not the sroll bars $GuiHeight = @DesktopHeight - 100 EndIf ;Set the GUI width based on the longest folder name For $a = 1 To $aList[0] $FolderNameLength = $aList[$a] $FolderNameLength2 = StringLen($FolderNameLength) _ArrayAdd($NewWidth, $FolderNameLength2) Next ;~ $NewWidth2 = _ArrayMax($NewWidth,0,1) $NewWidthSize = _ArrayMax($NewWidth) $GuiWidth = $NewWidthSize * 8 If $GuiWidth < 200 Then ;Make sure it isn't too thin $GuiWidth = 200 EndIf ; Create the radio array to match the number of folders Global $aRadios[$aList[0] + 1] = [$aList[0]] ; Create the GUI $hGUI = GUICreate("Folder List", $GuiWidth, $GuiHeight, 500, 10, BitOR($WS_SIZEBOX, $WS_POPUP)) ; Add the radios For $i = 1 To $aRadios[0] $aRadios[$i] = GUICtrlCreateRadio($aList[$i], 20, 20 * $i, 490, 17) Next GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") GUISetState() If $scrollmarker = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI) EndIf While 1 ; Read the event queue $nMsg = GUIGetMsg() ; Loop through the radio ControlIDs For $i = 1 To $aRadios[0] If $nMsg = $aRadios[$i] Then If GUICtrlRead($aRadios[$i], 1) = "Exit" Then Exit EndIf ; Found one! ;~ MsgBox(0, "Pressed", GUICtrlRead($aRadios[$i], 1)) ; No point in looking any further $whichfolder = $sPath & "" & GUICtrlRead($aRadios[$i], 1) ; Set the path to show files _GUICtrlButton_SetCheck($nMsg, $BST_UNCHECKED) GUIDelete();Delete the gui MyFileChoice(); Call the file selection function ExitLoop EndIf Next WEnd EndFunc ;==>MyFolderChoice Func MyFileChoice() $aList2 = _FileListToArray($whichfolder, "*", 1);file names to array If $aList2 = 0 Then ;empty folder check MsgBox(0, "Error", "There are no files to print in " & $whichfolder) MyFolderChoice() EndIf _ArrayAdd($aList2, "Cancel") ;add an extra button for cancelling file selection $aList2[0] = $aList2[0] + 1 ;Fix the number of elements to include the cancel button in the gui ; Create the radio array to match the number of folders Global $aRadios2[$aList2[0] + 1] = [$aList2[0]] ;Set GUI height based on number of folders $GuiHeight2 = $aList2[0] * 22 If $GuiHeight2 > @DesktopHeight Then $scrollmarker2 = True ; to show or not the sroll bars $GuiHeight2 = @DesktopHeight - 100 ElseIf $GuiHeight2 < 150 Then $GuiHeight2 = 150 EndIf ;Set the GUI width based on the longest folder name For $b = 1 To $aList2[0] $FileNameLength = $aList2[$b] $FileNameLength2 = StringLen($FileNameLength) _ArrayAdd($NewGUIWidth, $FileNameLength2) Next ;~ $NewWidth3 = _ArrayMax($NewGUIWidth,0,1) $NewWidthSize2 = _ArrayMax($NewGUIWidth) $GuiWidth2 = $NewWidthSize2 * 8 If $GuiWidth2 < 200 Then $GuiWidth2 = 200 EndIf ; Create the GUI $hGUI2 = GUICreate("Files List", $GuiWidth2, $GuiHeight2, 160, 10, BitOR($WS_MINIMIZEBOX, $WS_CAPTION, $WS_POPUP, $WS_SYSMENU, $WS_SIZEBOX)) ; Add the radios For $i = 1 To $aRadios2[0] $aRadios2[$i] = GUICtrlCreateRadio($aList2[$i], 20, 20 * $i, 490, 17) GUICtrlSetResizing(-1, $GUI_DOCKRIGHT + $GUI_DOCKWIDTH) Next ;GUIRegisterMsg($WM_SIZE, "WM_SIZE") ; You have already registered these once ;GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") ; so no need to do it again GUISetState() If $scrollmarker2 = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI2) $aRet = _GUIScrollbars_Size(0, $aRadios2[0] * 20, $GuiWidth2, $GuiHeight2) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoPage($hGUI2, $SB_VERT, $aRet[2]) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoMax($hGUI2, $SB_VERT, $aRet[3]) ; <<<<<<<<<<<<<<<<<< EndIf While 1 ; Read the event queue $nMsg2 = GUIGetMsg() If $nMsg2 = $GUI_EVENT_CLOSE Then Exit ; <<<<<<<<<<<<<<<<<< ; Loop through the radio ControlIDs For $i = 1 To $aRadios2[0] If $nMsg2 = $aRadios2[$i] Then If GUICtrlRead($aRadios2[$i], 1) = "Cancel" Then GUIDelete() MyFolderChoice() ;build the other window again ExitLoop EndIf ; Found one! MsgBox(0, "Pressed", GUICtrlRead($aRadios2[$i], 1)) ;~ _FilePrint(GUICtrlRead($aRadios2[$i], 1));Print the selected file. GUIDelete() MyFolderChoice() ;build the other window again ExitLoop EndIf Next WEnd EndFunc ;==>MyFileChoice Func WM_SIZE($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $wParam Local $index = -1, $yChar, $xChar, $xClientMax, $xClient, $yClient, $ivMax For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xClientMax = $aSB_WindowInfo[$index][1] $xChar = $aSB_WindowInfo[$index][2] $yChar = $aSB_WindowInfo[$index][3] $ivMax = $aSB_WindowInfo[$index][7] ExitLoop EndIf Next If $index = -1 Then Return 0 Local $tSCROLLINFO = DllStructCreate($tagSCROLLINFO) ; Retrieve the dimensions of the client area. $xClient = BitAND($lParam, 0x0000FFFF) $yClient = BitShift($lParam, 16) $aSB_WindowInfo[$index][4] = $xClient $aSB_WindowInfo[$index][5] = $yClient ; Set the vertical scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) ;~ DllStructSetData($tSCROLLINFO, "nMax", $ivMax) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $yClient / $yChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_VERT, $tSCROLLINFO) ; Set the horizontal scrolling range and page size DllStructSetData($tSCROLLINFO, "fMask", BitOR($SIF_RANGE, $SIF_PAGE)) DllStructSetData($tSCROLLINFO, "nMin", 0) DllStructSetData($tSCROLLINFO, "nMax", 2 + $xClientMax / $xChar) DllStructSetData($tSCROLLINFO, "nPage", $xClient / $xChar) _GUIScrollBars_SetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) Return $GUI_RUNDEFMSG EndFunc ;==>WM_SIZE Func WM_HSCROLL($hWnd, $Msg, $wParam, $lParam) #forceref $Msg, $lParam Local $nScrollCode = BitAND($wParam, 0x0000FFFF) Local $index = -1, $xChar, $xPos Local $Min, $Max, $Page, $Pos, $TrackPos For $x = 0 To UBound($aSB_WindowInfo) - 1 If $aSB_WindowInfo[$x][0] = $hWnd Then $index = $x $xChar = $aSB_WindowInfo[$index][2] ExitLoop EndIf Next If $index = -1 Then Return 0 ;~ ; Get all the horizontal scroll bar information Local $tSCROLLINFO = _GUIScrollBars_GetScrollInfoEx($hWnd, $SB_HORZ) $Min = DllStructGetData($tSCROLLINFO, "nMin") $Max = DllStructGetData($tSCROLLINFO, "nMax") $Page = DllStructGetData($tSCROLLINFO, "nPage") ; Save the position for comparison later on $xPos = DllStructGetData($tSCROLLINFO, "nPos") $Pos = $xPos $TrackPos = DllStructGetData($tSCROLLINFO, "nTrackPos") #forceref $Min, $Max Switch $nScrollCode Case $SB_LINELEFT ; user clicked left arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos - 1) Case $SB_LINERIGHT ; user clicked right arrow DllStructSetData($tSCROLLINFO, "nPos", $Pos + 1) Case $SB_PAGELEFT ; user clicked the scroll bar shaft left of the scroll box DllStructSetData($tSCROLLINFO, "nPos", $Pos - $Page) Case $SB_PAGERIGHT ; user clicked the scroll bar shaft right of 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_HORZ, $tSCROLLINFO) _GUIScrollBars_GetScrollInfo($hWnd, $SB_HORZ, $tSCROLLINFO) ;// If the position has changed, scroll the window and update it $Pos = DllStructGetData($tSCROLLINFO, "nPos") If ($Pos <> $xPos) Then _GUIScrollBars_ScrollWindow($hWnd, $xChar * ($xPos - $Pos), 0) Return $GUI_RUNDEFMSG EndFunc ;==>WM_HSCROLL 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 Func MyExit() Exit EndFunc ;==>MyExitHow about you? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JailDoctor Posted April 11, 2012 Posted April 11, 2012 (edited) It works! When I select a folder pointing to a shared drive with 109 sub folders there is a problem displaying all the sub folders. The scroll bar only goes down to folder 56; but I can live with it unless you have any ideas. Edited April 11, 2012 by JailDoctor
Moderators Melba23 Posted April 11, 2012 Moderators Posted April 11, 2012 JailDoctor, Of course I have ideas! You need to set the scrollbars size for the first GUI in the same way as as you do for the second: GUIRegisterMsg($WM_SIZE, "WM_SIZE") GUIRegisterMsg($WM_VSCROLL, "WM_VSCROLL") GUIRegisterMsg($WM_HSCROLL, "WM_HSCROLL") GUISetState() If $scrollmarker = True Then ;We need the scroll bars _GUIScrollBars_Init($hGUI) $aRet = _GUIScrollbars_Size(0, $aRadios[0] * 20, $GuiWidth, $GuiHeight) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoPage($hGUI, $SB_VERT, $aRet[2]) ; <<<<<<<<<<<<<<<<<< _GUIScrollBars_SetScrollInfoMax($hGUI, $SB_VERT, $aRet[3]) ; <<<<<<<<<<<<<<<<<< EndIf While 1 ; Read the event queue $nMsg = GUIGetMsg() All fixed? M23 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area
JailDoctor Posted April 11, 2012 Posted April 11, 2012 Outstanding!!!! You are the best!!! It makes perfect sense now. Why not do what worked in the other gui... You make it look so easy. Thank you so much!
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now