Jump to content

returning correct values?


Recommended Posts

#include <GUIConstants.au3>
   GuiCreate( "mygui", 400, 300)
   GUICreateEx( -1,)
   GuiShow()

$n1=GUISetControl("checkbox", "DIGI01", 5, 5, 100,20)
GUISetControlNotify()

$n2=GUISetControl("button", "end",0,100)
GUISetControlEx(-1,$GUI_FOCUS)           

GUIWaitClose()      
msgbox(0,"Value=", GUIRead() & " " & $n1 & " " & $n2 )

The above code appears to always return the values 4 3 4

unless I close from the close button and then I get -3 3 4

however it doesn't change if I alter the check box.. so how do I get the correct return value? I was expecting something like 0 and 1 or -1 and 1 or something..

moo

Link to comment
Share on other sites

The checkbox isn't generating a GUI close event, so it will never appear in your message box. The only 2 events you have that could close the GUI would be the red button (-3) or the button control you have, which is why the first and last number always match in your message box. If you need to handle the checkbox as a seperate event, you should use a While...EndWhile segment and test for a change in state with GuiMsg(0).

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

I've been having similar issues, but I'm don't think AutoIt is at fault. In addition to some AutoIt message boxes, I have had problems with a few installers moving behind my explorer window despite the fact that I never clicked the explorer window. Isn't micro$oft just great? :D .

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

have not run any recent updates for a couple of months.. hmmm..

Shouldn't Winactivate work though? I even checked with the window spy to be sure I had the right text. I don't get it.. I put it right at the end of the script too.

also.. in my initial test of the GUI with While wend.. it only displayed the one check box.. not the other buttons. I'll play a bit more but a hint from you more experienced fellows would be much apreciated :D (but it does work by returning the values to me when it closes)

moo

Edited by cowsmanaut
Link to comment
Share on other sites

How about a simple example? This has two controls: a checkbox with a notify, and a button. The button will exit, and the checkbox will show a splash screen for 1 second when you toggle the box.

GuiCreate("Example", 200, 200)
  $checkbox = GuiSetControl("checkbox", "Checkbox", 0, 0, 100, 20)
    GuiSetControlNotify()
  $button = GuiSetControl("button", "Exit example", 0, 100, 100, 20)
GuiShow()

While 1
  $msg = GuiMsg(0)
  If $msg = -3 OR $msg = $button Then Exit
  If $msg = $checkbox Then
    SplashTextOn("Checkbox toggled", "You have togled the checkbox!")
    Sleep(1000)
    SplashOff()
  EndIf
WEnd

[font="Optima"]"Standing in the rain, twisted and insane, we are holding onto nothing.Feeling every breath, holding no regrets, we're still looking out for something."[/font]Note: my projects are off-line until I can spend more time to make them compatable with syntax changes.

Link to comment
Share on other sites

One note about the "Foreground Problem".

I can confirm the experience of cowsmanaut. In some cases an au3 script with GUI or even a compiled au3 exe starts behind an already opened aktiv window!

Give it a try in XP home or professional. Take any of your .au3 with GUI and put it on your Desktop. It works also when you even put a link on the Desktop. Open a window before (explorer or anything else). Then start the au3 from the desktop. It will start behind the aktiv window and don't become aktiv. I tried it on home and professional. Works also when I put a link to the startmenu. When you put it in a directory on desktop, all is ok.

I have to mention that I am working with the german XP version.

I recognized a similarly problem in the past:

I did a script for network notification and started notepad from a batch script.

On some XP machines it started minimized, on some others normal.

I have no idea about these weird things.

arctor

Link to comment
Share on other sites

Hmmm...maybe there should be added:

SetForegroundWindow(m_hWndGUI);

in the Show()-function of the GUI-section after the line

ShowWindow(m_hWndGUI, SW_SHOW);

I tested it and it works...hmmm...maybe there's another solution...

Don't know what Jon thinks about it...

:D

EDIT: I changed the lines in the GUI-Show()-function to this:

// we need to show the GUI
SetForegroundWindow(m_hWndGUI);
ShowWindow(m_hWndGUI, SW_SHOW);

And it works now :huh2:

The focus goes to the window and what is also important: the Task in the Taskbar is activated :)

Edited by Holger
Link to comment
Share on other sites

ok so now that I've gotten a better idea about this.. is there a better way of doing what I'm doing.. cleaner.. shorter? I pretty much wasn to know if they are on or off so that I can read in other information or not.

For example if the load file check is on.. it will look to see what files has been selected. if the send message check is on then it will read from a dialogue box the typed message and send it.

so far I'm just having it say if it's on or off..

moo

GuiCreate("Example", 200, 200)
Opt("GuiNotifyMode",1)
 $checkbox = GuiSetControl("checkbox", "Checkbox", 0, 0, 100, 20)
 $checkboxb = GuiSetControl("checkbox", "Checkbox", 0, 20, 100, 20)
  

 $button = GuiSetControl("button", "Exit example", 0, 100, 100, 20)
GuiShow()

$A = -1
$B = -1

While 1
 $msg = GuiMsg(0)
 If $msg = -3 OR $msg = $button Then Exit

 If $msg = $checkbox Then
    $A=$A*"-1"

    if $A = -1 then
   SplashTextOn("Checkbox toggled", "You have turned off checkbox a!")
   Sleep(1000)
   SplashOff()
    elseif $A = 1 then
   SplashTextOn("Checkbox toggled", "You have turned on checkbox a!")
   Sleep(1000)
   SplashOff()
    endif

 elseIf $msg = $checkboxb Then
    $B=$B*"-1"

    if $B = -1 then
   SplashTextOn("Checkbox toggled", "You have turned off checkbox b!")
   Sleep(1000)
   SplashOff()
    elseif $B = 1 then
   SplashTextOn("Checkbox toggled", "You have turned on checkbox b!")
   Sleep(1000)
   SplashOff()
    endif
 EndIf
WEnd

thanks :D

Link to comment
Share on other sites

ok so now that I've gotten a better idea about this.. is there a better way of doing what I'm doing.. cleaner.. shorter?...

You can do a GuiRead on a checkbox to get the state.

If $msg = $checkbox Then
$var = GuiRead($checkbox)
...
EndIf

$var has now the value 1 or 4 (checked or unchecked)

See GuiRead in the Helpfile. And then See State table.

Instead of the many IF THEN you can do a SELECT...CASE...ENDSELECT to ask which control sent a notify.

Select
Case $msg = $checkbox
...
Case $msg = $checkboxb
...
EndSelect

arctor

Link to comment
Share on other sites

ShowWindow(m_hWndGUI, SW_SHOW);

I tested it and it works...hmmm...maybe there's another solution...

I never seen that. I know the @SW_SHOW with WinSetState.

Here is another solution for the "start behind another window" problem:

GuiShow
sleep(10)
WinActivate("Title of the own Window)
When I don't put a short sleep in, it sometimes nevertheless starts "behind". Surely the reason is: My machine is much to fast. :D

The disadvantage with an additional WinActivate() is: It's slow. The Gui shows up, and only after a short time you can see the controls. Even without a sleep().

Can there be a macro for the own Win Title like selfwin or something? Didn't find one in the helpfile.

arctor

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