question

Wami007-9389 avatar image
0 Votes"
Wami007-9389 asked JeanineZhang-MSFT commented

C++/CLI Make Borderless Form Sizeable

Hello , how can I convert this c# code to C++/CLI code to make my borderless form SizeAble?

   this->SetStyle(ControlStyles::ResizeDraw, true);

private const int cGrip=16;
private const int cCaption=32;

protected override void WndProc (ref Message m)
{
if (m.Msg==0x84)
{
Point pos = new Point(m.LParam.ToInt32());
pos = this.PointToClient (pos);

 if(pos.Y < cCaption) 

{
m.Result = (IntPtr)2;
return;
}
if (pos.X >= this.ClientSize.Width - cGrip && pos.Y >= this.ClientSize.Heigh - cGrip)
{
m.Result = (IntPtr)17;
return;
}
}


base.WndProc(ref m);

}



dotnet-csharpc++dotnet-runtime
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered JeanineZhang-MSFT commented

Try adding this code to your form class:

 #include <Windows.h>
    
 . . .
    
    
 private:
    
     const int cGrip = 16;
     const int cCaption = 32;
    
 protected:
     void WndProc( Message% m ) override
     {
         switch( m.Msg )
         {
         case WM_NCHITTEST:
             Point pos = Point( m.LParam.ToInt32( ) );
             pos = PointToClient( pos );
    
             if( pos.Y < cCaption )
             {
                 m.Result = IntPtr( HTCAPTION );
                 return;
             }
             if( pos.X >= ClientSize.Width - cGrip && pos.Y >= ClientSize.Height - cGrip )
             {
                 m.Result = IntPtr( HTBOTTOMRIGHT );
                 return;
             }
             break;
         }
    
         __super::WndProc( m );
     }
    
 . . .

· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

 Good Job, Works just like a charm ;) , Thanks...
0 Votes 0 ·

Do you know any way to using native C++ code in C++/CLi ? i can Include <iostream> but can't write Cout (

0 Votes 0 ·

@Wami007-9389

I suggest you could try to use #pragma unmanaged. For more details, I suggest you could refer to the link: https://docs.microsoft.com/en-us/cpp/preprocessor/managed-unmanaged?view=msvc-160


1 Vote 1 ·