Jump to content

Embedded IE - javascript problem


Go to solution Solved by mpower,

Recommended Posts

Hey lovely forum dwellers,

I'm having a problem with the use of javascript (jquery + plugins) in an embedded IE control.

I've created a GUI which has an embedded IE control and Im having a problem when trying to re-arrange table rows via drag&drop. When I click an item and drag it, it appears to highlight any text when I move the mouse around. Also it tends to not work properly - items are just placed at the top of the table rather than where they are dropped. Works fine in regular IE (non-embedded).

T0bGDB0.png

 

I've attached the example script along with the html file and javascript file and png gui elements. 

The script code is here also:

#include-once
#NoTrayIcon
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_UseUpx=n
#AutoIt3Wrapper_UseX64=n
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <GUIConstants.au3>
#include <WinAPIEx.au3>
#include <IE.au3>
#include <Array.au3>
#include <File.au3>
#include <Misc.au3>

Global $appname = 'Example App', $appver = '1.0', $bAero, $hidden = False, $tuck = False, $tucked = False, $untucked = False, $tucking = False, $untucking = False, $timer = 0, $tdiff = 0, _
$LAYERED_GUI = $WS_EX_LAYERED, $hGUI_child, $hGUI_height = 683, $hGUI_width = 715, $find = False, $qsInfocus = False, $hovercustlbl = False, $hoverexitlbl = False, $oRange, _
$appresourcesdir = @ScriptDir, $alreadyrunningui_W = 420, $alreadyrunningui_H = 160, $criticalupdate, $qsInput, $custLabel, $hoveraddlbl, $addLabel, $oIE
Global Const $hDwmApiDll = DllOpen("dwmapi.dll"), $sChkAero = DllStructCreate("int;")
DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "ptr", DllStructGetPtr($sChkAero))
$bAero = DllStructGetData($sChkAero, 1)
If Not $bAero Then
    $LAYERED_GUI = 0
    $hGUI_height = $hGUI_height - 20
    $hGUI_width = $hGUI_width - 60
EndIf

$hGUI = GUICreate("", $hGUI_width, $hGUI_height, -1, 0, $WS_POPUP, $LAYERED_GUI + $WS_EX_TOPMOST, WinGetHandle(AutoItWinGetTitle()))
$hIcon = _WinAPI_GetClassLongEx($hGUI, $GCL_HICON)
_WinAPI_DestroyIcon($hIcon)
_WinAPI_SetClassLongEx($hGUI, $GCL_HICON, 0)
_WinAPI_SetClassLongEx($hGUI, $GCL_HICONSM, 0)
$DPIratio = _GDIPlus_GraphicsGetDPIRatio()[0]

If $bAero Then
    $hGUI_child = GUICreate("", $hGUI_width-39, 683 - 26, 22,  3, $WS_POPUP, $WS_EX_MDICHILD + $WS_EX_TOPMOST, $hGUI)
    $hGUI_Font = $hGUI_child
Else
    $hGUI_Font = $hGUI
    $hGUI_child = $hGUI
EndIf

GUISetBkColor(0xFFFFFF)
GUISetFont(18 * $DPIratio, 100, Default, 'Segoe UI', $hGUI_Font, 5)
$exitLabel = GUICtrlCreateLabel('Exit', 575, 25)
GUICtrlSetCursor(-1, 0)
If FileExists(@ScriptDir & '/example.html') And FileExists(@ScriptDir & '/jquery_sortable.js') Then
    $custLabel = GUICtrlCreateLabel('Customise', 440, 25)
    GUICtrlSetCursor(-1, 0)
    $qsLabel = GUICtrlCreateLabel('Quick find:', 10, 25)
    $qsInput = GUICtrlCreateInput('', 150, 20, 100, 35)
    $oIE = _IECreateEmbedded()
    $oIEobj = GUICtrlCreateObj($oIE, 10, 85, 650, 550)
    $oNav = _IENavigate($oIE, @ScriptDir & '/example.html', 0)
    $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")
    $oDocEvents = ObjEvent($oIE.document, "Event_", "HTMLDocumentEvents2")
    #forceref $oDocEvents
Else
    MsgBox(0, 'Error', 'Please place html and js files in Script directory:'&@CRLF&@ScriptDir)
