Jump to content

Closing the window with _IECreateEmbedded() content

Recommended Posts

I use a simple script (below) to display a webpage that takes a selected text as a parameter, when the "^q" keystroke is pressed. Unfortunately, when an user open 3 windows using he script below, Autoit hangs. That's ok, I tried to keep only one window open, closing the previously opened window. But it turned out that always the newly opened window is closed, despite using the handle to the previous window, as confirmed by the console output ... Is there any error in the script?


#include <GUIConstantsEx.au3>
#include <IE.au3>
#include <WindowsConstants.au3>
#include <StringConstants.au3>

;Local $old_clipboard
HotKeySet ("^q", "gettext")

While 1

Func gettext ()
Local Static $another_handle

 $old_clipboard = ClipGet ()
 Send ("^c")
 $current_clipboard = ClipGet ()

 $width = 460
 $height = 580

 ConsoleWrite( $another_handle & @CRLF )
 If $another_handle <> 0 Then

Local $oIE = _IECreateEmbedded()

$another_handle = GUICreate("example", $width, $height, _
    (@DesktopWidth - $width) / 2, (@DesktopHeight - $height) / 2, _
 ConsoleWrite( $another_handle & @CRLF )

GUICtrlCreateObj($oIE, 0, 0, $width, $height)
GUICtrlSetColor(-1, 0xff0000)

GUISetState(@SW_SHOW) ;Show GUI
_IENavigate($oIE, StringFormat("https://duckduckgo.com/?q=%s", StringStripWS(ClipGet (), $STR_STRIPLEADING + $STR_STRIPTRAILING)))
ClipPut ($old_clipboard)
_IEAction($oIE, "stop")

; Waiting for user to close the window
While 1
    Local $iMsg = GUIGetMsg()
    Case $iMsg = $GUI_EVENT_CLOSE



Func CheckError($sMsg, $iError, $iExtended)
    If $iError Then
        $sMsg = "Error using " & $sMsg & " button (" & $iExtended & ")"
        $sMsg = ""
    GUICtrlSetData($g_idError_Message, $sMsg)
EndFunc   ;==>CheckError


Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...