tags:

views:

1887

answers:

4

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

A: 

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

kenny
I understood the SetWindowLong part. I was asking about how to call the original winproc.
Corey Trager
+1  A: 

Did you see this MSDN article?

http://support.microsoft.com/kb/815775

Martin Brown
That's subclassing in the .NET inheritence sense, not the Windows API sense.
Corey Trager
+2  A: 

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
Before calling the default proc, he wants to call the previous user proc pointed to by oldWndProc.
Martin Plante
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
Actually, I"m calling the WIN32 function CallWindowProc
Corey Trager
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
+1  A: 

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