Skip to content

Commit

Permalink
Tools dircetory added
Browse files Browse the repository at this point in the history
  • Loading branch information
Ixiko committed Jul 15, 2022
1 parent 0325e3f commit e0fd701
Show file tree
Hide file tree
Showing 150 changed files with 24,376 additions and 32,445 deletions.
130 changes: 130 additions & 0 deletions AHK_V2/Webview2.ahk2
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
; Current WebView2 Include
; For Version 2.0-beta.1
On_ReSize(controller,*){
If(wvLeft+wvTop+wvRight+wvBottom>0)
DllCall "SetRect","ptr",RECT,"int",wvLeft,"int",wvTop,"int",wvRight,"int",wvBottom
Else
DllCall "GetClientRect","ptr",AHKGui.hWnd,"ptr",RECT
NumPut "int",wvLeft,RECT
NumPut "int",wvTop,RECT,4
NumPut "int",NumGet(RECT,8,"int")-wvLeft,RECT,8
NumPut "int",NumGet(RECT,12,"int")-wvTop,RECT,12
; IWebView2WebViewController::put_Bounds
ComCall 6,controller,"ptr",RECT
}

QueryInterface(this,riid,ppvObject){
; Not used
}

AddRef(this){
NumPut "uint",ObjAddRef(this),this,A_PtrSize
}

Release(this){
NumPut "uint",ObjRelease(this),this,A_PtrSize
}

Invoke(this,HRESULT,iObject){
global CoreWebView2
Switch(this){
Case WebView2Environment:
; iObject = ICoreWebView2Environment
; ICoreWebView2Environment::CreateCoreWebView2Controller
ComCall 3,iObject,"ptr",AHKGui.hWnd,"ptr",WebView2Controller
Case WebView2Controller:
; iObject = IWebView2WebViewController
ObjAddRef iObject
AHKGui.OnEvent "Size",On_ReSize.Bind(iObject)
; Resize Or Set WebView to fit the bounds of the parent window.
If(wvLeft+wvTop+wvRight+wvBottom>0)
DllCall "SetRect","ptr",RECT,"int",wvLeft,"int",wvTop,"int",wvRight,"int",wvBottom
Else
DllCall "GetClientRect","ptr",AHKGui.hWnd,"ptr",RECT
; IWebView2WebViewController::put_Bounds
ComCall 6,iObject,"ptr",RECT
; IWebView2WebViewController::put_ZoomFactor
ComCall 8,iObject,"double",ZoomFactor
; IWebView2WebViewController::get_CoreWebView2
ComCall 25,iObject,"ptr*",&iCoreWebView2 := 0
CoreWebView2 := iCoreWebView2
; ICoreWebView2::add_NavigationCompleted
ComCall 15,CoreWebView2,"ptr",WebView2NavigationCompletedEventHandler,"uint64",token := 0
; ICoreWebView2::add_DocumentTitleChanged
ComCall 46,CoreWebView2,"ptr",WebView2DocumentTitleChangedEventHandler,"uint64",token := 0
If(NavUri)
; ICoreWebView2::Navigate
ComCall 5,CoreWebView2,"str",NavUri
Else If(NavStr)
; ICoreWebView2::NavigateToString
ComCall 6,CoreWebView2,"str",NavStr
If DevTool
; ICoreWebView2::OpenDevToolsWindow
ComCall 51,CoreWebView2
Case WebView2NavigationCompletedEventHandler:
If(jsCode)
; ICoreWebView2::ExecuteScript
ComCall 29,CoreWebView2,"str",jsCode,"ptr",WebView2ExecuteScriptCompletedHandler
If(HostName){
If(ObjGetCapacity(HostObj)){
objBuf := Buffer(24,0)
ahkObject := ComValue(0x400C,objBuf.ptr) ;VT_BYREF VT_VARIANT
ahkObject[] := HostObj
; ICoreWebView2::AddHostObjectToScript
ComCall 49,CoreWebView2,"str",HostName,"ptr",ahkObject
}Else{
MsgBox "HostObj Not Created....","Object Error!","iconi"
ExitApp
}
}
Case WebView2DocumentTitleChangedEventHandler:
If(Type(Event_Name)="Func"){
; ICoreWebView2::get_DocumentTitle
ComCall 48,CoreWebView2,"str*",&DocTitle := 0
Event_Name.Call(DocTitle)
}
}
}

; Run jScript on the fly
Run_JS(Code){
; ICoreWebView2::ExecuteScript
ComCall 29,CoreWebView2,"str",Code,"ptr",WebView2ExecuteScriptCompletedHandler
}

