CWebView::EnableEvents Method  
 
BOOL EnableEvents(
  WEBVIEWEVENTPROC lpEventProc,  
  DWORD_PTR dwParam  
);

The EnableEvents method enables event handling for the browser.

Parameters

lpEventProc
A callback function which will be invoked whenever browser events occur. This parameter cannot be NULL. The callback function will be invoked in the context of a separate thread which hosts the browser control, not the thread which calls this method. For more information, refer to the WebViewEventProc and Events documentation.
dwParam
An optional parameter which can be used to provide additional context to the event handler. This user-defined value is passed back to the callback function when an event occurs. If this information is not required, this parameter can be zero.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The EnableEvents method assigns or replaces the callback function that receives browser events for the specified host window. It can be used after the browser has been attached to start receiving notifications or to change event handlers at runtime. The change takes effect immediately and subsequent events will be invoked using the new handler.

Event delivery is serialized by the library and this call safely updates the event handler. You cannot specify a NULL pointer as the event handler; if you need to disable events, use the DisableEvents method. If events were previously frozen with FreezeEvents, calling this method with a new event handler will automatically unfreeze event notifications.

When using this method from within a C++ class, the event callback must be declared as a static function with the __stdcall (or CALLBACK) 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