Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/27/2020 in all areas

  1. AutoHotkey example Even if the .NET version of the WebView2 code does not work, it may well be that the Windows API version works. The AutoHotkey code actually works. If you want to try the AutoHotkey code, use this procedure. I've only tested on Windows 7. Not on Windows 10. I think the procedure is the same. Install AutoHotkey and SciTE for AutoHotkey: Download and install AutoHotkey_1.1.33.02_setup.exe. By default, AutoHotkey is installed under C:\Program Files\AutoHotkey. Download and install SciTE4AutoHotkey. Click "Installer". Download AutoHotkey v2 by clicking Current Alpha Release and extract the zip-file. Rename C:\Program Files\AutoHotkey\AutoHotkey.exe to AutoHotkey-a.exe or similar. Rename (or copy) AutoHotkeyU64.exe from the AutoHotkey v2 zip-file to AutoHotkey.exe. Copy the new AutoHotkey.exe to C:\Program Files\AutoHotkey Download and install the WebView2 Runtime: Evergreen Bootstrapper. Download AutoHotkey code and data to test WebView2: Download webview2.zip at the bottom of this post and extract the zip-file. Open webview2.ahk in SciTE4AutoHotkey and run the script by pressing F5. The AutoHotkey post describes that you need to install a beta or development version of Microsoft Edge to make the script work. But it has not been necessary. Now the AutoHotkey code must be translated to AutoIt. We've done this before and we can probably do it again. It's not necessarily completely trivial. But probably not completely impossible either. This is the AutoHotkey code to translate, webview2.ahk: #Requires AutoHotkey v2.0-a121 #SingleInstance Force ; DllCall("User32.dll\SetProcessDpiAwarenessContext", "Ptr", 0xFFFFFFFC) ; not sure if this is needed. Works fine without it. main := gui.new("+Resize") main.OnEvent("Close", "ExitApp") main.Show(Format("w{} h{}", A_ScreenWidth * 0.4, A_ScreenHeight * 0.6)) ; need to have the size also otherwise when you un-maximize it the window has zero height and width wv := WebView.new(main) wv.create() return mainSize(controller, win, minMax, *) { ; for performance reasons, you should make the webview2 not visible when the parent window is minimized/hidden. ComCall(3, controller, "Int*", isVisible := 0) ; IWebView2WebViewController::get_IsVisible if (minMax == -1) { if (isvisible) { ComCall(4, controller, "Int", false) ; IWebView2WebViewController::put_IsVisible } } else { if (!isVisible) { ComCall(4, controller, "Int", true) ; IWebView2WebViewController::put_IsVisible } else { DllCall("User32.dll\GetClientRect", "Ptr", win.hWnd, "Ptr", RECT := BufferAlloc(16)) ComCall(6, controller, "Ptr", RECT) ; IWebView2WebViewController::put_Bounds } } } class WebView { __new(parent, dllPath := "WebView2Loader.dll") { if (Type(parent) != "Gui") { throw Exception("Parent must be of type: Gui") } this.parent := parent this.dllPath := dllPath this.controllerCompletedHandler := ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.new(this) this.envCompletedHandler := IWebView2CreateWebView2EnvironmentCompletedHandler.new(this.parent, this.controllerCompletedHandler) } OnControllerCompleted(cb) { this.controllerCreatedCallbacks.push(cb) } create() { if (R := DllCall(this.dllPath . "\CreateCoreWebView2Environment", "Ptr", this.envCompletedHandler, "UInt")) { MsgBox("ERROR " . Format("{:08X}", R)) } } } class IWebView2CreateWebView2EnvironmentCompletedHandler extends IUnknown { __New(parent, controllerCompleted) { super.__new() this.parent := parent this.controllerCompleted := controllerCompleted } Invoke(thisPtr, hresult, ICoreWebView2Env) { ; ICoreWebView2Environment::CreateCoreWebView2Controller Method. ; https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/0-9-538/icorewebview2environment#createcorewebview2controller ComCall(3, ICoreWebView2Env, "Ptr", this.parent.hwnd, "Ptr", this.controllerCompleted) return 0 ; S_OK. } } class ICoreWebView2CreateCoreWebView2ControllerCompletedHandler extends IUnknown { __new(wv) { super.__new() this.wv := wv } Invoke(thisPtr, HRESULT, IWebView2WebViewController) { ObjAddRef(IWebView2WebViewController) ; This was key to retain a reference to the Controller this.wv.parent.OnEvent("Size", Func("mainSize").bind(IWebView2WebViewController)) ; Resize WebView to fit the bounds of the parent window. ; IWebView2WebViewController::put_Bounds Method. ; https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/0-9-538/icorewebview2controller#put_bounds DllCall("User32.dll\GetClientRect", "Ptr", this.wv.parent.hWnd, "Ptr", RECT := BufferAlloc(16)) ComCall(6, IWebView2WebViewController, "Ptr", RECT) ; IWebView2WebViewController::get_CoreWebView2 ; https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/0-9-538/icorewebview2controller#get_corewebview2 ComCall(25, IWebView2WebViewController, "Ptr*", coreWebView := 0) this.wv.coreWebView := coreWebView ; ICoreWebView2::add_navigationstarting ; https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/0-9-538/icorewebview2#add_navigationstarting ; not really sure what the last parameter (EventRegistrationToken) is for but passing an empty buffer makes it work ComCall(7, this.wv.coreWebView, "Ptr", ICoreWebView2NavigationStartingEventHandler.new(), "Ptr", token := BufferAlloc(8)) ; ICoreWebView2::Navigate ; https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/0-9-538/icorewebview2#navigate ; ComCall(5, this.wv.coreWebView, "Str", "https://getbootstrap.com/") ComCall(5, this.wv.coreWebView, "Str", "file:///" A_ScriptDir "/index.html") return 0 ; S_OK. } } class ICoreWebView2NavigationStartingEventHandler extends IUnknown { Invoke(thisPtr, IWebView2WebView, IWebView2NavigationStartingEventArgs) { ComCall(4, IWebView2NavigationStartingEventArgs, "Int*", isUserInitiated := 0) ComCall(5, IWebView2NavigationStartingEventArgs, "Int*", isRedirected := 0) if (isUserInitiated && !isRedirected) { ComCall(3, IWebView2NavigationStartingEventArgs, "Str*", uri := "") if (MsgBox("You are about to navigate to: " . uri . "`n`nDo you want to continue?", "Navigation warning", "YN Icon!") = "No") { ; IWebView2NavigationStartingEventArgs::put_Cancel ComCall(8, IWebView2NavigationStartingEventArgs, "Int", true) ; ICoreWebView2::NavigateToString ComCall(6, IWebView2WebView, "Str", "<h1>Navigation Canceled</h1><p>You chose to cancel navigation to the following URL: " . uri . "</p>") } } return 0 ; S_OK } } class IUnknown { methods := ["QueryInterface", "AddRef", "Release", "Invoke"] vtbl := BufferAlloc(4 * A_PtrSize) __New() { for (name in this.methods) { method := this.GetMethod(name) NumPut("UPtr", CallbackCreate(method.bind(this), "", method.MinParams - 1), this.vtbl, (A_Index - 1) * A_PtrSize) } this.ptr := DllCall("Kernel32.dll\GlobalAlloc", "UInt", 0, "Ptr", A_PtrSize + 4, "UPtr") NumPut("UPtr", this.vtbl.ptr, this.ptr) NumPut("UInt", 1, this.ptr, A_PtrSize) } __Delete() { DllCall("Kernel32.dll\GlobalFree", "Ptr", this) } QueryInterface(riid, ppvObject) { ; No idea why this isn't called at all... } AddRef(interface) { ObjAddRef(interface) } Release(interface) { ObjRelease(interface) } } The example is implemented in AutoIt code in WebView2-3.au3 in the 7z-file at bottom of this post. The AutoHotkey code is included in WebView2.ahk in the 7z-file.
    2 points
  2. nend

    Mail UDF

    I made this small UDF for the Swithmail program because I just can't find any working Autoit code which can use a office 365 account. This is a UDF based on the small commandline Swithmail (549KB) program. SwithMail is an application that allows you to send SSL/TLS SMTP It can send mail via SMTP/Gmail/Office 365 (as far as I know no other AutoIT UDF can do this). Link to Swithmail website https://www.tbare.com/software/swithmail/ In the zipfile example there Swithmail program included. Mail Example.zip
    1 point
  3. 1 point
  4. I don’t see how the script gets past this line: $data = Round(InetGeatSize("https://geeks3d.com/downloads/2020p/FurMark_1.23.0.0_Setup.exe")/1024/1024,2) unless you have a custom InetGeatSize() function defined somewhere...
    1 point
  5. It always returns False for me too. 2 trac tickets (at least) have already been created : * Trac ticket #2284 rejected by Jon 7 years ago * Trac ticket #3659 which looks more promising, initiated by Tersion & mikell 2 years ago in this link, now owned by jpm who sent a fix to Jon 4 months ago. Fingers crossed...
    1 point
  6. I do not know if it is the right explanation. I tried to abort a DL and it is still returning False.
    1 point
  7. Those macros are header annotations, and are used with visual studio etc, to insure functions are called correctly, they are not operative, and in this case can be safely ignored as shown by @TheXman. more info: https://docs.microsoft.com/en-us/windows/win32/winprog/header-annotations
    1 point
  8. Nine

    Stdout redirect how to ?

    your run statement skips the show flag, see help file, that is why it doesn't work. And the way you capture $text may not be enough to grab all data, usually it should be embedded in a loop. And there is no reason why you have a switch and a select, you can combine those 2 into a single switch.
    1 point
  9. From the FileExists help file entry -- Good discussion here --
    1 point
×
×
  • Create New...