Question

In c#, I can "hijack" the WndProc of a window within the same process as the executing code, using the NativeWindow class, giving me the capability to override certain messages and let others pass.

Here is an example:

protected override void WndProc(ref Message m)
{
    switch (m.Msg)
    {
        case WM_ENABLE:
            //do default thing
            base.WndProc(ref m);
            //then do my thing
            break;
        case WM_PAINT:
            //don't even call base.WndProc, I'll handle painting.
            break;
        default:
            //all other messages...
            base.WndProc(ref m);
            break;
    }
}

How can I accomplish the same thing in a c++ Win32 application? I'm not even sure where to start or what the correct term is.

Was it helpful?

Solution

You can use a WindowProc callback in C++ for any HWND.

For full details and options (there are quite a few ways to do this in the WIndows API), see Using Windows Procedures. The closest to your C# option would be to Subclass a Window. Note that the new, improved mechanism to subclass a Window is to use SetWindowSubclass.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top