WebViewEventProc Function  
 
VOID CALLBACK WebViewEventProc(
  HWND hWndHost,  
  UINT uEventId,  
  WPARAM wParam,  
  LPARAM lParam,  
  DWORD_PTR dwParam  
);

The WebViewEventProc function is an application-defined callback function that processes events generated by the browser.

Parameters

hWndHost
Handle to the client session.
uEventId
An unsigned integer which specifies which event occurred. For a complete list of events, refer to the Events documentation.
wParam
An integer value that depends on the event context. This value is commonly used by an event to indicate success (1) or failure (0). It may also be used to indicate a transition in state. Refer to the events documentation for information about how this parameter may be used by a specific event.
lParam
An integer value that depends on the event context. This value is commonly used by an event to provide a status code or error code, depending whether the operation which raised the event succeeded or failed. Refer to the events documentation for information about how this parameter may be used by a specific event.
dwParam
A user-defined integer value which was provided when the event callback was specified. This is typically used to provide additional context to the event or associate the event with a specific object. If this user-defined parameter was not specified when the browser window was attached or created, this value will be zero.

Return Value

None.

Remarks

The class invokes the callback function whenever an event occurs. Applications are not required to implement event handlers for each event, and may choose to not provide any event handlers by passing NULL as the callback function parameter. A minimal implementation would typically create handlers for the WEBVIEW_EVENT_NAVIGATION_STARTING event which notifies the application when the browser is beginning to navigate to a new location, and the WEBVIEW_EVENT_NAVIGATION_COMPLETED event which indicates the navigation has completed.

When you attach a browser instance to an existing window, the callback function is always invoked on the same UI thread that owns that window, ensuring events are processed in the context of the caller's thread. However, if you create a new browser window using the Create method, a different thread manages the top-level window and message loop, and in that case the callback function is invoked on the thread that owns the browser window rather than the thread that created it. This distinction is important when your application accesses shared data or resources from within the event handler. To avoid race conditions or undefined behavior, ensure that access to shared state is synchronized using mutexes, critical sections, or other appropriate synchronization primitives.

It is important to keep event handlers responsive. Because events are raised on the UI thread, long-running work in an event handler can block the user interface and stall navigation. Where possible, defer heavy operations to background threads. Avoid displaying modal dialogs or message boxes from within event handlers. Also note that some events may fire multiple times during a single navigation. For example, the security state can transition through several levels (unknown, neutral, secure, or warning) before settling on a final value. Applications should be written to handle these changes incrementally.

After the browser has been attached to a window, it is possible to change the event handler using the EnableEvents function. This changes the event handler for the browser instance, and from that point forward all event notifications will be routed to the new handler.

When defining an event handler within a C++ class, the event callback must be declared as a static function with the __stdcall calling convention. This is required because the library calls the handler just as it would with any Win32 API callback function, without knowledge of C++ instance objects. Non-static member functions include a hidden this pointer parameter, which makes their signature incompatible with the expected WEBVIEWEVENTPROC type. A common pattern is to pass the object's this pointer as the dwParam value, then cast it back inside the static callback function to access the instance. This preserves object-oriented design while still meeting the calling convention requirements of the API.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib

See Also