Help Center

CAxHost.Constructorconstructor

Creates an instance of the OLE container using a ProgId.

COMconstructorCaxHost.incdocumented

Syntax

CONSTRUCTOR CAxHost (BYVAL pWindow AS CWindow PTR, BYVAL cID AS LONG_PTR, BYREF wszProgID AS WSTRING, BYVAL x AS LONG = 0, BYVAL y AS LONG = 0, BYVAL nWidth AS LONG = 0, BYVAL nHeight AS LONG = 0, BYVAL dwStyle AS DWORD = 0, BYVAL dwExStyle AS DWORD = 0, BYVAL pAmbientDisp AS CAXHOST_AMBIENTDISP PTR = NULL)
CONSTRUCTOR CAxHost (BYVAL pWindow AS CWindow PTR, BYVAL cID AS INTEGER, BYREF wszProgID AS WSTRING, BYREF wszLicKey AS WSTRING, BYVAL x AS LONG = 0, BYVAL y AS LONG = 0, BYVAL nWidth AS LONG = 0, BYVAL nHeight AS LONG = 0, BYVAL dwStyle AS DWORD = 0, BYVAL dwExStyle AS DWORD = 0, BYVAL pAmbientDisp AS CAXHOST_AMBIENTDISP PTR = NULL)

Parameters

NameDescription
pWindowPointer to the instance of the CWindow class used to create the form.
cIDThe identifier of the control. It must be unique.
wszProgIDThe ProgID of the object to create, such "MSCAL.Calendar".
wszLicKeyThe license key of the control, if the control is licensed.
x, yThe coordinates of the upper-left corner of the window relative to the upper-left corner of the parent window's client area.
nWidthThe width of the window.
nHeightThe height of the window.
dwStyleThe style of the window being created.
dwExStyleThe extended style of the window being created.
pAmbientDispPointer to a CAXHOST_AMBIENTDISP structure.

Description

Creates an instance of the OLE container using a ProgId.

Examples

#define UNICODE #include once "AfxNova/DVARIANT.inc" #INCLUDE ONCE "AfxNova/CWindow.inc" #include once "AfxNova/CAxHost.inc" USING AfxNova

DECLARE FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _

BYVAL hPrevInstance AS HINSTANCE, _
                       BYVAL pwszCmdLine AS WSTRING PTR, _
                       BYVAL nCmdShow AS LONG) AS LONG

END wWinMain(GetModuleHandleW(NULL), NULL, wCommand(), SW_NORMAL)

' // Forward declaration DECLARE FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

CONST IDC_WEBBROWSER = 1001

' ======================================================================================== ' Main ' ======================================================================================== FUNCTION wWinMain (BYVAL hInstance AS HINSTANCE, _

BYVAL hPrevInstance AS HINSTANCE, _
               BYVAL pwszCmdLine AS WSTRING PTR, _
               BYVAL nCmdShow AS LONG) AS LONG

' // Set process DPI aware SetProcessDpiAwareness(PROCESS_SYSTEM_DPI_AWARE) ' // Enable visual styles without including a manifest file AfxEnableVisualStyles

' // Creates the main window DIM pWindow AS CWindow = "MyClassName" ' Use the name you wish DIM hWin AS HWND = pWindow.Create(NULL, "CWindow - CAxHost -WebBrowser", @WndProc) ' // Sizes it by setting the wanted width and height of its client area pWindow.SetClientSize(900, 450) ' // Centers the window pWindow.Center

' // Create an instance of the WebBrowser control DIM pHost AS CAxHost = CAxHost(@pWindow, IDC_WEBBROWSER, "Shell.Explorer", 0, 0, pWindow.ClientWidth, pWindow.ClientHeight) ' // Get a direct pointer to the Afx_IWebBrowser2 interface DIM hWb AS HWND = GetDlgItem(pWindow.hWindow, IDC_WEBBROWSER) DIM pWb AS Afx_IWebBrowser2 PTR = CAST(ANY PTR, AfxCAxHostDispPtr(hWb)) IF pWb THEN

DIM dvUrl AS DVARIANT = "http://www.jose.it-berater.org/index.html"
  DIM hr AS HRESULT = pWb->Navigate2(dvUrl, NULL, NULL, NULL, NULL)

END IF

' // Displays the window and dispatches the Windows messages FUNCTION = pWindow.DoEvents(nCmdShow)

END FUNCTION ' ========================================================================================

' ======================================================================================== ' Main window procedure ' ======================================================================================== FUNCTION WndProc (BYVAL hwnd AS HWND, BYVAL uMsg AS UINT, BYVAL wParam AS WPARAM, BYVAL lParam AS LPARAM) AS LRESULT

SELECT CASE uMsg

' // If an application processes this message, it should return zero to continue
  ' // creation of the window. If the application returns –1, the window is destroyed
  ' // and the CreateWindowExW function returns a NULL handle.
  CASE WM_CREATE
     RETURN 0

  ' // Sent when the user selects a command item from a menu, when a control sends a
  ' // notification message to its parent window, or when an accelerator keystroke is translated.
  CASE WM_COMMAND
     SELECT CASE CBCTL(wParam, lParam)
        CASE IDCANCEL
           ' // If ESC key pressed, close the application by sending an WM_CLOSE message
           IF CBCTLMSG(wParam, lParam) = BN_CLICKED THEN SendMessageW(hwnd, WM_CLOSE, 0, 0)
     END SELECT
     RETURN 0

  CASE WM_DESTROY
     ' // End the application by sending an WM_QUIT message
     PostQuitMessage(0)
     RETURN 0

END SELECT

' // Default processing of Windows messages FUNCTION = DefWindowProcW(hwnd, uMsg, wParam, lParam)

END FUNCTION ' ========================================================================================

The following example embeds an instance of the WebBrowser control and navigates to a site:

Reference

  • Include file CaxHost.inc
  • Defined in AfxNova/CAxHost.inc:206
  • Documented in COM/CAxHost Class.md
  • Topic: CAxHost Class