Export (0) Print
Expand All

FontDialog.HookProc Method

Specifies the common dialog box hook procedure that is overridden to add specific functionality to a common dialog box.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.UnmanagedCode)]
protected override IntPtr HookProc(
	IntPtr hWnd,
	int msg,
	IntPtr wparam,
	IntPtr lparam
)

Parameters

hWnd
Type: System.IntPtr

The handle to the dialog box window.

msg
Type: System.Int32

The message being received.

wparam
Type: System.IntPtr

Additional information about the message.

lparam
Type: System.IntPtr

Additional information about the message.

Return Value

Type: System.IntPtr
A zero value if the default dialog box procedure processes the message; a nonzero value if the default dialog box procedure ignores the message.

A hook procedure is a mechanism by which a function can intercept events before they reach an application. When you override the CommonDialog.HookProc method for a CommonDialog class, the operating system invokes your override of the function to post operating system messages to the window.

Notes to Inheritors

When overriding HookProc in a derived class, be sure to call the base class's HookProc method.

The following code example demonstrates how to override the HookProc method. The example consists of a class that inherits the FontDialog class. In the class's HookProc override, the example evaluates the method's msg parameter against constant values for particular Windows messages. If the msg parameter equals the specified constant, the example writes trace output identifying the Windows message that was passed to the HookProc method. This example requires that the class in which the HookProc method is declared inherits the FontDialog class.


// Defines the constants for Windows messages. 

const int WM_SETFOCUS = 0x0007;
const int WM_INITDIALOG = 0x0110;
const int WM_LBUTTONDOWN = 0x0201;
const int WM_RBUTTONDOWN = 0x0204;
const int WM_MOVE = 0x0003;

// Overrides the base class hook procedure...
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name="FullTrust")] 
protected override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
{

	// Evaluates the message parameter to determine the user action. 

	switch(msg)
	{

		case WM_INITDIALOG:
			System.Diagnostics.Trace.Write("The WM_INITDIALOG message was received.");
			break;
		case WM_SETFOCUS:
			System.Diagnostics.Trace.Write("The WM_SETFOCUS message was received.");
			break;
		case WM_LBUTTONDOWN:
			System.Diagnostics.Trace.Write("The WM_LBUTTONDOWN message was received.");
			break;
		case WM_RBUTTONDOWN:
			System.Diagnostics.Trace.Write("The WM_RBUTTONDOWN message was received.");
			break;
		case WM_MOVE:
			System.Diagnostics.Trace.Write("The WM_MOVE message was received.");
			break;

	}

	// Always call the base class hook procedure. 

	return base.HookProc(hWnd, msg, wParam, lParam);

}

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft