Sign in to follow this  
Followers 0
Shinies

Embedding IE

9 posts in this topic

#1 ·  Posted (edited)

I haven't got any replies so i figured my question was either not worded well or i didn't give an example that you guys could use. So here is the example: cannot backspace in the edit after having clicked in the embedded IE control. How do i either avoid this or take measures to correct for this?

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>


;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = _GUICtrlEdit_Create($WinMain, "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)

_IENavigate($oMainIE, "about:blank")

;Perform starup operations
GUISetState(@SW_SHOW)

While 1

$mMsg = GUIGetMsg()
Switch $mMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch

WEnd
Edited by Smerk

Share this post


Link to post
Share on other sites



First, please include functional code.. I had to figure out what includes to use..

Second, I found that it is same behavior with _GUICtrlRichEdit_Create

Third, If you use GUICtrlCreateEdit, you can backspace, but you lose your cursor () which is something I am waiting to hear back on.

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = GUICtrlCreateEdit( "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)
_IENavigate($oMainIE, "about:blank")
;Perform starup operations
GUISetState(@SW_SHOW)
While 1
$mMsg = GUIGetMsg()
Switch $mMsg
Case -3
Exit
EndSwitch
WEnd

Share this post


Link to post
Share on other sites

First, please include functional code.. I had to figure out what includes to use..

Second, I found that it is same behavior with _GUICtrlRichEdit_Create

Third, If you use GUICtrlCreateEdit, you can backspace, but you lose your cursor () which is something I am waiting to hear back on.

That's pretty odd. I have no clue why i lost the includes when i pasted the code in, i actually had no clue what you were talking about until i double checked. Sorry about that, and thank you for the reply.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Try this, I borrow this _GUICtrlEdit_SetPos function from Yashied --

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#Include <ScrollBarConstants.au3>
;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = _GUICtrlEdit_Create($winmain, "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)
$backspace = GUICtrlCreateDummy()
Dim $AccelKeys[1][2] = [["{BACKSPACE}", $backspace]]
GUISetAccelerators($AccelKeys,$winmain)
_IENavigate($oMainIE, "about:blank")
;Perform starup operations
GUISetState(@SW_SHOW)
While 1
$mMsg = GUIGetMsg()
Switch $mMsg
Case $backspace
$out = _GUICtrlEdit_GetText($MainMsgBoardInput)
_GUICtrlEdit_SetText($MainMsgBoardInput,StringTrimRight($out,1))
_GUICtrlEdit_SetPos($MainMsgBoardInput, -1, -1)
Case -3
Exit
EndSwitch
WEnd
;http://www.autoitscript.com/forum/topic/124099-howto-get-cursor-position-in-multiline-edit/
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlEdit_SetPos
; Description....: Sets the caret to the specified line and column.
; Syntax.........: _GUICtrlEdit_SetPos ( $hWnd, $iLine [, $iColumn] )
; Parameters.....: $hWnd - Handle or identifier (controlID) to the control.
;                $iLine - The zero-based index of the line on which must set the caret. If this parameter is (-1),
;                            the caret will be set on the last line.
;                $iColumn - The zero-based index of the column on which must set the caret. If this parameter is (-1),
;                            the caret will be set at the end of the specified line. Default is 0.
; Return values..: Success - 1.
;                Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........: _GUICtrlEdit_Scroll(), _GUICtrlEdit_SetSel()
; Link...........: None
; Example........: Yes
; ===============================================================================================================================
Func _GUICtrlEdit_SetPos($hWnd, $iLine, $iColumn = 0)
If Not IsHWnd($hWnd) Then
     $hWnd = GUICtrlGetHandle($hWnd)
     If $hWnd = 0 Then
         Return SetError(1, 0, 0)
     EndIf
EndIf
Local $Lenght, $Num = 0, $Count = _GUICtrlEdit_GetLineCount($hWnd)
If $iLine > $Count - 1 Then
     $Num = _GUICtrlEdit_GetTextLen($hWnd)
Else
     If $iLine < 0 Then
         $iLine = $Count - 1
     EndIf
     For $i = 0 To $iLine - 1
         $Num += _GUICtrlEdit_LineLength($hWnd, $i) + 2 ; + @CR + @LF
     Next
     $Lenght = _GUICtrlEdit_LineLength($hWnd, $iLine)
     If ($iColumn < 0) Or ($iColumn > $Lenght) Then
         $iColumn = $Lenght
     EndIf
     $Num += $iColumn
EndIf
_GUICtrlEdit_SetSel($hWnd, $Num, $Num)
_GUICtrlEdit_Scroll($hWnd, $SB_SCROLLCARET)
Return 1
EndFunc ;==>_GUICtrlEdit_SetPos
Edited by step887

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Good thinking mate! However in that script pressing backspace would delete content from the edit control no matter where the input was focused. Ive made a slight change so that it only deletes from the control if the control is selected, otherwise it will not.

There are quite possibly some other issue that will continue to arise from the embedded IE, so it may be more simple to use the native edit control rather than the UDF version.

Heres the code for anyone else who might run into this problem though:

EIDT: Cut off my damn includes again, lol! Whats up with that...

;==========================================================================================
#include <ie.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>
#Include <ScrollBarConstants.au3>
#include <WinAPI.au3>
;Mainwindow
$WinMain = GUICreate("hello", 510, 510)
$MainMsgBoardInput = _GUICtrlEdit_Create($winmain, "", 1, 439, 498, 50, BitOR($ES_MULTILINE, $ES_WANTRETURN, $WS_VSCROLL, $ES_AUTOVSCROLL))
$oMainIE = _IECreateEmbedded()
GUICtrlCreateObj($oMainIE, 1, 1, 498, 435)
$backspace = GUICtrlCreateDummy()
Dim $AccelKeys[1][2] = [["{BACKSPACE}", $backspace]]
GUISetAccelerators($AccelKeys,$winmain)
_IENavigate($oMainIE, "about:blank")
;Perform starup operations
GUISetState(@SW_SHOW)
While 1
$mMsg = GUIGetMsg()
Switch $mMsg

Case $backspace
If _WinAPI_GetFocus() = $MainMsgBoardInput Then
$out = _GUICtrlEdit_GetText($MainMsgBoardInput)
_GUICtrlEdit_SetText($MainMsgBoardInput,StringTrimRight($out,1))
_GUICtrlEdit_SetPos($MainMsgBoardInput, -1, -1)
EndIf

Case -3
Exit
EndSwitch
WEnd
;http://www.autoitscript.com/forum/topic/124099-howto-get-cursor-position-in-multiline-edit/
; #FUNCTION# ====================================================================================================================
; Name...........: _GUICtrlEdit_SetPos
; Description....: Sets the caret to the specified line and column.
; Syntax.........: _GUICtrlEdit_SetPos ( $hWnd, $iLine [, $iColumn] )
; Parameters.....: $hWnd - Handle or identifier (controlID) to the control.
; $iLine - The zero-based index of the line on which must set the caret. If this parameter is (-1),
; the caret will be set on the last line.
; $iColumn - The zero-based index of the column on which must set the caret. If this parameter is (-1),
; the caret will be set at the end of the specified line. Default is 0.
; Return values..: Success - 1.
; Failure - 0 and sets the @error flag to non-zero.
; Author.........: Yashied
; Modified.......:
; Remarks........: None
; Related........: _GUICtrlEdit_Scroll(), _GUICtrlEdit_SetSel()
; Link...........: None
; Example........: Yes
; ===============================================================================================================================
Func _GUICtrlEdit_SetPos($hWnd, $iLine, $iColumn = 0)
If Not IsHWnd($hWnd) Then
$hWnd = GUICtrlGetHandle($hWnd)
If $hWnd = 0 Then
Return SetError(1, 0, 0)
EndIf
EndIf
Local $Lenght, $Num = 0, $Count = _GUICtrlEdit_GetLineCount($hWnd)
If $iLine > $Count - 1 Then
$Num = _GUICtrlEdit_GetTextLen($hWnd)
Else
If $iLine < 0 Then
$iLine = $Count - 1
EndIf
For $i = 0 To $iLine - 1
$Num += _GUICtrlEdit_LineLength($hWnd, $i) + 2 ; + @CR + @LF
Next
$Lenght = _GUICtrlEdit_LineLength($hWnd, $iLine)
If ($iColumn < 0) Or ($iColumn > $Lenght) Then
$iColumn = $Lenght
EndIf
$Num += $iColumn
EndIf
_GUICtrlEdit_SetSel($hWnd, $Num, $Num)
_GUICtrlEdit_Scroll($hWnd, $SB_SCROLLCARET)
Return 1
EndFunc ;==>_GUICtrlEdit_SetPos
Edited by Smerk

Share this post


Link to post
Share on other sites

See my sig for an alternative to embedded IE created by another user. It works well.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Dale from some of my previous testing before posting, using that UDF caused the embedded window to lose visibility when another child window is placed over it. Did not find out how to get around that problem.

Share this post


Link to post
Share on other sites

There are long-standing issues with GUIControlCreateObject and keyboard events and visibility. If the suggested workaround doesn't work for you, I'd suggest looking through the Trac tickets and opening a new one if your issue is not called out.

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

Understood, thank you for the help Dale :)

Share this post


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
Sign in to follow this  
Followers 0

  • Similar Content

    • oceanwind
      By oceanwind
      Hi All:
       How to set the input border color?
      tks in advance
    • nassausky
      By nassausky
      Hi all,
       
      Anyone have any idea how to close all open tabs except a specific one I manually open.  Assuming I don't know what is open in all the tabs except just the one I want to keep open.
       
      I didn't want to use sendkeys and I was trying to use the following code to list the title (or url) of the 3 open tabs and  after I got that part working I would just close the other 2. This sample only displays the title of the first open tab
      #include <IE.au3> Const $ie_new_in_tab = 0x0800 $oIE = _IECreate("https://www.autoitscript.com") __IENavigate($oIE, "https://www.autoitscript.com/forum/", 1, $ie_new_in_tab) ;(obj,url,wait,param) __IENavigate($oIE, "https://www.google.com/", 1, $ie_new_in_tab) ;(obj,url,wait,param) Local $aIE[1] $aIE[0] = 0 Local $i = 1, $oIE While 1     $oIE = _IEAttach("", "instance", $i)     If @error = $_IEStatus_NoMatch Then ExitLoop     ConsoleWrite(_IEPropertyGet($oIE, "title") & @CRLF)     ReDim $aIE[$i + 1]     $aIE[$i] = $oIE ;each item holds object     $aIE[0] = $i ;first item holds count     $i += 1 WEnd MsgBox($MB_SYSTEMMODAL, "Browsers Found", "Number of browser instances in the array: " & $aIE[0]) ; This doesn't return the list of tabs in the console just the first tab  
      Thanks for any and all help
    • Shirdish_chakravarthi
      By Shirdish_chakravarthi
      Hello Guys this is my gui and i need the numeric value typed in the highlighted  inputbox. if this value is greater than 1 i need to perform some operations
      \
       
      Here is the summary about that field which i got from wininfo tool

      i tried writing the code as shown below.. but the msgbox is popping up empty value..when the same code is pasted under some button action i am able to access the value present in the field..but when placed alone as written in the attached script i am unable to fetch it... 

      here i am using the valu present in the field

      can you guys tell me what's wrong??? or how can i get that value?
       
      My_GUI.au3

    • toto22
      By toto22
      I'm trying to click on Java Dropbox using IE. However, I'm running into problems. There is a Dropbox "Please Select" with two options "Buy" and "Sell".
      I'm able to click on a drop box (please see code below) but i'm unable to select "Buy" or "Sell"".
      Local $sMyString = "Please Select" ;############ ENTER ############# Local $oLinks = _IELinkGetCollection($oIE) For $oLink In $oLinks Local $sLinkText = _IEPropertyGet($oLink, "innerText") If StringInStr($sLinkText, $sMyString) Then _IEAction($oLink, "click") ExitLoop EndIf Next  
      Please help
       
         
    • Gowrisankar
      By Gowrisankar
      Hello everyone,
      I'm working on a task where, a PDF file is opened (in IE browser) when I click a link in a website.
      I have to read the first page of the PDF to find particular strings. Can you please share some ideas?