Jump to content

Recommended Posts

Posted (edited)

I have a situation where I need to occasionally place a button on a GUI, wait for the button to be pressed, and then remove the button.

The placement part works, but the button doesn't appear to be enabled for user action -- and it is not being detected by the _IsPressed loop. Here's a clip of the code I have:

;
;
$tempButton = GUICtrlCreateButton("Special Action", 20, 20, 80, 20)
GUICtrlSetState(-1,$GUI_ENABLE)
GUICtrlSetState(-1,$GUI_FOCUS)
GUISetState ()

$dll = DllOpen("user32.dll")
While 1
    Sleep ( 250 )
    If _IsPressed($tempButton, $dll) Then ExitLoop
WEnd

DllClose($dll)
GUICtrlDelete($tempButton)
;
;

What have I left out? Or am I just using a wrong approach?

Thanks for any help.

Edited by qwert
Posted

try to add after line:

$tempButton = GUICtrlCreateButton("Special Action", 20, 20, 80, 20)

this line:

GUICtrlSetState($tempButton,$GUI_ONTOP)

Working now ? :)

Posted (edited)

_IsPressed() is for keyboard buttons. If you want to detect that the button was pressed, you'll have to set an OnEvent function (if you're using GUIOnEventMode), or you'll have to figure it out using GUIGetMsg().

As for removing the button... if you're going to be constantly creating/deleting the button, you might as well create it once, then hide it using GUICtrlSetState($tempButton, $GUI_HIDE) and unhide it using GUICtrlSetState($tempButton, $GUI_SHOW).

Edited by -Ultima-

[ WinINet.au3 | Array.au3 (Optimized) | _UnixTimeParse() ]

Posted (edited)

Ispressed() Doesn't work for GUI buttons silly :)

Try looking at GUIGetMsg()

EDIT: Beaten to it :(

Edited by Paulie
Posted

Ispressed() Doesn't work for GUI buttons silly :)

Try looking at GUIGetMsg()

EDIT: Beaten to it :(

Oops.

The problem, then, is that I already have an OnEvent function set up for all the normal buttons on this GUI -- and this one isn't defined at the time they are set up.

It sounds like I'll have to define a GUIGetMessage in a separate loop.

Thanks for the help.

  • Moderators
Posted

Oops.

The problem, then, is that I already have an OnEvent function set up for all the normal buttons on this GUI -- and this one isn't defined at the time they are set up.

It sounds like I'll have to define a GUIGetMessage in a separate loop.

Thanks for the help.

That's not going to work because you can't use GUIGetMsg and GUIOnEventMode at the same time.

A suggestion would be to define it when created to the event function you want to use.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Posted (edited)

That's not going to work because you can't use GUIGetMsg and GUIOnEventMode at the same time.

True, of course. I misstated earlier. My script uses GUIGetMsg mode for the main buttons -- so I've just added a second, localized check. The other aspect I didn't explain is that when this temporary button is on the screen, all other buttons need to be deactivated (unclickable). This revised code achieves that:

;
;
$tempButton = GUICtrlCreateButton("Special Action", 20, 20, 80, 20)
GUICtrlSetState(-1,$GUI_ONTOP)
GUICtrlSetState(-1,$GUI_ENABLE)
GUICtrlSetState(-1,$GUI_FOCUS)
GUISetState ()

While 1
     Sleep(50)
     $tempMsg = GUIGetMsg()
     If $tempMsg = $tempButton Then
      ExitLoop
     EndIf
WEnd

GUICtrlDelete($tempButton)
;
;

Thanks for each of your responses.

Edited by qwert
Posted

This revised code achieves that ...

Well, my joy over the achievement was short lived. Yes, everything works -- the temporary button is created, does it's job, and then is deleted -- but afterward, all of the original buttons are disabled. The entire GUI just sits there; nothing works.

I've tried steps like GUISetState(@SW_UNLOCK, $main) and GUISetState(@SW_ENABLE, $main), but nothing has worked.

Any ideas of what to try?

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
×
×
  • Create New...