Developed for 32 Bit Visual Basic 6 and works very well in AHK 32 bit 2.0.2.
Version Dependent ProgID "RC6.cWebView2"
For the most part the methods and properties are self explanitory.
Have converted a couple of my 64 bit Webview2 scripts to RC6 with no problems.
Remember, Do have fun, thanks
Example 1: Cartman sizing the window
Code: Select all
NavStr := "
(
<body bgColor="cyan" style="overflow:hidden">
<script>
const Eric = [["M14,85l3,9h72c0,0,5-9,4-10c-2-2-79,0-79,1","fill:#7C4E32"]
,["M19,47c0,0-9,7-13,14c-5,6,3,7,3,7l1,14c0,0,10,8,23,8c14,0,26,1,28,0c2-1,9-2,9-4c1-1,27,1,27-9c0-10,7-20-11-29c-17-9-67-1-67-1","fill:#E30000 "]
,["M17,32c-3,48,80,43,71-3 l-35-15","fill:#FFE1C4"]
,["M17,32c9-36,61-32,71-3c-20-9-40-9-71,3","fill:#8ED8F8"]
,["M54,35a10 8 60 1 1 0,0.1zM37,38a10 8 -60 1 1 0,0.1z","fill:#FFF"]
,["M41,6c1-1,4-3,8-3c3-0,9-1,14,3l-1,2h-2h-2c0,0-3,1-5,0c-2-1-1-1-1-1l-3,1l-2-1h-1c0,0-1,2-3,2c0,0-2-1-2-3M17,34l0-2c0,0,35-20,71-3v2c0,0-35-17-71,3M5,62c3-2,5-2,8,0c3,2,13,6,8,11c-2,2-6,0-8,0c-1,1-4,2-6,1c-4-3-6-8-2-12M99,59c0,0-9-2-11,4l-3,5c0,1-2,3,3,3c5,0,5,2,7,2c3,0,7-1,7-4c0-4-1-11-3-10","fill:#FFF200"]
,["M56,78v1M55,69v1M55,87v1","stroke:#000;stroke-linecap:round"]
,["M60,36a1 1 0 1 1 0-0.1M49,36a1 1 0 1 1 0-0.1M57,55a2 3 0 1 1 0-0.1M12,94c0,0,20-4,42,0c0,0,27-4,39,0z",""]
,["M50,59c0,0,4,3,10,0M56,66l2,12l-2,12M25,50c0,0,10,12,23,12c13,0,24,0,35-15","fill:none;stroke:#000;stroke-width:0.5"]];
const NS_SVG = "http://www.w3.org/2000/svg";
const svg = document.createElementNS(NS_SVG,"svg");
svg.setAttribute("viewBox","0 0 105 100");
document.body.appendChild(svg);
for(let i=0;i<Eric.length;i++){
let path = document.createElementNS(NS_SVG,"path");
path.setAttribute("d",Eric[i][0]);
path.setAttribute("style",Eric[i][1]);
svg.appendChild(path);
}
</script>
)"
wv := ComObject("RC6.cWebView2")
win := Gui("toolwindow ReSize","WebView2 Cartman AHK:" A_AhkVersion)
win.BackColor := "black"
win.OnEvent "Close",(*)=>ExitApp()
win.OnEvent "Size",(*)=>wv.SyncSizeToHostWindow()
win.Show "w" A_ScreenWidth*.3 " h" A_ScreenHeight*.5
wv.BindTo(win.hWnd)
wv.NavigateToString(NavStr)
Esc::ExitApp
Code: Select all
WM_LBUTTONDOWN := 513,GCL_HCURSOR := -12,IMAGE_CURSOR := 2,WM_NCLBUTTONDOWN := 161,HTCAPTION := 2
Width := A_ScreenWidth*.3,Height := A_ScreenHeight*.4,tWidth := 15
wv := ComObject("RC6.cWebView2")
win := Gui("-caption resize","WebView2 Testing Drag And Resize")
win.BackColor := "aqua"
pic := win.AddPic("x0 y" tWidth " w" A_ScreenWidth " h" A_ScreenHeight-tWidth)
win.Show "w" Width " h" Height
OnMessage WM_LBUTTONDOWN,(*)=>PostMessage(WM_NCLBUTTONDOWN,HTCAPTION)
DllCall "SetClassLong","ptr",win.hWnd,"int",GCL_HCURSOR,"ptr",LoadPicture("c:\Windows\Cursors\aero_link_xl.cur",,&IMAGE_CURSOR)
wv.BindTo(pic.hWnd)
wv.NavigateToString("<body bgColor='navy' style='overflow:hidden'>")
Esc::ExitApp
Code: Select all
Pixels(){
wv2hWnd := ControlGetHwnd("Chrome_RenderWidgetHostHWND1","A")
ControlSetExStyle "-0x00282024",wv2hWnd
hDC := DllCall("GetDC","ptr",wv2hWnd,"ptr")
WinGetClientPos ,,&w,&h,wv2hWnd
Loop {
DllCall "SetPixelV","ptr",hDC,"int",Random(0,w),"int",Random(0,h),"int",Random(0,1<<24)
Sleep 0
}
}
WV_NAVIGATIONCOMPLETED(*){
HostName := "AHK"
HostObj := {Run_Pixels:Pixels}
objBuf := Buffer(24,0)
ahkObject := ComValue(0x400C,objBuf.ptr) ;VT_BYREF VT_VARIANT
ahkObject[] := HostObj
wv.AddObject(HostName,ahkObject)
wv.ExecuteScript("chrome.webview.hostObjects.AHK.Run_Pixels();")
}
wv := ComObject("RC6.cWebView2")
ComObjConnect wv,"wv_"
win := Gui("toolwindow","WebView2 Pixels AHK:" A_AhkVersion)
win.BackColor := "Black"
win.OnEvent "Close",(*)=>ExitApp()
win.Show "w" A_ScreenWidth*.2 " h" A_ScreenHeight*.37
wv.BindTo(win.hWnd)
wv.NavigateToString("<body style='overflow:hidden'>")
Esc::ExitApp