Skip to content

Commit 4e01dfe

Browse files
authored
Merge pull request #41 from mlipok/PDVViewerExample
Pdv viewer example
2 parents cd3589d + c72c523 commit 4e01dfe

File tree

4 files changed

+101
-36
lines changed

4 files changed

+101
-36
lines changed

examples/4-FileViewerDemo.au3

Lines changed: 101 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,30 @@
11
#AutoIt3Wrapper_UseX64=y
22
#include <GUIConstantsEx.au3>
3+
#include <SendMessage.au3>
4+
#include <StaticConstants.au3>
5+
#include <WinAPIGdi.au3>
6+
#include <WinAPISysWin.au3>
37
#include <WindowsConstants.au3>
4-
5-
#include "..\NetWebView2Lib.au3"
8+
#include <WinAPIGdi.au3>
9+
#include <WinAPIGdiDC.au3>
10+
#include <WinAPIHObj.au3>
11+
12+
#SciTE4AutoIt3_Dynamic_Include_Path=;..\NetWebView2Lib.au3
13+
#SciTE4AutoIt3_Dynamic_Include=y ;dynamic.include=y/n
14+
#SciTE4AutoIt3_Dynamic_Include_whiletyping=y ;dynamic.include.whiletyping=y/n
15+
#SciTE4AutoIt3_Dynamic_Include_recursive_check=y ;dynamic.include.recursive.check=n/y
16+
#SciTE4AutoIt3_Dynamic_Include_use_local_cache=y ;dynamic.include.use.local.cache=n/y
17+
#SciTE4AutoIt3_Dynamic_Include_version=prod ;dynamic.include.version=prod/beta
18+
#SciTE4AutoIt3_Dynamic_Include_verboselevel=0 ;dynamic.include.verbose.level=0/1/2 ; 0=disabled; 1=Timing per Function; 2=1+Total timing
19+
#SciTE4AutoIt3_Dynamic_Include_Always_Update_Local_File=n ;dynamic.include.always.update.local.file=n/y
20+
#SciTE4AutoIt3_AutoItTools_debug=n ;debug.autoIttools=n/y
21+
#SciTE4AutoIt3_AutoItDynamicIncludes_debug=n ;debug.AutoItDynamicIncludes=n/y
22+
#SciTE4AutoIt3_AutoItAutocomplete_debug=n ;debug.autoitautocomplet=n/y
23+
#SciTE4AutoIt3_AutoItGotoDefinition_debug=n ;debug.autoitgotodefinition=n/y
24+
#SciTE4AutoIt3_AutoItIndentFix_debug=n ;debug.autoitindentfix=n/y
25+
26+
;~ #include "..\NetWebView2Lib.au3"
27+
#include "..\NetWebView2Lib-org.au3"
628

729
; ==============================================================================
830
; WebView2 Multi-Channel Presentation Script^
@@ -20,13 +42,13 @@ Func Main()
2042
#forceref $oMyError
2143

2244
; Create the UI
23-
Local $iHeight = 400
24-
$hGUI = GUICreate("WebView2 .NET Manager - Community Demo", 800, $iHeight, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
25-
$idLabelStatus = GUICtrlCreateLabel("Status: Initializing Engine...", 10, $iHeight -20 , 880, 20)
45+
Local $iHeight = 800
46+
$hGUI = GUICreate("WebView2 .NET Manager - Demo: " & @ScriptName, 1100, $iHeight, -1, -1, BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPCHILDREN))
47+
$idLabelStatus = GUICtrlCreateLabel("Status: Initializing Engine...", 10, $iHeight - 20, 880, 20)
2648
GUICtrlSetFont(-1, 9, 400, 0, "Segoe UI")
2749

2850
; Initialize WebView2 Manager and register events
29-
Local $oWebV2M = _NetWebView2_CreateManager()
51+
Local $oWebV2M = _NetWebView2_CreateManager("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0", "", "--mute-audio")
3052
$_g_oWeb = $oWebV2M
3153
If @error Then Return SetError(@error, @extended, $oWebV2M)
3254

@@ -37,43 +59,27 @@ Func Main()
3759
Local $sProfileDirectory = @TempDir & "\NetWebView2Lib-UserDataFolder"
3860
_NetWebView2_Initialize($oWebV2M, $hGUI, $sProfileDirectory, 0, 0, 0, 0, True, True, True, 1.2, "0x2B2B2B")
3961

