2

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

oldWndProc = SetWindowLong(HandleOfCbEditControl, GWL_WNDPROC, newWndProc);

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?***
         }

    }

EDIT: 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#.

Corey Trager
  • 22,649
  • 18
  • 83
  • 121

3 Answers3

2

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"...] public static extern int CallWindowProc(int previousProc, int nativeControlHandle, int msg, int lParam, int wParam);

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

ctacke
  • 66,480
  • 18
  • 94
  • 155
  • Before calling the default proc, he wants to call the previous user proc pointed to by oldWndProc. – Martin Plante Oct 14 '08 at 13:15
  • Thanks for the tip that int, uint, and IntPtr are all identical. I learned that by stumbling around before I read your comment, but your comment is comforting that I was doing the right thing. – Corey Trager Oct 14 '08 at 13:17
  • Actually, I"m calling the WIN32 function CallWindowProc – Corey Trager Oct 14 '08 at 13:18
  • 2
    int, uint, and IntPtr are only identical under x86 (32 bit). On a x64 platform, IntPtr is 64 bit, while the others are 32 bit. – Joel Lucsy Oct 14 '08 at 15:10
1

You should use CallWindowProc to call that oldWndProc pointer.

[DllImport("user32")]
private static extern int CallWindowProc(IntPtr lpPrevWndFunc, IntPtr hWnd, int Msg, int wParam, int lParam);
Martin Plante
  • 4,553
  • 3
  • 33
  • 45
0

This site will be very helpful with all of your interop/p-invoke efforts (SetWindowLong)

kenny
  • 21,522
  • 8
  • 49
  • 87