; Main vtable Object Setup
WebView2(){
Static vtbl := []
vtbl.Push Buffer(4*A_PtrSize)
For Method In [QueryInterface,AddRef,Release,Invoke]
NumPut "uptr",CallbackCreate(Method),vtbl[vtbl.Length],(A_Index-1)*A_PtrSize
ptr := DllCall("GlobalAlloc","uint",64,"ptr",A_PtrSize+4,"uptr")
NumPut "uptr",vtbl[vtbl.Length].ptr,ptr
NumPut "uint",1,ptr,A_PtrSize
Return ptr
}

; One Main Function For WebView2 Setup
WebView2_Init(iGui){
global
AHKGui := iGui
WebView2Environment := WebView2() ; IWebView2CreateWebView2EnvironmentCompletedHandler.
WebView2Controller := WebView2() ; ICoreWebView2CreateCoreWebView2ControllerCompletedHandler.
WebView2NavigationCompletedEventHandler := WebView2() ; ICoreWebView2NavigationCompletedEventHandler
WebView2ExecuteScriptCompletedHandler := WebView2() ; ICoreWebView2ExecuteScriptCompletedHandler
WebView2DocumentTitleChangedEventHandler := WebView2() ; ICoreWebView2DocumentTitleChangedEventHandler.

local dllPath := "c:\Program Files (x86)\AutoHotKey\JMM\WebView2\x64\WebView2Loader"
DllCall dllPath "\CreateCoreWebView2Environment","ptr",WebView2Environment

If(A_LastError){
local buf := Buffer(8,0)
DllCall "FormatMessage","uint",256|4096,"ptr",0,"uint",A_LastError,"uint",0,"ptr",buf.ptr,"uint",0,"ptr",0
msgbox "Error " A_LastError " = " StrGet(NumGet(buf,"ptr"))
ExitApp
}
}

; WebView2 Globals To Make AHK Gui Execute Your Code
NavUri := "",NavStr := "",RECT := Buffer(16,0),Event_Name := "",jsCode := "",HostName := "",HostObj := {}
ZoomFactor := 1.25,wvLeft := 0,wvTop := 0,wvRight := 0,wvBottom := 0,DevTool := False,AHKGui := ""
2 changes: 1 addition & 1 deletion AHK_V2/WinAPI/Shlwapi.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
AssocCreate(clsid, riid, ppv) => DllCall('Shlwapi\AssocCreate', 'ptr', clsid, 'ptr', riid, 'ptr', ppv, 'int')
AssocCreate(clsid, riid, ppv) => DllCall('Shlwapi\AssocCreate', 'ptr', clsid, 'ptr', riid, 'ptr', ppv, 'int')
AssocGetPerceivedType(pszExt, ptype, pflag, ppszType) => DllCall('Shlwapi\AssocGetPerceivedType', 'wstr', pszExt, 'ptr', ptype, 'ptr', pflag, 'wstr', ppszType, 'int')
AssocIsDangerous(pszAssoc) => DllCall('Shlwapi\AssocIsDangerous', 'wstr', pszAssoc, 'int')
AssocQueryKey(flags, key, pszAssoc, pszExtra, phkeyOut) => DllCall('Shlwapi\AssocQueryKey', 'int', flags, 'int', key, 'str', pszAssoc, 'str', pszExtra, 'ptr', phkeyOut, 'int')
Expand Down
2 changes: 1 addition & 1 deletion AHK_V2/class_MemoryViewer.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#DllImport ReadProcessMemory, Kernel32\ReadProcessMemory, i==tttutut*
#DllImport ReadProcessMemory, Kernel32\ReadProcessMemory, i==tttutut*
#DllImport WriteProcessMemory, Kernel32\WriteProcessMemory, i==tttutut*
#DllImport VirtualProtectEx, Kernel32\VirtualProtectEx, i==ttutuiui*

