What causes my borderless C++/CLI app to crash when overriding WndProc?

Posted by Ste on Stack Overflow See other posts from Stack Overflow or by Ste
Published on 2010-12-24T23:31:31Z Indexed on 2010/12/25 4:54 UTC
Read the original article Hit count: 296

Filed under:
|
|
|

I use a form with border NONE. I need to override WndProc for resize and move form. However, using this code, my app crashes!

 static const int WM_NCHITTEST = 0x0084;
 static const int HTCLIENT = 1;
 static const int HTCAPTION = 2;

 protected: virtual void Form1::WndProc(System::Windows::Forms::Message %m) override 
 {        
     switch (m.Msg)
     {
         case WM_NCHITTEST:
             if (m.Result == IntPtr(HTCLIENT))
             {
                 m.Result = IntPtr(HTCAPTION);
             }
             break;
     }
     Form1::WndProc(m);
 }       


virtual System::Windows::Forms::CreateParams^ get() override
{

    System::Windows::Forms::CreateParams^ cp = __super::CreateParams;
    cp->Style |= 0x40000; 
    return cp;
}

How can I fix my code not to crash but still allow my form to be moved and resized?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about winforms