Q: I've built an ActiveX control that can be put in the Internet Explorer. How can I make it send the browser to another URL?
A: Use the HLinkNavigateString function that's part of the WinINet API. This function takes two arguments: a pointer to an COM object and a string that represents the URL to go to.
If you've built an ActiveX control, the COM object to pass for the first parameter is the same object that was generated by the ActiveX control wizard. If you're invoking the HLinkNavigateString function from within a method of this object, you can pass Self as this parameter.
Example:
HLinkNavigateString( Self, 'http://www.borland.com' );
If you're building an ActiveForm, the wizard generates a form class (derived from TActiveForm), but the COM object is actually a standard controller object implemented by TActiveFormControl. From within a method of the form class, you can use the ComObject property to retrieve a pointer to the form's COM controller object.
Example:
HLinkNavigateString( ComObject, 'http://www.borland.com' );
The Microsoft WinINet API also includes functions to cause the browser to move forward or backward in the browser history, as if the user presed the forward or backward buttons. These functions are listed below.
function HlinkGoBack(pUnk: IUnknown): HResult; stdcall; function HlinkGoForward(pUnk: IUnknown): HResult; stdcall;The pUnk parameter in each of these is the same COM object: either Self in the case of an ActiveX control, or ComObject in the case of an ActiveForm.
This sample demonstrates the three kinds of HLink* functions, and also shows how to obtain the Internet Explorer's LocationURL property from the page the ActiveX is embedded into.
API documentation for HLinkNavigateString and other HLink* functions
URL Moniker sample code in C++
Unified Browsing with ActiveX Extensions Brings the Internet to Your Desktop , by Stephen Rauch.