40-
GUISetState(@SW_SHOW)
41-
ConsoleWrite("! ===" & @ScriptLineNumber & @CRLF)
42-
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 0)
62+
GUISetState(@SW_SHOW, $hGUI)
63+
WinSetOnTop($hGUI, '', True)
64+
4365
Local $s_PDF_FileFullPath
4466

45-
GUISetState(@SW_HIDE)
46-
$s_PDF_FileFullPath = "file:///" & @ScriptDir & '/FileViewerDemo_1.pdf'
47-
_NetWebView2_Navigate($oWebV2M, $s_PDF_FileFullPath)
48-
ConsoleWrite("! ===" & @ScriptLineNumber & @CRLF)
49-
Sleep(200)
50-
GUISetState(@SW_SHOW)
51-
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, $s_PDF_FileFullPath)
67+
_WebView2_ShowPD($hGUI, $oWebV2M, "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf")
5268

53-
GUISetState(@SW_HIDE)
54-
$s_PDF_FileFullPath = "file:///" & @ScriptDir & '/FileViewerDemo_2.pdf'
55-
_NetWebView2_Navigate($oWebV2M, $s_PDF_FileFullPath)
56-
ConsoleWrite("! ===" & @ScriptLineNumber & @CRLF)
57-
Sleep(200)
58-
GUISetState(@SW_SHOW)
59-
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, $s_PDF_FileFullPath)
69+
_WebView2_ShowPD($hGUI, $oWebV2M, "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf")
6070

61-
ConsoleWrite($oWebV2M.GetBrowserProcessId() & @CRLF)
62-
ConsoleWrite($oWebV2M.GetInnerText() & @CRLF)
63-
_NetWebView2_Navigate($oWebV2M, 'https://google.com')
64-
MsgBox($MB_TOPMOST, @ScriptLineNumber, _NetWebView2_GetSource($oWebV2M))
65-
MsgBox($MB_TOPMOST, @ScriptLineNumber, $oWebV2M.GetDocumentTitle())
66-
;~ $oWebV2M.Print()
67-
ConsoleWrite($oWebV2M.WebViewSetFocus() & @CRLF)
68-
$oWebV2M.LockWebView()
69-
$oWebV2M.DisableBrowserFeatures()
71+
$s_PDF_FileFullPath = "file:///" & @ScriptDir & '/FileViewerDemo_1.pdf'
72+
_WebView2_ShowPD($hGUI, $oWebV2M, $s_PDF_FileFullPath)
73+
;~ MsgBox($MB_TOPMOST, " _WebView2_ShowPD() TEST #" & @ScriptLineNumber, $s_PDF_FileFullPath, 0, $hGUI)
7074

71-
ConsoleWrite("- " & $oWebV2M.GetHtmlSource() & @CRLF)
72-
ConsoleWrite("- " & $oWebV2M.GetSelectedText() & @CRLF)
73-
$oWebV2M.SetZoom(0.6);
75+
$s_PDF_FileFullPath = "file:///" & @ScriptDir & '/FileViewerDemo_2.pdf'
76+
_WebView2_ShowPD($hGUI, $oWebV2M, $s_PDF_FileFullPath)
77+
;~ MsgBox($MB_TOPMOST, " _WebView2_ShowPD() TEST #" & @ScriptLineNumber, $s_PDF_FileFullPath, 0, $hGUI)
7478

79+
$s_PDF_FileFullPath = "file:///" & @ScriptDir & '/FileViewerDemo_3.pdf'
80+
_WebView2_ShowPD($hGUI, $oWebV2M, $s_PDF_FileFullPath)
7581

76-
MsgBox($MB_TOPMOST, "TEST #" & @ScriptLineNumber, 1)
82+
;~ MsgBox($MB_TOPMOST, " _WebView2_ShowPD() TEST #" & @ScriptLineNumber, $s_PDF_FileFullPath, 0, $hGUI)
7783

7884
; Main Loop
7985
While 1
@@ -87,3 +93,62 @@ Func Main()
8793

