Jump to content

WinMove demolishes my GUI


kindlin
 Share

Recommended Posts

Two questions, first:

I'm making a GUI for a program I'm writing (i wouldn't call it basic, but it's not anything advanced either) and I'm trying to get the window to automatically adjust as the user selects options. When they select option 1, it only needs about 150 pixels, so the window will be 150 pixels. Option 2 on the other hand is more like 300 pixels on info/options/inputs, so the window needs to expand. I got the Tab to automatically increase in size with the following code, $Ypos is updated every time a GUI element is created, so it always makes the Tab as big as the last element created.

$TabPos=ControlGetPos("Automation","",$Tab)
ControlMove("Automation","",$Tab,$TabPos[0],$TabPos[1],$TabPos[2],$Ypos-5)

I tried basically the exact code but for the window, but craziness happens. (With WinGetPos and WinMove) All of my previously created elements all get squished at the top the second the WinMove code is ran. I tried tying it to a hotkey and it was all good until I hit that hotkey! haha. So what can I do to either A) make it not get squished/messed up, or B ) use some other function to adjust the window size, but I haven't found one.

Second question:

I have the basic GUI elements created and then I GUISetState() and they all appear. I then add in further GUI elements based on what option the user selects. The problem is those new elements are not part of the initial tabs I create, so when I go from one tab to another the new elements just sit their, and are not attached to the tabs. I've tried having the GUISetState at the end of the endless while loop which controls my options/the rest of my GUI, hoping it would re @show every time, but then nothing appears, ever.

Any help would be greatly appreciated.

Link to comment
Share on other sites

1: How did you tell the controls to resize? Post a reproducer (short running example) so we can see how you are using GUICtrlSetResizing()/GUIResizeMode.

2: You need to switch the "active" tab with GUISwitch().

And you said this is your GUI so use GUICtrlSetPos() instead of ControlMove(). Also use the window handle (remember GUICreate()?) instead of using the title, you never know what other windows may exist when your script get to that point.

Link to comment
Share on other sites

I never use either of these commands:

GUICtrlSetResizing()

GUIResizeMode

Some google searching and help file browsing led me to those, but none of the info I could find made any sense. Some one posted ControlMove and I fell in love. I can't think of an easy way to show just what I'm talking about, so just run this code, check out how it automatically adjusts the tab height when you select pause/mouseclick, then un-comment the WinMove section near the bottom and see it gets total screwed. I made the currently commented out part a hotkey at one point to see it mutilate my GUI upon a key press, but that didn't help me resolve the problem.

HotKeySet("{END}","end")

#include <GUIConstantsEx.au3>

$TabWidth=300
$TabHeight=100
$BorderWidth=15
Dim $ButtonSize[2]
$ButtonSize[0]=75
$ButtonSize[1]=20
$CurrentTask="Dummy"
Global $Ypos=$BorderWidth
Global $CurrentMousePos[2]=["N/A", "N/A"]

GUICreate("Automation",$tabWidth+$BorderWidth*2,$BorderWidth*2+$TabHeight+250)

$Tab=GUICtrlCreateTab($BorderWidth,$Ypos,$tabWidth,$TabHeight+250)
$Ypos=$Ypos+30
$TabC=GUICtrlCreateTabItem("Construction")
GUICtrlCreateLabel("Select new task for your Automation to perform",$BorderWidth*2,$Ypos)
$Ypos=$Ypos+20
$Combo=GUICtrlCreateCombo("",$BorderWidth*2,$Ypos,$ButtonSize[0]*2,$ButtonSize[1])
$Ypos=$Ypos+$ButtonSize[1]+10
GUICtrlSetData($Combo,"Pause(ms)|Mouse Click|Wait For Pixel|Mouse Move|Mouse Drag")
$YposHold=$Ypos
$Tab2=GUICtrlCreateTabItem("Testing")
GUISetState()

