Search code examples
c#winformswinapiwndproc

New to C#-would like to add WndProc


Everyone, I am just so new to C#, please help me...

I would like to add WndProc to process messages, I have look into properties but I don't see the thunderbolt to display function name so I can add one I like. I search the internet and see WndProc as

protected override void WndProc(ref Message msg) 
{
   //do something
}

I would like it to be generated for me, not to type it down ?


Solution

  • WndProc is not a .NET event handler; it's a window procedure, part of the native Win32 API. You won't get any code generation for it as an event handler in Visual Studio.

    In Windows Forms all you have to do is override a form's existing WndProc() method and start coding. As it's found in the Form class, there is an autocomplete option for it if you type the following:

    override WndProc
    

    which then generates:

        protected override void WndProc(ref Message m)
        {
            base.WndProc(ref m);
        }