8894
_NetWebView2_CleanUp($oWebV2M, $oJSBridge)
8995
EndFunc ;==>Main
96+
97+
Func _GetFirstChildWindowHWND($hWnd)
98+
Local $aData = _WinAPI_EnumChildWindows($hWnd)
99+
ConsoleWrite("! $aData[1][0] = " & $aData[1][0] & @CRLF)
100+
;~ _ArrayDisplay($aData, '_WinAPI_EnumChildWindows')
101+
102+
If Not @error And UBound($aData) Then Return $aData[1][0]
103+
104+
Return SetError(1, @extended, False)
105+
EndFunc ;==>_GetFirstChildWindowHWND
106+
107+
108+
Func __WebView2_freezer($hMainGUI_Window, $hWebView2_Window)
109+
Local $aPos = WinGetPos($hWebView2_Window)
110+
111+
Local $hPrev = GUISwitch($hMainGUI_Window)
112+
;~ Local $idPic = GUICtrlCreatePic('', $aPos[0], $aPos[1], $aPos[2], $aPos[3])
113+
Local $idPic = GUICtrlCreatePic('', 0, 0, $aPos[2], $aPos[3])
114+
Local $hPic = GUICtrlGetHandle($idPic)
115+
GUISwitch($hPrev)
116+
117+
; Create bitmap
118+
Local $hDC = _WinAPI_GetDC($hPic)
119+
Local $hDestDC = _WinAPI_CreateCompatibleDC($hDC)
120+
Local $hBitmap = _WinAPI_CreateCompatibleBitmap($hDC, $aPos[2], $aPos[3])
121+
Local $hDestSv = _WinAPI_SelectObject($hDestDC, $hBitmap)
122+
Local $hSrcDC = _WinAPI_CreateCompatibleDC($hDC)
123+
Local $hBmp = _WinAPI_CreateCompatibleBitmap($hDC, $aPos[2], $aPos[3])
124+
Local $hSrcSv = _WinAPI_SelectObject($hSrcDC, $hBmp)
125+
_WinAPI_PrintWindow($hWebView2_Window, $hSrcDC, 2)
126+
_WinAPI_BitBlt($hDestDC, 0, 0, $aPos[2], $aPos[3], $hSrcDC, 0, 0, $MERGECOPY)
127+
128+
_WinAPI_ReleaseDC($hPic, $hDC)
129+
_WinAPI_SelectObject($hDestDC, $hDestSv)
130+
_WinAPI_SelectObject($hSrcDC, $hSrcSv)
131+
_WinAPI_DeleteDC($hDestDC)
132+
_WinAPI_DeleteDC($hSrcDC)
133+
_WinAPI_DeleteObject($hBmp)
134+
135+
; Set bitmap to control
136+
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
137+
Local $hObj = _SendMessage($hPic, $STM_GETIMAGE)
138+
If $hObj <> $hBitmap Then
139+
_WinAPI_DeleteObject($hBitmap)
140+
EndIf
141+
Return $idPic
142+
EndFunc ;==>__WebView2_freezer
143+
144+
Func _WebView2_ShowPD($hMainGUI_Window, $oWebV2M, $s_PDF_FileFullPath)
145+
Local $hWebView2_Window = _WinAPI_GetWindow($hMainGUI_Window, $GW_CHILD)
146+
Local $idPic = __WebView2_freezer($hMainGUI_Window, $hWebView2_Window)
147+
_SendMessage($hWebView2_Window, $WM_SETREDRAW, False, 0) ; Disables ; https://www.autoitscript.com/forum/topic/199172-disable-gui-updating-repainting/
148+
_NetWebView2_Navigate($oWebV2M, $s_PDF_FileFullPath)
149+
Sleep(1000)
150+
_SendMessage($hWebView2_Window, $WM_SETREDRAW, True, 0) ; Enables
151+
_WinAPI_RedrawWindow($hWebView2_Window, 0, 0, BitOR($RDW_FRAME, $RDW_INVALIDATE, $RDW_ALLCHILDREN)) ; Repaints
152+
GUICtrlDelete($idPic)
153+
EndFunc ;==>_WebView2_ShowPD
154+

examples/FileViewerDemo_1.pdf

26.2 KB
Binary file not shown.

examples/FileViewerDemo_2.pdf

26.4 KB
Binary file not shown.

examples/FileViewerDemo_3.pdf

39.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)