Jump to content

Embedding IE


Shinies
 Share

Recommended Posts

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
Link to comment
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
Link to comment
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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
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

Link to comment
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

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...