CommonDialog.HookProc(IntPtr, Int32, IntPtr, IntPtr) メソッド

定義

共通ダイアログ ボックスに特定の機能を追加するためにオーバーライドされる共通ダイアログ ボックス フック プロシージャを定義します。

protected:
 virtual IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
protected virtual IntPtr HookProc(IntPtr hWnd, int msg, IntPtr wparam, IntPtr lparam);
abstract member HookProc : nativeint * int * nativeint * nativeint -> nativeint
override this.HookProc : nativeint * int * nativeint * nativeint -> nativeint
Protected Overridable 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

既定のダイアログ ボックス プロシージャがメッセージを処理する場合は 0 の値。既定のダイアログ ボックス プロシージャがメッセージを無視する場合は、0 以外の値。

次のコード例は、 HookProc メソッドをオーバーライドする方法を示しています。 この例は、 CommonDialog クラスを継承するクラスで構成されています。 クラスの HookProc オーバーライドでは、メソッドの msg パラメーターを特定のWindows メッセージの定数値と比較して評価します。 msg パラメーターが指定した定数と等しい場合は、HookProc メソッドに渡されたWindows メッセージを識別するトレース出力を書き込みます。 この例では、 HookProc メソッドが宣言されているクラスが CommonDialog クラスを継承していることを前提としています。

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 メソッドをオーバーライドすると、オペレーティング システムによって関数のオーバーライドが呼び出され、オペレーティング システム メッセージがウィンドウにポストされます。

既定では、フック プロシージャは、 WM_INITDIALOG メッセージに応答して、画面上のダイアログ ボックスを中央に置きます。

注意 (継承者)

クラスを継承すると、このメソッドをオーバーライドして、特定の機能を共通のダイアログ ボックスに追加できます。 派生クラスで HookProc(IntPtr, Int32, IntPtr, IntPtr) をオーバーライドする場合は、必ず基底クラスの HookProc(IntPtr, Int32, IntPtr, IntPtr) メソッドを呼び出してください。

適用対象