FontDialog.HookProc(IntPtr, Int32, IntPtr, IntPtr) 方法

定义

指定为将特定功能添加到通用对话框而重写的通用对话框挂钩程序。

protected:
 override IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
protected override IntPtr HookProc (IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
override this.HookProc : nativeint * int * nativeint * nativeint -> nativeint
Protected Overrides Function HookProc (hWnd As IntPtr, msg As Integer, wparam As IntPtr, lparam As IntPtr) As IntPtr

参数

hWnd
IntPtr

nativeint

对话框窗口的句柄。

msg
Int32

正在接收的消息。

wparam
IntPtr

nativeint

关于消息的附加信息。

lparam
IntPtr

nativeint

关于消息的附加信息。

返回

IntPtr

nativeint

如果默认对话框过程处理此消息,则为零值;如果默认对话框过程忽略此消息,则为非零值。

示例

下面的代码示例演示如何重写 HookProc 该方法。 该示例由继承类的 FontDialog 类组成。 在类的HookProc重写中,此示例针对特定Windows消息的msg常量值计算方法的参数。 msg如果参数等于指定的常量,该示例将写入跟踪输出,标识传递给HookProc该方法的Windows消息。 此示例要求声明该方法的 HookProc 类继承该 FontDialog 类。

private:
   // Defines the constants for Windows messages.
   literal int WM_SETFOCUS = 0x0007;
   literal int WM_INITDIALOG = 0x0110;
   literal int WM_LBUTTONDOWN = 0x0201;
   literal int WM_RBUTTONDOWN = 0x0204;
   literal int WM_MOVE = 0x0003;

protected:
   // Overrides the base class hook procedure...
   [SecurityPermission(SecurityAction::Demand, Flags=SecurityPermissionFlag::UnmanagedCode)] 
   virtual IntPtr HookProc( IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam ) override
   {
      // Evaluates the message parameter to determine the user action.
      #if defined(TRACE)
      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;
      }
      #endif
     
      // Always call the base class hook procedure.
      return FontDialog::HookProc( hWnd, msg, wParam, lParam );
   }

// 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...
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);
}
    ' Defines the constants for Windows messages.

    Const WM_SETFOCUS = &H7
    Const WM_INITDIALOG = &H110
    Const WM_LBUTTONDOWN = &H201
    Const WM_RBUTTONDOWN = &H204
    Const WM_MOVE = &H3
<System.Security.Permissions.PermissionSetAttribute(System.Security.Permissions.SecurityAction.Demand, Name:="FullTrust")> _
    Protected Overrides Function HookProc(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr


        ' Evaluates the message parameter to determine the user action.

        Select Case msg

            Case WM_INITDIALOG
                System.Diagnostics.Trace.Write("The WM_INITDIALOG message was received.")
            Case WM_SETFOCUS
                System.Diagnostics.Trace.Write("The WM_SETFOCUS message was received.")
            Case WM_LBUTTONDOWN
                System.Diagnostics.Trace.Write("The WM_LBUTTONDOWN message was received.")
            Case WM_RBUTTONDOWN
                System.Diagnostics.Trace.Write("The WM_RBUTTONDOWN message was received.")
            Case WM_MOVE
                System.Diagnostics.Trace.Write("The WM_MOVE message was received.")

        End Select

        ' Always call the base class hook procedure.

        Return MyBase.HookProc(hWnd, msg, wParam, lParam)

    End Function

注解

挂钩过程是一种机制,函数可以在事件到达应用程序之前截获事件。 重写CommonDialog.HookProc类的方法CommonDialog时,操作系统将调用函数的重写,以将操作系统消息帖子窗口。

继承者说明

HookProc(IntPtr, Int32, IntPtr, IntPtr) 派生类中重写时,请务必调用基类 HookProc(IntPtr, Int32, IntPtr, IntPtr) 的方法。

适用于

另请参阅