VFP - Create a Document object
Since the document interface is a pretty common interface to use in conjunction with an antview object, it seems like a good idea to show how-to set it up.
The document object has to be created and then linked to the antview object that you are going to use it with.
The following code is from the standard example, which can be found in your examples folder.
This is taken from the Init method in the Antview form object in the file antviewv2.scx.
* create objects
thisform.oAntviewDocument = CREATEOBJECT('AntViewAx2.AntViewDocument') && create the AntViewDocument and assign it to a form property
* create fox form - antviewdocuments event handler for aSynch methods.
* Set next property true if you would like to bind antviewDocument events to a VFP event handler
thisform.allowasyncmethods = .t.
IF thisform.allowasyncmethods
* declare asych antviewdocument return variables
PUBLIC pcReturnString
pcReturnString = ""
thisform.oAvdEvents = NEWOBJECT('avdeventsv2','avdeventsv2.prg') && We need an object for our events
EVENTHANDLER(this.oAntviewDocument,this.oAvdevents)
endif
* If you allow async methods, edit avdevents.prg to add specific code for each event as required.
* initialise Antview object
thisform.oAntView.Init()
thisform.oAntView.UnlockControl("ExampleCompany","WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F")
lnStatus = thisform.oAntView.UnlockStatus
* set next/previous focus window
thisform.oAntView.NextFocusWindowHandleHwnd = thisform.hwnd
thisform.oAntView.PreviousFocusWindowHandleHwnd = thisform.Hwnd
* connect antview objects
thisform.oAntviewDocument.CurrentBrowser = thisform.oAntView.object
*browse to opening url
thisform.text1.Value = thisform.homeurl
thisform.oAntView.object.navigate(ALLTRIM(thisform.text1.Value))
thisform.Resize
thisform.refresh
There's a bit more in it like how-to unlock the AntView control, navigate and set PreviousFocus/NextFocus attributes.
But the important parts are:
- Create the Document object
* create objects
thisform.oAntviewDocument = CREATEOBJECT('AntViewAx2.AntViewDocument') && create the AntViewDocument and assign it to a form property
- Attach the Event handler
thisform.oAvdEvents = NEWOBJECT('avdeventsv2','avdeventsv2.prg') && We need an object for our events
EVENTHANDLER(this.oAntviewDocument,this.oAvdevents)
- Connect the Document object to the AntView object
* connect antview objects
thisform.oAntviewDocument.CurrentBrowser = thisform.oAntView.object
Once that has been done you are able to use the interface of the document object like so:
thisform.oAntviewDocument.ElementClickByQuerySelector('.printMenuLink')
For all the methods/events and properties available, see AntViewDocument.
AntView - The MS Edge WebView2 ActiveX control Date last changed: 04/16/2025