Expand Down
2 changes: 1 addition & 1 deletion AHK_V2/class_WebView2.ahk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/************************************************************************
/************************************************************************
* @description Use Microsoft Edge WebView2 control in ahk
* @file WebView2.ahk
* @author thqby
Expand Down
30 changes: 30 additions & 0 deletions AHK_V2/docs/_JXON_README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# JXON_ahk2
JSON serializer for AHK v2 (beta.3)

Thanks to cocobelgica for his initial AHK v1 release [here](https://github.com/cocobelgica/AutoHotkey-JSON).

The focus of this serializer is compatibility with JSON.

Most Array(), Map(), Object() or a nested combination are supported (with exception for maps with object type keys, those are not supported).

## JxonEncode(obj, indent:=0)

```
text := JxonEncode(obj, indent:=0)
```

Output var is the serialized text.

Indent is in spaces. Leaving this param blank will output the JSON text as a single line. A value of 1 or more in this param will insert a line break at every element, and every nested level will get an additional indented space. This param indicates the number of spaces to add for indent per level.

## JxonDecode(&text)

```
obj := JxonDecode(&text)
```

Input must be properly formatted JSON text. If not properly formatted an error will be thrown. The error message will indicate the character number where parsing failed due to improper format.

The input `&text` must be passed as a VarRef with the `&` character. This will ensure better performance and memory savings with massive input strings.

Limitation: Class which objects are to be decoded must have a constructor able to be executed without arguments (will be called to instantiate the Class).
41 changes: 41 additions & 0 deletions AHK_V2/examples/Webview2-example 2.ahk2
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#include WebView2.ahk

HtmlSite := "https www.google.com " Broken Link for safety

jsCode := "
(
function Sleep(ms){
return new Promise(resolve => setTimeout(resolve,ms));
}
async function InterAct(){
// Load jQuery
var jq = document.createElement("script");
jq.src = "https ajax.googleapis.com /ajax/libs/jquery/3.5.1/jquery.min.js"; Broken Link for safety
document.head.appendChild(jq);

// Load SweetAlert
var msg = document.createElement("script");
msg.src = "https unpkg.com /sweetalert/dist/sweetalert.min.js"; Broken Link for safety
document.head.appendChild(msg);

// Wait for jQuery & SweetAlert to Load
await Sleep(500);

// Show Cool MsgBox SweetAlert
await swal("Watch Google Logo Fade Out...","jQuery Version = "+$.fn.jquery,"info");

$("#hplogo").fadeOut(3000);
}
InterAct();
)"

win := Gui.new(,"WebView2 Fade Google Logo")
win.OnEvent "Close",(*) => ExitApp()

Init_WebView2(win)

ExecuteScript_WebView2

win.Show "w" A_ScreenWidth//2 " h" A_ScreenHeight//2

Esc::ExitApp
25 changes: 25 additions & 0 deletions AHK_V2/examples/Webview2-example 3.ahk2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include webview2.ahk

NavUri := "https www.bing.com " Broken Link for safety

win := Gui.New("-caption","WebView2 Testing")
win.BackColor := "Aqua"

wvRight := A_ScreenWidth
wvBottom := A_ScreenHeight/1.5

WebView2_Init(win)

win.Show "w" A_ScreenWidth " h" A_ScreenHeight

;Give some time to load Gui
sleep 600

NavUri := "https www.google.com " Broken Link for safety

wvtop := A_ScreenHeight/1.5
wvBottom := 1090

WebView2_Init(win)

Esc::ExitApp
48 changes: 48 additions & 0 deletions AHK_V2/examples/Webview2-example 4.ahk2
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include WebView2.ahk

NavUri := "https://www.google.com"

jsCode := Format("
(
function Sleep(ms){
return new Promise(resolve => setTimeout(resolve,ms));
}
(async function Run_Script(){
// Load jQuery
var jq = document.createElement("script");
jq.src = "https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
document.head.appendChild(jq);

// Wait for jQuery to Load
await Sleep(350);

// Load SweetAlert
var msg = document.createElement("script");
msg.src = "https://unpkg.com/sweetalert/dist/sweetalert.min.js";
document.head.appendChild(msg);

// Wait for SweetAlert to Load
await Sleep(350);

var style = document.createElement("style");
style.textContent = ".swal-title{color:yellow;}"+
".swal-modal{background-color:navy;border:3px solid cyan}"+
".swal-text{font-size:18px;background-color:navy;border:3px solid cyan;color:yellow;}"
document.head.appendChild(style);

// Show Cool MsgBox SweetAlert
await swal("Watch Google Logo Fade Out...","jQuery Version = "+$.fn.jquery+"\nAHK Version = {}","info");
// IF GOOGLE LOGO DOES NOT FADE, TRY OTHER FADEOUT
//$("#hplogo").fadeOut(3000);
$(".lnXdpd").fadeOut(3000);
})();
)",A_AhkVersion)

win := Gui("toolwindow","WebView2 Fade Google Logo")
win.OnEvent "Close",ExitApp

WebView2_Init win

win.Show "w" A_ScreenWidth/2 " h" A_ScreenHeight/2

Esc::ExitApp
Loading

0 comments on commit e0fd701

Please sign in to comment.