/* Test.prg. Test of Antview ocx with HMG. This code is a test code. I have download and test the code : https://www.hmgforum.com/viewtopic.php?f=9&t=7012 The sample works fine : many thanks to the authors. That I need to do with the HMG webview2 sample : - Print to PDF, - Get the HTML source. Using Antview ocx version Windows 1.1.270 : https://antview.dev/downloads/ I am retired and I think that this ocx is too expensive for me. */ // Parameters. #define BM_WEBVIEW2_FOLDER "c:\Webview2_Folder" // Folder for the Webview2 files. #define BM_URL_TO_RUN "https://www.cabinet-louis-reynaud.eu/index.php/clr-labs-3/" // URL for navigate #define BM_FILE_PDF hb_dirbase() + "_Result_PDF.pdf" #define BM_FILE_HTML hb_dirbase() + "_Result_HTML.txt" #define BM_FILE_PROP hb_dirbase() + "_Result_Properties.txt" #define BM_GET_PROPS_TRY BEGIN SEQUENCE ; cProps += WriteProp( p, b:&( p ) ) ; RECOVER USING oError ; cProps += WritePropErr( p, hb_valToStr( oError:description ) ) ; END SEQUENCE #include "hmg.ch" #xcommand bh_Try => BEGIN SEQUENCE WITH { | oErr | Break( oErr ) } #xcommand bh_Endtry => END procedure Main DEFINE WINDOW Form1 ; WIDTH 1000 ; HEIGHT 700 ; TITLE "" ; ICON "Files\AntView.ico" ; ON INIT FORM1_INIT() ; ON RELEASE FORM1_RELEASE() ; ON SIZE FORM1_RESIZE() ; ON MAXIMIZE FORM1_RESIZE() ; MAIN DEFINE MAIN MENU POPUP "Action" ITEM 'Accept cookies' ACTION CookiesYes() ITEM 'Get HTML source' ACTION GetHtml() ITEM 'Print to PDF' ACTION PrintToPdf() ITEM 'Get properties' ACTION GetProperties() END POPUP END MENU @ 10, 10 ACTIVEX EdgeWebBrowser ; WIDTH Form1.Width - 28 ; HEIGHT Form1.Height - 80 ; PROGID "{7E146B1D-42ED-4386-904F-9A9EDB61F9AE}" END WINDOW Form1.Center Form1.Activate Return // Menu functions. // Delete the folder BM_WEBVIEW2_FOLDER if cookies menu arent not look. procedure CookiesYes local cJscript := 'var button = document.getElementsByClassName("cmplz-accept");' + hb_eol() cJscript += 'button[0].click();' Form1.EdgeWebBrowser.Object:ExecuteScript( cJscript ) hb_idlesleep( 0.3 ) return procedure GetHtml local i local cHtml := "" local oDoc := win_OleCreateObject( "AntViewAx.AntViewDocument" ) fErase( BM_FILE_HTML ) oDoc:CurrentBrowser := Form1.EdgeWebBrowser.Object oDoc:RequestCurrentHtml() for i := 1 to 100 oDoc:RequestCurrentHtmlSync( @cHtml ) if len( cHtml ) > 0 exit endif hb_idlesleep( 0.3 ) endfor hb_idlesleep( 0.3 ) oDoc := nil hb_memowrit( BM_FILE_HTML, chtml ) wapi_ShellExecute( nil, "open", BM_FILE_HTML ) return procedure PrintToPdf local i fErase( BM_FILE_PDF ) Form1.EdgeWebBrowser.Object:PrintToPdf( BM_FILE_PDF, '{ "landscape" : true, "scale" : 0.7 }' ) for i := 1 to 100 if file( BM_FILE_PDF ) exit endif hb_idlesleep( 0.2 ) endfor hb_idlesleep( 0.2 ) wapi_ShellExecute( nil, "open", BM_FILE_PDF ) return procedure GetProperties local b := Form1.EdgeWebBrowser.Object local p // Property. local cProps // Output list. local oError // Error object. local pu_nSpace := 38 // Spaces for the properties name. ErrorBlock( {|e| Break(e)} ) fErase( BM_FILE_PROP ) cProps := "EdgeWebBrowser properties." + hb_eol() cProps += "!" + replicate( "-", pu_nSpace ) + "!-------------!" + hb_eol() cProps += "!Name" + space( pu_nSpace - 4 ) + "!Type !Value" + hb_eol() cProps += "!" + replicate( "-", pu_nSpace ) + "!-------------!" + hb_eol() p := "Active" ; BM_GET_PROPS_TRY p := "AdditionalBrowserArguments" ; BM_GET_PROPS_TRY p := "AlignDisabled" ; BM_GET_PROPS_TRY p := "AlignWithMargins" ; BM_GET_PROPS_TRY p := "AllowSingleSignOnUsingOSPrimaryAccount" ; BM_GET_PROPS_TRY p := "AlignDisabled" ; BM_GET_PROPS_TRY p := "AutoScroll" ; BM_GET_PROPS_TRY p := "AutoSize" ; BM_GET_PROPS_TRY p := "AxBorderStyle" ; BM_GET_PROPS_TRY p := "BorderWidth" ; BM_GET_PROPS_TRY p := "BrowserAcceleratorKeysEnabled" ; BM_GET_PROPS_TRY p := "BrowserProcessID" ; BM_GET_PROPS_TRY p := "BrowserProcessIDLong" ; BM_GET_PROPS_TRY p := "BrowserVersionString" ; BM_GET_PROPS_TRY p := "BuiltInErrorPageEnabled" ; BM_GET_PROPS_TRY p := "CanGoBack" ; BM_GET_PROPS_TRY p := "CanGoForward" ; BM_GET_PROPS_TRY p := "Caption" ; BM_GET_PROPS_TRY p := "Color" ; BM_GET_PROPS_TRY p := "ContainsFullScreenElement" ; BM_GET_PROPS_TRY p := "Controller" ; BM_GET_PROPS_TRY p := "CookieManager" ; BM_GET_PROPS_TRY p := "CreateWebViewOnCreate" ; BM_GET_PROPS_TRY p := "CurrentPPI" ; BM_GET_PROPS_TRY p := "DefaultContextMenusEnabled" ; BM_GET_PROPS_TRY p := "DefaultInterface" ; BM_GET_PROPS_TRY p := "DefaultScriptDialogsEnabled" ; BM_GET_PROPS_TRY p := "DefaultUserDataFolderLocation" ; BM_GET_PROPS_TRY p := "DemoDaysLeft" ; BM_GET_PROPS_TRY p := "DevToolsEnabled" ; BM_GET_PROPS_TRY p := "DockSite" ; BM_GET_PROPS_TRY p := "DocumentTitle" ; BM_GET_PROPS_TRY p := "DoubleBuffered" ; BM_GET_PROPS_TRY p := "DownloadDialogCornerAlignment" ; BM_GET_PROPS_TRY p := "DropTarget" ; BM_GET_PROPS_TRY p := "Enabled" ; BM_GET_PROPS_TRY p := "Environment" ; BM_GET_PROPS_TRY p := "EventsUseHexadecimal" ; BM_GET_PROPS_TRY p := "ExplicitHeight" ; BM_GET_PROPS_TRY p := "ExplicitLeft" ; BM_GET_PROPS_TRY p := "ExplicitTop" ; BM_GET_PROPS_TRY p := "ExplicitWidth" ; BM_GET_PROPS_TRY p := "Font" ; BM_GET_PROPS_TRY p := "GeneralAutofillEnabled" ; BM_GET_PROPS_TRY p := "HelpFile" ; BM_GET_PROPS_TRY p := "IDispatchPointer" ; BM_GET_PROPS_TRY p := "KeyPreview" ; BM_GET_PROPS_TRY p := "Language" ; BM_GET_PROPS_TRY p := "LastErrorCode" ; BM_GET_PROPS_TRY p := "LastErrorMessage" ; BM_GET_PROPS_TRY p := "MouseInClient" ; BM_GET_PROPS_TRY p := "Muted" ; BM_GET_PROPS_TRY p := "NextFocusWindowHandle" ; BM_GET_PROPS_TRY p := "NextFocusWindowHandleUInt" ; BM_GET_PROPS_TRY p := "ParentCustomHint" ; BM_GET_PROPS_TRY p := "ParentDoubleBuffered" ; BM_GET_PROPS_TRY p := "PasswordAutosaveEnabled" ; BM_GET_PROPS_TRY p := "PixelsPerInch" ; BM_GET_PROPS_TRY p := "PopupMode" ; BM_GET_PROPS_TRY p := "PreviousFocusWindowHandle" ; BM_GET_PROPS_TRY p := "PreviousFocusWindowHandleUInt" ; BM_GET_PROPS_TRY p := "PrintScale" ; BM_GET_PROPS_TRY p := "Scaled" ; BM_GET_PROPS_TRY p := "ScaleFactor" ; BM_GET_PROPS_TRY p := "ScreenSnap" ; BM_GET_PROPS_TRY p := "ScriptEnabled" ; BM_GET_PROPS_TRY p := "Settings" ; BM_GET_PROPS_TRY p := "SizeRatio" ; BM_GET_PROPS_TRY p := "SnapBuffer" ; BM_GET_PROPS_TRY p := "Source" ; BM_GET_PROPS_TRY p := "StatusBarEnabled" ; BM_GET_PROPS_TRY p := "StatusBarText" ; BM_GET_PROPS_TRY p := "StyleName" ; BM_GET_PROPS_TRY p := "SynchronousTimeOut" ; BM_GET_PROPS_TRY p := "TargetCompatibleBrowserVersion" ; BM_GET_PROPS_TRY p := "UseDockManager" ; BM_GET_PROPS_TRY p := "UserAgent" ; BM_GET_PROPS_TRY p := "UserDataFolder" ; BM_GET_PROPS_TRY p := "VersionString" ; BM_GET_PROPS_TRY p := "Visible" ; BM_GET_PROPS_TRY p := "VisibleDockClientCount" ; BM_GET_PROPS_TRY p := "WebMessageEnabled" ; BM_GET_PROPS_TRY p := "WebResourceResponseReceivedEnabled" ; BM_GET_PROPS_TRY p := "WebView2LoaderPath" ; BM_GET_PROPS_TRY p := "WebViewCreated" ; BM_GET_PROPS_TRY p := "WindowClosedRequestEnabled" ; BM_GET_PROPS_TRY p := "ZoomControlEnabled" ; BM_GET_PROPS_TRY p := "ZoomFactor" ; BM_GET_PROPS_TRY cProps += "!" + replicate( "-", pu_nSpace ) + "!-------------!" + hb_eol() hb_MemoWrit( BM_FILE_PROP, cProps ) wapi_ShellExecute( nil, "open", BM_FILE_PROP ) return function WriteProp( cName, xProp ) local pu_nSpace := 38 // Spaces for the properties name. local cStringe := "!" + cName + space( pu_nSpace - len( cName ) ) + "!" cStringe += valtype( xProp ) + space( 13 - len( valtype ( xProp ) ) ) + "!" return cStringe + hb_valToStr( xProp ) + hb_eol() function WritePropErr( cName, cError ) local pu_nSpace := 38 // Spaces for the properties name. local cStringe := "!" + cName + space( pu_nSpace - len( cName ) ) + "!" cStringe += " ***Error*** !" return cStringe + cError + hb_eol() // Form1 functions. procedure Form1_Init local IsSucess := .F. local nError Form1.Title := "http://bernard.mouille.free.fr/" Form1.EdgeWebBrowser.Object:UserDataFolder := BM_WEBVIEW2_FOLDER nError := Form1.EdgeWebBrowser.Object:CreateWebViewSync( nil ) if .not. nError == 0 MsgStop( Error_CreateWebViewSync( nError ), "CreateWebViewSync() error" ) else Form1.EdgeWebBrowser.Object:NavigateWithWebResourceRequestSync( BM_URL_TO_RUN ; // URL. , 'GET' ; // Method ( GET / POST ) , "" ; // Postdate( If POST ). , "" ; // Headers. , @IsSucess ; // Return .T. if navigate ok. , @nError ) // Retuned error. if .not. IsSucess MsgStop( Error_TxWebErrorStatus( nError ), "NavigateWithWebResourceRequestSync() error" ) endif endif return procedure Form1_Resize Form1.EdgeWebBrowser.Width := Form1.Width - 28 Form1.EdgeWebBrowser.Height := Form1.Height - 80 return procedure Form1_Release bh_Try Form1.EdgeWebBrowser.Object:CloseBrowserProcess() bh_Endtry bh_Try Form1.EdgeWebBrowser.Object:CloseWebView() bh_Endtry return // Errors functions. function Error_CreateWebViewSync( nError ) local cError do case case nError == 0 cError := "0 -> No Error." case nError == 21 cError := "21 -> Function is already running (can only run one at a time)." case nError == 22 cError := "22 -> Function timed out." case nError == 25 cError := "25 -> Trying to run a synchronous method from within a WebView2 event." otherwise cError := hb_ntos( nError ) + " -> *** Error is not in this program. ***" endcase return cError function Error_TxWebErrorStatus( nError ) local cError do case case nError == 0 cError := "0 -> Unknown error." case nError == 1 cError := "1 -> Certificate Common Name Is Incorrect." case nError == 2 cError := "2 -> CertificateExpired." case nError == 3 cError := "3 -> Client Certificate Contains Errors." case nError == 4 cError := "4 -> CertificatRevoked." case nError == 5 cError := "5 -> Certificate Is Invalid." case nError == 6 cError := "6 -> Server Unreachable." case nError == 7 cError := "7 -> Timeout." case nError == 8 cError := "8 -> Error Http Invalid Server Response." case nError == 9 cError := "9 -> Connection Aborted." case nError == 10 cError := "10 -> Connection Reset." case nError == 11 cError := "11 -> Disconnected." case nError == 12 cError := "12 -> CannotConnect." case nError == 13 cError := "13 -> Host Name Not Resolved." case nError == 14 cError := "14 -> Operation Canceled." case nError == 15 cError := "15 -> Redirect Failed." case nError == 16 cError := "16 -> Unexpected Error." otherwise cError := hb_ntos( nError ) + " -> *** Error is not in this program. ***" endcase return cError