EndIf
$hENTER = GUICtrlCreateDummy()
Dim $AccelKeys[1][2]=[["{ENTER}", $hENTER]]
GUISetAccelerators($AccelKeys)

$hGUI_child2 = GUICreate("", 112, 50, 280, 645, $WS_POPUP, $LAYERED_GUI + $WS_EX_MDICHILD + $WS_EX_TOPMOST, $hGUI_child)
If Not $bAero Then
    $apos = WinGetPos($hGUI_child2)
    WinMove($hGUI_child2, '', $apos[0] - 15, Default)
    GUISetBkColor(0xE0F2F7)
    $hGUI_Font = $hGUI_child2
    GUISetFont(33 * $DPIratio, 100, Default, 'Segoe UI', $hGUI_Font, 5)
    GUICtrlCreateLabel(" = ", 0, 0, 112, 50, $SS_CENTER + $SS_CENTERIMAGE)
EndIf
GUISetCursor(0, 1, $hGUI_child2)

If $bAero Then
    _GDIPlus_Startup()
    $hImage = _GDIPlus_ImageLoadFromFile($appresourcesdir & '/panel.png')
    SetBitmap($hGUI, $hImage)
    $hImage = _GDIPlus_ImageLoadFromFile($appresourcesdir & '/roundbn.png')
    SetBitmap($hGUI_child2, $hImage)
    _GDIPlus_Shutdown()
EndIf

#Region ### $alreadyrunningui ###
$alreadyrunningui = GUICreate($appname & ' ' & $appver, $alreadyrunningui_W, $alreadyrunningui_H, @DesktopWidth/2 - $alreadyrunningui_W/2, @DesktopHeight/2 - $alreadyrunningui_H/2)
GUISetBkColor(0xFFFFFF, $alreadyrunningui)
GUICtrlCreateLabel('Sorry, ' & $appname & ' ' & $appver & ' appears to be running already.' & @CRLF & _
                              @CRLF & 'Please close the existing instance before trying again, thanks.', 10, 45, $alreadyrunningui_W - 20, 63, $SS_CENTER)
GUICtrlSetFont(-1, 11, 400, -1)
$alreadyrunning_okay = GUICtrlCreateButton('Ok', (($alreadyrunningui_W/2) - (100/2)), 120, 100)
#EndRegion ### $alreadyrunningui ###

#Region ### Single Instance Check ###
If _Singleton("example", 1) = 0 Then
    GUISetState(@SW_SHOW, $alreadyrunningui)
Else
    StartMain()
EndIf
#EndRegion ### Single Instance Check###

While 1
    $mPos = MouseGetPos()
    If BitAnd($hidden, $mPos[1] = 0, $timer = 0) Then
        $timer = TimerInit()
        Sleep(10)
    ElseIf $mPos[1] <> 0 Then
        $timer = 0
        $tdiff = 0
    EndIf
    If $timer <> 0 Then $tdiff = TimerDiff($timer)
    If BitAND($hidden, Not $tucked, $mPos[1] <> 0, Not $tucking) Then
        $tuck = True
        $untucking = False
        $tucking = True
        AdlibRegister("TuckAway", 2500)
    ElseIf BitAND($hidden, $tucked, $mPos[1] = 0, Not $untucking, $tdiff > 450) Then
        $tuck = False
        $tucking = False
        $untucking = True
        AdlibRegister("TuckAway")
    ElseIf BitAND($hidden, Not $tucked, $mPos[1] = 0, $tucking) Then
        AdlibUnRegister("TuckAway")
        $tuck = False
        $tucking = False
    EndIf
    $msg = GUIGetMsg(1)
    Switch $msg[1]
        Case $alreadyrunningui
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE, $alreadyrunning_okay
                    Exit
            EndSwitch
        Case $hGUI_child
            Switch $msg[0]
                Case $GUI_EVENT_CLOSE, $exitLabel
                    Exit
                Case $hENTER
                    If $qsInfocus Then _IESearchText($oIE, GUICtrlRead($qsInput), 1)
                Case $custLabel
                    MsgBox(64, $appname & ' ' & $appver, 'Feature will be added in future release.', 0, $hGUI_child)
            EndSwitch
        Case $hGUI_child2
            Switch $msg[0]
                Case $GUI_EVENT_PRIMARYUP
                    If Not $hidden Then
                        HidePanel()
                    Else
                        HidePanel(False)
                    EndIf
            EndSwitch
    EndSwitch
    $mouse = GUIGetCursorInfo($hGUI_child)
    If BitAnd($mouse[4] = $custLabel, Not $hovercustlbl) Then
        $hovercustlbl = True
        GUICtrlSetFont($custLabel, 18 * $DPIratio, Default, 4)
    ElseIf BitAnd($mouse[4] <> $custLabel, $hovercustlbl) Then
        $hovercustlbl = False
        GUICtrlSetFont($custLabel, 18 * $DPIratio, Default, Default)
    ElseIf BitAnd($mouse[4] = $exitLabel, Not $hoverexitlbl) Then
        $hoverexitlbl = True
        GUICtrlSetFont($exitLabel, 18 * $DPIratio, Default, 4)
    ElseIf BitAnd($mouse[4] <> $exitLabel, $hoverexitlbl) Then
        $hoverexitlbl = False
        GUICtrlSetFont($exitLabel, 18 * $DPIratio, Default, Default)
    EndIf
