C++/CLI Make Borderless Form Sizeable

Wami007 296 Reputation points
2021-03-31T20:51:20.597+00:00

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);
  }
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,022 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,762 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,167 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 118.1K Reputation points
    2021-03-31T21:15:40.757+00:00

    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 );
        }
    
    . . .
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.