Jump to content

GUI > WinActivate()?


IAMK
 Share

Recommended Posts

Hello,

 

I have a script which uses a GUI with two buttons. It gets shown and hidden., and pressing the buttons (including their hotkeys) highlights the button, making you able to press enter the next time.

However, I don't want that.

 

I've tried using WinActivate() to make enter do things on another program, but the enter is still tied to the AutoIT GUI (which still has the button highlighted).

 

Here's the important part of my code:

$MY_GUI = GUICreate("Check.exe", 400, 300, ((@DesktopWidth / 2) - 200), -500)
WinSetOnTop($MY_GUI, "", 1) ;Keeps the window on the top.
$Button1 = GUICtrlCreateButton("Pass (Ctrl+P)", 40, 250, 120, 40, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$Button2 = GUICtrlCreateButton("Fail (Ctrl+F)", 240, 250, 120, 40, $WS_GROUP)
GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
$GUIText = GUICtrlCreateLabel("", 20, 10, 360, 230)
GUICtrlSetFont(-1, 13, 400, 0, "MS Sans Serif")
GUICtrlSetData($GUIText, Execute($stepMessage[$step]))

   $showGUI = "True"
   GUISetState(@SW_SHOW)

   While($showGUI = "True")
      $buttonPressed = GUIGetMsg()

      Switch $buttonPressed
         Case $Button1 ;Pass
            $pass = "True"

            $buttonPressed = 0

            $showGUI = "False"
            GUISetState(@SW_HIDE)
         Case $Button2 ;Fail
            $buttonPressed = 0

            $showGUI = "False"
            GUISetState(@SW_HIDE)

            While($message = "")
               $message = InputBox("Check.exe", "Please enter the reason the step failed." & @CRLF, "", "", 300, 200, ((@DesktopWidth / 2) - 150), -400)
            WEnd

            Return $message
      EndSwitch
   WEnd
Local $pass = "False" ;Whether "Pass" or "Fail" was pressed.

   Local $failLog = xxxfunc($pass) ;Returns a message to log if the step failed. ##THIS CALLS THE CODE SNIPPET ABOVE##

   FileWrite($file, _Now() & ": Step " & $step & getStatus($pass) & "and took " & Ceiling(TimerDiff($timer) / 1000) & " seconds." & @CRLF)

   If($failLog <> "") Then
      FileWrite($file, "Logged comment: " & $failLog & @CRLF)
   EndIf

   WinActivate("[TITLE:ProgramName]")
;Hotkeys:
HotKeySet("^{p}", "pressPass")
HotKeySet("^{f}", "pressFail")

Func pressPass()
   $buttonPressed = $Button1
EndFunc

Func pressFail()
   $buttonPressed = $Button2
EndFunc

 

The GUI's button/hotkey pressing works correctly.

The same WinActivate code works in another script of mine.

Together, WinActivate is not take "Active" away from the GUI's last-pressed button. How do I fix this?

 

Thank you in advance.

Edited by IAMK
Link to comment
Share on other sites

  • Moderators

@IAMK regarding your report, this is the proper forum for this thread as it deals with a GUI you're creating

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • 2 weeks later...

You could make a check to the functions of the buttons to only work when your GUI is the active window.

Guidelines:

Func XYZfrom button1

If winactive"yourgui" <> 0 Then

Do things in function

EndIf

EndFunc

BTW your code broken in parts like that makes it harder to understand,

but if i understood the problem correctly, this solution should work.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

@careca It has parts of code which I can't share, sorry.

As for that solution, it won't fix the issue. The issue is not about the button being pressed. I'll use notepad as a simple example.

I press ctrl + p to click the pass button on the GUI.

The pass button is now highlighted and the GUI is the active window.

I want notepad to be the active window after pressing ctrl + p, allowing me to simply start typing into notepad.

 

Currently: I need to click on notepad after pressing ctrl + p to type in notepad.

Link to comment
Share on other sites

Maybe try to disable the button, to hide, to force notepad as top window..

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Try setting something else as default "button". Controlsetstate or whatever it is may be able to do that.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

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

×
×
  • Create New...