在C#中,我有一个的IntPtr到Win32的WndProc。什么是语法调用它?我有一个、语法、IntPtr、WndProc

2023-09-04 23:05:56 作者:不如相忘于江湖

我在子类本机窗口(组合框的编辑控件...)

I'm subclassing a native window (the edit control of a combobox...)

oldWndProc = SetWindowLong函数(HandleOfCbEditControl,GWL_WNDPROC,newWndProc);

oldWndProc = SetWindowLong(HandleOfCbEditControl, GWL_WNDPROC, newWndProc);

在我的子类的WndProc,我将有code这样的,正确的,但我不能找出语法调用oldWndProc。

In my subclassing wndproc, I'll have code like this, right, but I can't figure out the syntax for calling the oldWndProc.

    int MyWndProc(int Msg, int wParam, int lParam)
    {
         if (Msg.m ==  something I'm interested in...)
         {
              return something special
         }
         else
         {
              return result of call to oldWndProc  <<<<   What does this look like?***
         }

    }

编辑:在这个问题的话子类化指的是Win32 API的意义,而不是C#。子类在这里并不意味着压倒一切的。NET基类的行为。这意味着告诉WIN32调用Windows当前回调的函数指针来代替。它无关的传承在C#。

The word "subclassing" in this question refers to the WIN32 API meaning, not C#. Subclassing here doesn't mean overriding the .NET base class behavior. It means telling WIN32 to call your function pointer instead of the windows current callback. It has nothing to do with inheritence in C#.

推荐答案

您会打电话的 CallWindowProc的通过P /调用。只要定义参数INT变量(因为它看起来像你如何在调用SetWindowLong调用中定义他们的),所以是这样的:

You'll call CallWindowProc by P/Invoke. Just define the parameters as int variables (as it looks like that's how you defined them in the SetWindowLong call), so something like this:

[的DllImport(CallWindowProc的...] 公共静态外部INT CallWindowProc的(INT previousProc,INT nativeControlHandle,诠释味精,诠释lParam的,诠释的wParam);

[DllImport("CallWindowProc"...] public static extern int CallWindowProc(int previousProc, int nativeControlHandle, int msg, int lParam, int wParam);

记住,对于编组,INT,UINT和IntPtr的都是相同的。

Remember, that for marshaling, int, uint and IntPtr are all identical.

 
精彩推荐
图片推荐