Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Processing a Native Window Message Inside a Non-visual Class (See related posts)

Say you have a dynamic library and you want to treat a native window message inside any non-visual class in that library.
Derive this class from NativeWindow as shown below. After creating the new class from Class1, you can pass the Handle (like IntPtr) of this class to any native function.

public class Class1: NativeWindow
{
        CreateParams cp = new CreateParams();

        public Class1()
        {
                // Create the actual window
                this.CreateHandle(cp);
        }

        protected override void WndProc(ref Message m)
        {
                if(m.Msg == WM_...)
                {
                        // Do something here in response to messages
                        return;
                }
                base.WndProc(ref m);
        }

}

You need to create an account or log in to post comments to this site.


Related Posts