While 1
    
    $msg = GUIGetMsg()
    $CurrentTaskOld=$CurrentTask
    $CurrentTask=GUICtrlRead($Combo)
    
    
    If $CurrentTask<>$CurrentTaskOld then
        $Ypos=$YposHold
        For $i=8 to 20
            GUICtrlDelete($i)
        Next
        
        Select
        Case $CurrentTask = "" Or $CurrentTask="Dummy"
            ;do nothing
        Case $CurrentTask = "Pause(ms)"
            GUICtrlCreateLabel("Enter the duration you wish Automation program to pause.",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            $Ptime=GUICtrlCreateInput("Duration",$BorderWidth*2,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
        Case $CurrentTask = "Mouse Click"
            HotKeySet("{ENTER}","MousePos")
            GUICtrlCreateLabel("Which button? (1,2,4, etc.)",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            $Cbutton=GUICtrlCreateInput("Button",$BorderWidth*2,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
            GUICtrlCreateLabel("Press ""Enter"" to aquire mouse position.",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            $Clabelxy=GUICtrlCreateLabel("Current saved location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            GUICtrlCreateLabel("# Clicks",$BorderWidth*2,$Ypos)
            GUICtrlCreateLabel("Mouse Speed (0=instant)",$BorderWidth*2+115,$Ypos)
            $Ypos=$Ypos+20
            $Cclick=GUICtrlCreateInput("Clicks",$BorderWidth*2,$Ypos,75)
            $Cspeed=GUICtrlCreateInput("Speed",$BorderWidth*2+115,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
        Case $CurrentTask = "Wait For Pixel"
            
            
        Case $CurrentTask = "Mouse Move"
            
        Case $CurrentTask = "Mouse Drag"
            
        EndSelect
        
        $NTbutton=GUICtrlCreateButton("Finish",$BorderWidth*2,$Ypos,$ButtonSize[0],$ButtonSize[1])
        $Ypos=$Ypos+$ButtonSize[1]+5
        
        $TabPos=ControlGetPos("Automation","",$Tab)
        ControlMove("Automation","",$Tab,$TabPos[0],$TabPos[1],$TabPos[2],$Ypos-5)
        
        ;$WinPos=WinGetPos("Automation")
        ;WinMove("Automation","",$WinPos[0],$WinPos[1],$WinPos[2],$Ypos+$BorderWidth*2)
    EndIf
    
    Select
    Case $msg=$GUI_EVENT_CLOSE 
        end()
    Case $msg=$NTbutton
        NewTask()
    EndSelect
WEnd

Func MousePos()
    $CurrentMousePos=MouseGetPos()
    GUICtrlSetData($Clabelxy, "Current saved location: X="&$CurrentMousePos[0]&", Y="&$CurrentMousePos[1])
EndFunc

Func end()
    Exit
EndFunc

2. I checked the help file on GUISwitch() and it does talk about tabs, but where/when do I need to put the switch in for the Construction tab to keep all current GUI elements I have my program creating? And when I start working on the second tab, (probably wont be "testing" more like "using") how do I tell it all further elements go to that tab?

And I used "Automation" as the title because it asked for a title. Can I just pass "1" which is the handle of my GUI window, it being the first thing created in my code. (I have verififed my GUI is handle 1). Also whats a "winhandle"? Is that the return value of GUICreate?

Whats the difference between ControlMove and GUICtrlSetPos? Is there a reason to use one over the other?

Also, random question, is there a reason to "Opt('MustDeclareVars', 1)" and then make a bunch of local/global variables declared right off the bat? I just declare constants as a random global variable (none func'ed=automatically global) and I simply declare variables as they are used, unless I have a reason not to.

Link to comment
Share on other sites

I never use either of these commands:

GUICtrlSetResizing()

GUIResizeMode

Some google searching and help file browsing led me to those, but none of the info I could find made any sense. ..........

You need to make sense of it. It really isn't complicated. If you want the left side of a control to stay at the same left position then add $GUI_DOCKLEFT, if you want the width to stay constant add $GUI_DOCKWIDTH.

HotKeySet("{END}","end")

#include <GUIConstantsEx.au3>
#include <windowsconstants.au3>
Opt("guiresizemode",$GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT)
$TabWidth=300
$TabHeight=100
$BorderWidth=15
Dim $ButtonSize[2]
$ButtonSize[0]=75
$ButtonSize[1]=20
$CurrentTask="Dummy"
Global $Ypos=$BorderWidth
Global $CurrentMousePos[2]=["N/A", "N/A"]

GUICreate("Automation",$tabWidth+$BorderWidth*2,$BorderWidth*2+$TabHeight+250,-1,-1,BitOr($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX))

$Tab=GUICtrlCreateTab($BorderWidth,$Ypos,$tabWidth,$TabHeight+250)
$Ypos=$Ypos+30
$TabC=GUICtrlCreateTabItem("Construction")
GUICtrlCreateLabel("Select new task for your Automation to perform",$BorderWidth*2,$Ypos)
$Ypos=$Ypos+20
$Combo=GUICtrlCreateCombo("",$BorderWidth*2,$Ypos,$ButtonSize[0]*2,$ButtonSize[1])
$Ypos=$Ypos+$ButtonSize[1]+10
GUICtrlSetData($Combo,"Pause(ms)|Mouse Click|Wait For Pixel|Mouse Move|Mouse Drag")
$YposHold=$Ypos
$Tab2=GUICtrlCreateTabItem("Testing")
GUISetState()

While 1

    $msg = GUIGetMsg()
    $CurrentTaskOld=$CurrentTask
    $CurrentTask=GUICtrlRead($Combo)


    If $CurrentTask<>$CurrentTaskOld then
        $Ypos=$YposHold
        For $i=8 to 20
            GUICtrlDelete($i)
        Next

        Select
        Case $CurrentTask = "" Or $CurrentTask="Dummy"
            ;do nothing
        Case $CurrentTask = "Pause(ms)"
            GUICtrlCreateLabel("Enter the duration you wish Automation program to pause.",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            $Ptime=GUICtrlCreateInput("Duration",$BorderWidth*2,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
        Case $CurrentTask = "Mouse Click"
            HotKeySet("{ENTER}","MousePos")
            GUICtrlCreateLabel("Which button? (1,2,4, etc.)",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            $Cbutton=GUICtrlCreateInput("Button",$BorderWidth*2,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
            GUICtrlCreateLabel("Press ""Enter"" to aquire mouse position.",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            $Clabelxy=GUICtrlCreateLabel("Current saved location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+20
            GUICtrlCreateLabel("# Clicks",$BorderWidth*2,$Ypos)
            GUICtrlCreateLabel("Mouse Speed (0=instant)",$BorderWidth*2+115,$Ypos)
            $Ypos=$Ypos+20
            $Cclick=GUICtrlCreateInput("Clicks",$BorderWidth*2,$Ypos,75)
            $Cspeed=GUICtrlCreateInput("Speed",$BorderWidth*2+115,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
        Case $CurrentTask = "Wait For Pixel"


        Case $CurrentTask = "Mouse Move"

        Case $CurrentTask = "Mouse Drag"

        EndSelect

        $NTbutton=GUICtrlCreateButton("Finish",$BorderWidth*2,$Ypos,$ButtonSize[0],$ButtonSize[1])
        $Ypos=$Ypos+$ButtonSize[1]+5

        $TabPos=ControlGetPos("Automation","",$Tab)
        ;ControlMove("Automation","",$Tab,$TabPos[0],$TabPos[1],$TabPos[2],$Ypos-5)

        ;$WinPos=WinGetPos("Automation")
        ;WinMove("Automation","",$WinPos[0],$WinPos[1],$WinPos[2],$Ypos+$BorderWidth*2)
    EndIf

    Select
    Case $msg=$GUI_EVENT_CLOSE
        end()
    Case $msg=$NTbutton
    ; NewTask()
    EndSelect
WEnd

Func MousePos()
    $CurrentMousePos=MouseGetPos()
    GUICtrlSetData($Clabelxy, "Current saved location: X="&$CurrentMousePos[0]&", Y="&$CurrentMousePos[1])
EndFunc

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

  • Moderators

kindlin,

Could I suggest taking a look at the GUIExtender UDF in my sig? It enables you to open and close different parts of your GUI and sounds like it might help you. :mellow:

As to your questions:

Can I just pass "1" which is the handle of my GUI window, it being the first thing created in my code

Your GUI handle will most certainly not be 1. Controls created by native AutoIt function have a ControlID which is actually an index to an internal array of the controls - GUIs and UDF-created controls have a Handle which is a special numerical ID used by Windows to identify elements of the system. They look like Hex numbers (0x00FF3421) but are actually a special variable. You can use the return value from GUICreate in any AutoIt function that requires a "title" parameter - but do not forget to keep an empty "text" parameter in the list as well. :)

ControlMove and GUICtrlSetPos

As just explained, controls created by the native AutoIt functions return a ControlID and this can be used in the GUICtrl* functions. UDF-created controls and those in external apps are not in AutoIt's internal array and so need the Control* functions as these also identify the GUI concerned.

is there a reason to "Opt('MustDeclareVars', 1)" and then make a bunch of local/global variables declared right off the bat?

1. Keep the number of Global variables to a minimum.

2. Declare any Global variables at the top of the script so all functions know which they are. Do not declare Global variables inside functions - bad coding practice.

3. Declare Local variables within a function as you need them. However, if the variable is used in a conditional structure or loop, it is best to declare them as the function starts - it is too easy to get miss a declaration in the first case, and you waste cycles constantly redeclaring a variable in the second.

You might find the Variables - using Global, Local and ByRef tutorial in the Wiki useful reading. :)

Please ask if anything is still unclear. :)

M23

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

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

@Martin

I thought that's how it worked, I can't remember exactly what went wrong, but I fiddled with the code a couple days ago and the sample code did not help me at all, so I just gave up. Either way, I'll try and integrate it into my code. Your code works tho! Woot! Thanks. Now some clarifying questions:

Can you explain what the "BitOr($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX)" is doing? I know it constructs a new number based on the binary representation of the to inside numbers, but why not just type whatever the number needed is. Also, why have that in the parent section of my GUICreate? It IS the parent, it's the initial window. (I also tried removing it from the code, and I didn't notice anything different) Either way, turning the values of two useful constants into a new number that may r may not mean anything, seems counterproductive. And yes, I know I'm just missing something obvious/basic, but I haven't dealt much with interesting programming, only the basic concepts, but I love to learn new things.

@Melba23

I found/DLed/looked at your examples for GUIExtender. I'm not sure exactly what it does though. Is GUIExtender what causes the 2nd and 4th boxes in your first example to appear/disappear? Is that the entire point of the program? How would I implement that with my current program? Would I create all elements for all options and the GUIExtender would be able to slide the currently selected option into place? I kind of like my coding right now, honestly, though yours might work better, I really don't know. Either way, Martin helped me get this code working, so I'm going to go with it.

I wrote this little code to show you why I thought what I thought;

HotKeySet("{END}","end")

#include <windowsconstants.au3>
#include <GUIConstantsEx.au3>
$Ypos=20

$wuzzup=GUICreate("Hi",150,150)
$b1=GUICtrlCreateButton("B1",25,$Ypos,75,20)
$Ypos=$Ypos+25
$c1=GUICtrlCreateButton("C1",25,$Ypos,75,20)
$Ypos=$Ypos+25
$d1=GUICtrlCreateButton("D1",25,$Ypos,75,20)
$Ypos=$Ypos+25
$e1=GUICtrlCreateButton("E1",25,$Ypos,75,20)
$Ypos=$Ypos+25
$f1=GUICtrlCreateButton("F1",25,$Ypos,75,20)
$Ypos=$Ypos+25
$g1=GUICtrlCreateButton("G1",25,$Ypos,75,20)
$Ypos=$Ypos+25

GUISetState()

MsgBox(4096,"",$wuzzup&" | "&$b1&" | "&$c1&" | "&$d1&" | "&$e1&" | "&$f1&" | "&$g1)

$msg="hi"
while $msg<>$GUI_EVENT_CLOSE 
    $msg = GUIGetMsg()
WEnd

Func end()
    Exit
EndFunc

When ran, each button has the value of 3, 4, 5, 6, 7 and 8. The GUI itself however, has a value of like 0x0000000C437 or something crazy. I just figured the integers would go back to 1 for the main GUI, guess not.

Control* still requires a controlID, says the help file. If you don't know the controlID, as you gave a couple examples where that is true, how would you go about Control*'ing these other elements?

Final question(for now! haha). I tossed GUISwitch right before it creates all of the options-elements and those are now on the construction tab, like I want. However, they don't show up unless I switch to the other tab and go back, tho the window auto adjusts etc. I tried putting GUISetState at the end of my While, and while it now does make the GUI show, it didn't help the elements appear.

-----

Thanks for all the help and understanding. I hope I'm not asking too many/too stupid questions; I do try and find answers on my own, but it's not always easy for me.

Edited by kindlin
Link to comment
Share on other sites

Hope I'm not asking too much, but I have another question before I finish my coding for the day. I'll be back later to check out this thread.

My GUI is coming together nicely, thanks in large part to you guys. But I have a bug that I'm just not understanding. My current code will be placed at the bottom of this post if you want to check it out.

I have 4 options set up right now that involve getting the location of the mouse on the screen. After my function gets the location is updates certain labels with that information so the user can see that it worked. One of my options also requests a color. I have simple code that checks if the $UpdateLabelColor label currently exists. If it does (which is only on the one option) then update it, otherwise skip this step. The problem is that if I mouse over that option (wait for pixel) then it creates the element for a split second before destroying it to create other elements for the other options. This insta create/destroy fumbles my program and causes the ControlGetHandle() to return a handle for the label even tho it doesn't actually exist, I already destroyed it before I ever run that function.

The weird part is, that even tho the result of that handle existing causes the program to update $UpdateLabelColor with the current color, what it actually does it update $UpdateLabelPos and override my actual $UpdateLabelPos with info that should be in $UpdateLabelColor.

Now, I got a workaround for this by simply having the program update $UpdateLabelColor before $UpdateLabelPos so that it reupdates the label with the correct info, but it's still weird, and I'd rather know what caused this incase it happens in the future and I can't just use a simple workaround. Thanks in advance for the help!

EDIT: Oh, and by uncommenting the GUISwitch, right after the While starts, you can see question in my previous post in action.

HotKeySet("{END}","end")

#include <GUIConstantsEx.au3>
#include <windowsconstants.au3>
Opt("guiresizemode",$GUI_DOCKTOP + $GUI_DOCKWIDTH + $GUI_DOCKLEFT + $GUI_DOCKHEIGHT)

$TabWidth=310
$TabHeight=100
$BorderWidth=15
Dim $ButtonSize[2],$Dstart,$Dend,$DstartFinal,$DendFinal
$ButtonSize[0]=75
$ButtonSize[1]=20
$CurrentTask="Dummy"
$LabelHeight=17
Global $Ypos=$BorderWidth, $CurrentMousePos[2]=["N/A", "N/A"], $CurrentMouseColor="N/A", $UpdateLabelPos, $UpdateLabelColor

$Main=GUICreate("Automation",$tabWidth+$BorderWidth*2,$BorderWidth*2+$TabHeight+500)

$Tab=GUICtrlCreateTab($BorderWidth,$Ypos,$tabWidth,$TabHeight)
$Ypos=$Ypos+30
$TabC=GUICtrlCreateTabItem("Construction")
GUICtrlCreateLabel("Select new task for your Automation to perform",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
$Ypos=$Ypos+$LabelHeight
$Combo=GUICtrlCreateCombo("",$BorderWidth*2,$Ypos,$ButtonSize[0]*2,$ButtonSize[1])
$Ypos=$Ypos+$ButtonSize[1]+10
GUICtrlSetData($Combo,"Pause(ms)|Mouse Click|Wait For Pixel|Mouse Move|Mouse Drag")
$YposHold=$Ypos
$Tab2=GUICtrlCreateTabItem("Testing")

GUISetState()

While 1
    
    $msg = GUIGetMsg()
    $CurrentTaskOld=$CurrentTask
    $CurrentTask=GUICtrlRead($Combo)
    
    
    If $CurrentTask<>$CurrentTaskOld then
        ;GUISwitch($Main,$TabC)
        HotKeySet("`")
        $Ypos=$YposHold
        For $i=$Tab2+1 to 20
            GUICtrlDelete($i)
        Next
        
        
        Select
        Case $CurrentTask = "" Or $CurrentTask="Dummy"
            ;do nothing
        Case $CurrentTask = "Pause(ms)"
            GUICtrlCreateLabel("This function halts the program.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("Enter the duration you wish Automation program to pause.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $Ptime=GUICtrlCreateInput("250",$BorderWidth*2,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
        Case $CurrentTask = "Mouse Click"
            HotKeySet("`","MouseInfo")
            GUICtrlCreateLabel("This function simulates a mouse click.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("Which button? (left,right,4,5)",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $Cbutton=GUICtrlCreateInput("left",$BorderWidth*2,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
            GUICtrlCreateLabel("Press ""Tilda"" to aquire mouse position.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $UpdateLabelPos=GUICtrlCreateLabel("Current saved location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("# Clicks",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            GUICtrlCreateLabel("Mouse Speed (0=instant)",$BorderWidth*2+115,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $Cclick=GUICtrlCreateInput("1",$BorderWidth*2,$Ypos,75)
            $Cspeed=GUICtrlCreateInput("0",$BorderWidth*2+115,$Ypos,75)
            $Ypos=$Ypos+$ButtonSize[1]+5
        Case $CurrentTask = "Wait For Pixel"
            HotKeySet("`","MouseInfo")
            GUICtrlCreateLabel("This function halts the program until a specified",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("pixel becomes a specified color.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("Press ""Tilda"" to aquire mouse position.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $UpdateLabelPos=GUICtrlCreateLabel("Current saved location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $UpdateLabelColor=GUICtrlCreateLabel("Current saved color(hex): None",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
        Case $CurrentTask = "Mouse Move"
            HotKeySet("`","MouseInfo")
            GUICtrlCreateLabel("This function simulates mouse movement.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("Press ""Tilda"" to aquire mouse position.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $UpdateLabelPos=GUICtrlCreateLabel("Current saved location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
        Case $CurrentTask = "Mouse Drag"
            HotKeySet("`","MouseInfo")
            GUICtrlCreateLabel("This function simulates dragging the mouse.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            GUICtrlCreateLabel("Press subseqent buttons to finalize 'current' location.",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $Dstart=GUICtrlCreateButton("Start",$BorderWidth*2,$Ypos,$ButtonSize[0],$ButtonSize[1])
            $Dend=GUICtrlCreateButton("End",$BorderWidth*2+$ButtonSize[0]+15,$Ypos,$ButtonSize[0],$ButtonSize[1])
            $Ypos=$Ypos+$ButtonSize[1]+5
            $UpdateLabelPos=GUICtrlCreateLabel("Current saved location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $DstartFinal=GUICtrlCreateLabel("Final start location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
            $DendFinal=GUICtrlCreateLabel("Final end location: X=N/A, Y=N/A",$BorderWidth*2,$Ypos,$TabWidth-$BorderWidth*2)
            $Ypos=$Ypos+$LabelHeight
        EndSelect
        
        $Fbutton=GUICtrlCreateButton("Finish",$BorderWidth*2,$Ypos,$ButtonSize[0],$ButtonSize[1])
        $Ypos=$Ypos+$ButtonSize[1]+5
        
        $TabPos=ControlGetPos($Main,"",$Tab)
        GUICtrlSetPos($Tab,$TabPos[0],$TabPos[1],$TabPos[2],$Ypos)
        
        $WinPos=WinGetPos($Main)
        WinMove($Main,"",$WinPos[0],$WinPos[1],$WinPos[2],$Ypos+$BorderWidth*2+30)
    EndIf
    
    Select
    Case $msg=$GUI_EVENT_CLOSE 
        end()
    Case $msg=$Fbutton
        NewTask()
    Case $msg=$Dstart
        GUICtrlSetData($DstartFinal,"Final start location: X="&$CurrentMousePos[0]&", Y="&$CurrentMousePos[1])
    Case $msg=$Dend
        GUICtrlSetData($DendFinal,"Final end location: X="&$CurrentMousePos[0]&", Y="&$CurrentMousePos[1])
    EndSelect
    
WEnd

Func NewTask()
    ;nothing yet
EndFunc
Link to comment
Share on other sites

  • Moderators

kindlin,

Is GUIExtender what causes the 2nd and 4th boxes in your first example to appear/disappear? Is that the entire point of the program?

Yes - what else did you think it did? :)

Would I create all elements for all options and the GUIExtender would be able to slide the currently selected option into place?

Here is a short example showing how the UDF can do just that: :)

#include <GUIConstantsEx.au3>
#include <GUIExtender.au3>

$hGUI = GUICreate("Test", 500, 420)

_GUIExtender_Init($hGUI)

_GUIExtender_Section_Start(0, 40)

$hCombo = GUICtrlCreateCombo("", 10, 10, 200, 20)
GUICtrlSetData(-1, "None|Section 2|Section 3|Section 4|Section 5")

_GUIExtender_Section_End()

$iIndex2 = _GUIExtender_Section_Start(40, 100)
_GUIExtender_Section_Action($iIndex2)
GUICtrlCreateLabel("Section 2", 10, 50, 480, 80)
GUICtrlSetBkColor(-1, 0xFFCCCC)
_GUIExtender_Section_End()

$iIndex3 = _GUIExtender_Section_Start(140, 50)
_GUIExtender_Section_Action($iIndex3)
GUICtrlCreateLabel("Section 3", 10, 150, 480, 30)
GUICtrlSetBkColor(-1, 0xCCFFCC)
_GUIExtender_Section_End()

$iIndex4 = _GUIExtender_Section_Start(190, 150)
_GUIExtender_Section_Action($iIndex4)
GUICtrlCreateLabel("Section 4", 10, 200, 480, 130)
GUICtrlSetBkColor(-1, 0xCCCCFF)
_GUIExtender_Section_End()

$iIndex5 = _GUIExtender_Section_Start(340, 80)
_GUIExtender_Section_Action($iIndex5)
GUICtrlCreateLabel("Section 5", 10, 350, 480, 60)
GUICtrlSetBkColor(-1, 0xFFFF00)
_GUIExtender_Section_End()

_GUIExtender_Section_Extend(0, False)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $hCombo
            Switch GUICtrlRead($hCombo)
                Case "None"
                    _GUIExtender_Section_Extend(0, False)
                Case "Section 2"
                    _GUIExtender_Section_Extend(0, False)
                    _GUIExtender_Section_Extend(2)
                Case "Section 3"
                    _GUIExtender_Section_Extend(0, False)
                    _GUIExtender_Section_Extend(3)
                Case "Section 4"
                    _GUIExtender_Section_Extend(0, False)
                    _GUIExtender_Section_Extend(4)
                Case "Section 5"
                    _GUIExtender_Section_Extend(0, False)
                    _GUIExtender_Section_Extend(5)
            EndSwitch
    EndSwitch

WEnd

As you can see the various sections only appear when you select them in the combo.

When ran, each button has the value of 3, 4, 5, 6, 7 and 8. The GUI itself however, has a value of like 0x0000000C437 or something crazy. I just figured the integers would go back to 1 for the main GUI, guess not.

Did you read what I posted above? I explained that the controls return ControlIDs while the GUI returns a Handle. :mellow:

Control* still requires a controlID

Different kind of ControlID I am afraid. :)

M23

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

Open spoiler to see my UDFs:

Spoiler

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

 

Link to comment
Share on other sites

@Martin

...

Can you explain what the "BitOr($GUI_SS_DEFAULT_GUI,$WS_SIZEBOX)" is doing? I know it constructs a new number based on the binary representation of the to inside numbers, but why not just type whatever the number needed is. Also, why have that in the parent section of my GUICreate? It IS the parent, it's the initial window. (I also tried removing it from the code, and I didn't notice anything different) Either way, turning the values of two useful constants into a new number that may r may not mean anything, seems counterproductive. And yes, I know I'm just missing something obvious/basic, but I haven't dealt much with interesting programming, only the basic concepts, but I love to learn new things.

...

You can make a window with lots of different characteristics or "styles". Each style has a code. If you want more than one style applied to your window then you must combine the styles and you should only combine with BitOr. The style I used was

"BitOr($GUI_SS_DEFAULT_GUI, $WS_SIZEBOX)"

and this gives the default style and it adds the ability to resize the window by dragging the edges which I thiought was needed to see the effect of the GuiCtrlSetyResizing statements.

There is a good reason you should use BitOr to combine styles. Individual styles have a specific value and are designed so that you could get the required style by adding them up provided you can be sure that each style only consists of one style and there are no duplicates. Some styles are combinations alteady.

Suppose you decided you would like a window with a SIZEBOX style, and you thought it would be good to have a thick border. The if you thought adding the styles was right you would do this

$Style = $WS_POPUPWINDOW + $WS_SIZEBOX + $WS_THICKFRAME

but the style will not be what you want. If you do this however

$style = BitOr( $WS_POPUPWINDOW , $WS_SIZEBOX, $WS_THICKFRAME)

then you will get what you expected. There are many more cases where adding styles gives the wrong result and I think you should always use BitOr.

If instead of writing

$style = BitOr( $WS_POPUPWINDOW , $WS_SIZEBOX, $WS_VSCROLL)

you wrote

$style = 0x80AC0000

then probably no-one, including you, would have a clue what that was supposed to do when you looked at it the next day.

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

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

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