WEnd

Func StartMain()
    GUIRegisterMsg($WM_MOUSEWHEEL, "WM_MOUSEWHEEL")
    GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUISetState(@SW_SHOW, $hGUI)
    If $bAero Then GUISetState(@SW_SHOW, $hGUI_child)
    GUISetState(@SW_SHOW, $hGUI_child2)
    _WinAPI_SetFocus(ControlGetHandle($hGUI_child, '', $qsInput))
EndFunc

Func _IEEvent_BeforeNavigate2($IEpDisp, $IEURL, $IEFlags, $IETargetFrameName, $IEPostData, $IEHeaders, $IECancel)
    GUICtrlSetData($qsInput, '')
    $oIE.document.body.style.border = "0"
    HidePanel()
EndFunc

Volatile Func Event_oncontextmenu($oEvtObj)
    If IsObj($oEvtObj) Then $oEvtObj.returnValue = False
EndFunc

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    Local $iCode = BitShift($wParam, 16)
    Local $nIDFrom = BitAND($wParam, 0xFFFF)

    Switch $hWnd
        Case $hGUI_child
            Switch $nIDFrom
                Case $qsInput
                    Switch $iCode
                        Case $EN_CHANGE
                            _IESearchText($oIE, GUICtrlRead($qsInput), 0)
                        Case $EN_SETFOCUS
                            $qsInfocus = True
                        Case $EN_KILLFOCUS
                            $qsInfocus = False
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func _IESearchText($oIE, $sFindText, $fNext = 0)
    $docRange = $oIE.document.body.createTextRange()
    $docRange.execCommand("backColor", false, "#ffffff");
    If $sFindText <> '' Then
        If $fNext = 0 Then
            $oRange = $oIE.document.body.createTextRange()
        Else
            $oRange.moveStart("character")
        EndIf
        If $oRange.FindText($sFindText) Then
            $oRange.execCommand("backColor", false, "#fdee00");
            $oRange.scrollIntoView()
        Else
            $oRange = $oIE.document.body.createTextRange()
        EndIf
    Else
        $oIE.document.parentwindow.scroll(0)
    EndIf
EndFunc

Func WM_MOUSEWHEEL($hWnd, $iMsg, $wParam, $lParam)
    Switch $wParam
        Case 0x00780000
            $oIE.document.parentwindow.scrollBy(0, -150)
        Case 0xFF880000
            $oIE.document.parentwindow.scrollBy(0, 150)
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

Func HidePanel($hide = True)
    AdlibUnRegister("TuckAway")
    If $hide Then
        $tucked = False
        $untucked = True
        $hidden = True
        $tucking = False
        $untucking = False
        If $bAero Then
            For $i = -1 to -663 Step - 1.5
                WinMove($hGUI, "", Default, $i)
            Next
        Else
            WinMove($hGUI, "", Default, -663)
        EndIf
        GUICtrlSetData($qsInput, '')
        If IsObj($oIE) Then $oIE.document.parentwindow.scroll(0)
    Else
        $tucked = False
        $untucked = False
        $hidden = False
        $tucking = False
        $untucking = False
        If $bAero Then
            For $i = -664 to -4 Step 1.5
                WinMove($hGUI, "", Default, $i)
            Next
        Else
            WinMove($hGUI, "", Default, -4)
        EndIf
        _WinAPI_SetFocus(ControlGetHandle($hGUI_child, '', $qsInput))
    EndIf
