Jump to content

Need conformation on possible bug - NO LONGER NEEDED


Recommended Posts

I have a script I made a few weeks ago to work with a context menu. When I select SFDC, the script will exit. Any other choice works fine. Why would Send("{ESC}") cause the script to close? I think I know the cause. Researching now. Thanks for the help everyone!

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_icon=..\icons\Diary.ico
#AutoIt3Wrapper_outfile=Context.exe
#AutoIt3Wrapper_UseUpx=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
;Opt("TrayIconHide", 1) ;testing
Opt("MouseCoordMode", 0)
#include <Misc.au3>
#include <GUIConstants.au3>
#include <WindowsConstants.au3>
DIM $ww2, $ww
HotKeySet("+!d", "Terminate")
$dll = DllOpen("user32.dll")
$Form1  = GUICreate("", 100, 22, 193, 80, BitOR($WS_POPUP, $WS_EX_MDICHILD,$WS_EX_TOOLWINDOW))
$List_1 = GUICtrlCreateCombo("", 0, 0, 100, 22)
GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE|SFDC","")
WinSetOnTop($Form1, "", 1)
GUISetState(@SW_Hide)

While 1
    $Msg = GUIGetMsg(0)
    select
        Case _IsPressed("02", $dll) and _IsPressed("11", $dll)
            Context()
            while 2
                $Msg2 = GUIGetMsg(0)
                Select 
                    Case $Msg2 = $GUI_EVENT_CLOSE
                        Exit
                    Case _IsPressed("01", $dll) and WinActive($Form1) = 0
                        GUISetState(@SW_Hide)
                        exitloop                        
                    Case $Msg2 = $List_1
                    $G = GUICtrlRead($List_1)
                    If $G = "Notepad" then 
                        GUISetState(@SW_HIDE)
                        Run("Notepad.exe")
                        ExitLoop
                    endif
                    If $G = "Calculator" then 
                        GUISetState(@SW_HIDE)
                        Run("Calc.exe")
                        ExitLoop
                    endif
                    If $G = "Word" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Microsoft Office\OFFICE11\WINWORD.EXE")
                        ExitLoop
                    endif   
                    If $G = "FireFox" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\Mozilla Firefox\firefox.exe")
                        ExitLoop
                    endif   
                    If $G = "SciTE" then 
                        GUISetState(@SW_HIDE)
                        Run("C:\Program Files\AutoIt3\SciTE\SciTE.exe")
                        ExitLoop
                    endif   
                    If $G = "SFDC" then 
                        GUISetState(@SW_HIDE)
                        if WinActive($ww, $ww2) = 0 then WinActivate($ww, $ww2)
                        sleep(300)
                        send("{ESC}") ;This is causing the script to close. Not sure why. 
                        ;changed hotsetkey. Made no difference.
                        ExitLoop ;remarking this out made no difference. 
                    endif
                EndSelect   
            WEnd
        Case $Msg = $GUI_EVENT_CLOSE
            Exit            
    EndSelect
WEnd

Func Terminate()
    Exit 0
EndFunc   ;==>Terminate

Func Context()
    $m = MouseGetPos()
    WinMove($Form1, "", $m[0], $m[1]-22)
    GUICtrlSetData($List_1, "","")
    GUICtrlSetData($List_1, "Notepad|Calculator|Word|FireFox|SciTE|SFDC","")
    $ww2 = WinGetText("[active]")
    $ww = WinGetTitle("[active]")
    GUISetState(@SW_SHOW,$Form1)
EndFunc   ;==>Context
Edited by Volly
Link to comment
Share on other sites

I tried this:

GUISetState(@SW_HIDE)
                            sleep(100)
                            if WinActive($ww, $ww2) = 0 then WinActivate($ww, $ww2)
                            sleep(300)
                            send("dog");THis is causing the script to close. Not sure why. 
                    ;changed hotsetkey. Made no difference.
                                $wwQ = WinGetTitle("[active]")  
                                $wwQ2 = WinGetText("[active]")
                            MsgBox(0, $wwQ, $wwQ2, 1)
                            ExitLoop;remarking this out made no difference. 
                        endif

What is odd is MsgBox(0, $wwQ, $wwQ2,1) is reporting nothing. I can wait for the msgbox to close, then no window is active. If I press the esc key, the script closes. Very odd.

Edited by Volly
Link to comment
Share on other sites

Your own window is still active when you send the ESC key. Because WinActivate does not wait until the window is active. It just tells Windows to make the window active.

Possible solution is to wait for the window to become active:

If $G = "SFDC" then 
                        GUISetState(@SW_HIDE)
                        if WinActive($ww, $ww2) = 0 then WinActivate($ww, $ww2)
                        WinWaitActive($ww, $ww2)
                        send("{ESC}") ;This is causing the script to close. Not sure why. 
                        ;changed hotsetkey. Made no difference.
                        ExitLoop ;remarking this out made no difference. 
                    endif

Or as an alternative you may stop your GUI from closing if the ESC key is sent to it by using this option:

Opt("GUICloseOnEsc", 0)

but that will not fix your problem. Only the symptoms.

Can't explain your second symptons though.

Edit: Grammar. :P

Edited by Manadar
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...