EndFunc

Func TuckAway()
    If $tuck Then
        $tucking = False
        $untucked = False
        $tucked = True
        For $i = 663 to 695 Step 1
            WinMove($hGUI, "", Default, -$i)
            Sleep(10)
        Next
    Else
        $untucking = False
        $tucked = False
        For $i = 695 to 663 Step - 1
            WinMove($hGUI, "", Default, -$i)
            Sleep(10)
        Next
    EndIf
    AdlibUnRegister("TuckAway")
EndFunc

Func SetBitmap($hGUI, $hImage, $iOpacity = 255)
    Local $hScrDC, $hMemDC, $hBitmap, $hOld, $pSize, $tSize, $pSource, $tSource, $pBlend, $tBlend
    $hScrDC = _WinAPI_GetDC(0)
    $hMemDC = _WinAPI_CreateCompatibleDC($hScrDC)
    $hBitmap = _GDIPlus_BitmapCreateHBITMAPFromBitmap($hImage)
    $hOld = _WinAPI_SelectObject($hMemDC, $hBitmap)
    $tSize = DllStructCreate($tagSIZE)
    $pSize = DllStructGetPtr($tSize)
    DllStructSetData($tSize, "X", _GDIPlus_ImageGetWidth($hImage))
    DllStructSetData($tSize, "Y", _GDIPlus_ImageGetHeight($hImage))
    $tSource = DllStructCreate($tagPOINT)
    $pSource = DllStructGetPtr($tSource)
    $tBlend = DllStructCreate($tagBLENDFUNCTION)
    $pBlend = DllStructGetPtr($tBlend)
    DllStructSetData($tBlend, "Alpha", $iOpacity)
    DllStructSetData($tBlend, "Format", 1)
    _WinAPI_UpdateLayeredWindow($hGUI, $hGUI, 0, $pSize, $hMemDC, $pSource, 0, $pBlend, $ULW_ALPHA)
    _WinAPI_ReleaseDC(0, $hScrDC)
    _WinAPI_SelectObject($hMemDC, $hOld)
    _WinAPI_DeleteObject($hBitmap)
    _WinAPI_DeleteDC($hMemDC)
EndFunc

Func _GDIPlus_GraphicsGetDPIRatio($iDPIDef = 96)
    _GDIPlus_Startup()
    Local $hGfx = _GDIPlus_GraphicsCreateFromHWND(0)
    If @error Then Return SetError(1, @extended, 0)
    Local $aResult
    #forcedef $__g_hGDIPDll, $ghGDIPDll

    $aResult = DllCall($__g_hGDIPDll, "int", "GdipGetDpiX", "handle", $hGfx, "float*", 0)

    If @error Then Return SetError(2, @extended, 0)
    Local $iDPI = $aResult[2]
    Local $aresults[2] = [$iDPIDef / $iDPI, $iDPI / $iDPIDef]
    _GDIPlus_GraphicsDispose($hGfx)
    _GDIPlus_Shutdown()
    Return $aresults
EndFunc   ;==>_GDIPlus_GraphicsGetDPIRatio

Any help would be much appreciated.

Cheers!

example.zip

Edited by mpower
Link to comment
Share on other sites

  • Solution

Okay so looks like problems were in the javascript itself and also lack of support for IE 7/8 from bootstrap/jquery, so I resolved the issue of non-support by using >IE Embedded Control Versioning UDF to set my app/autoit to use Internet Explorer version 10 prior to creating the embedded object. This, along with javascript tweaking, resolved the problems. Hope this helps someone in the future.

Link to comment
Share on other sites

  • 3 months later...
  • 4 months later...

Okay so looks like problems were in the javascript itself and also lack of support for IE 7/8 from bootstrap/jquery, so I resolved the issue of non-support by using >IE Embedded Control Versioning UDF to set my app/autoit to use Internet Explorer version 10 prior to creating the embedded object. This, along with javascript tweaking, resolved the problems. Hope this helps someone in the future.

Link is broken, I found this link here:

https://www.autoitscript.com/forum/topic/163492-ie-embedded-control-versioning-use-ie9-and-html5-in-a-gui/

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

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