« Blog Home

§ Borderless window resizing with WM_NCHITTEST

Want to have a borderless window that can be resized like a normal window?  Use WM_NCHITTEST.


procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
procedure TForm2.WMNCHitTest(var Message: TWMNCHitTest);
  EDGEDETECT = 7;  //adjust to suit yourself
  deltaRect: TRect;  //not really used as a rect, just a convenient structure
  if BorderStyle = bsNone then
    with Message, deltaRect do begin
      Left := XPos - BoundsRect.Left;
      Right := BoundsRect.Right - XPos;
      Top := YPos - BoundsRect.Top;
      Bottom := BoundsRect.Bottom - YPos;
      if (Top<EDGEDETECT)and(Left<EDGEDETECT) then
        Result := HTTOPLEFT
      else if (Top<EDGEDETECT)and(Right<EDGEDETECT) then
        Result := HTTOPRIGHT
      else if (Bottom<EDGEDETECT)and(Left<EDGEDETECT) then
        Result := HTBOTTOMLEFT
      else if (Bottom<EDGEDETECT)and(Right<EDGEDETECT) then
        Result := HTBOTTOMRIGHT
      else if (Top<EDGEDETECT) then
        Result := HTTOP
      else if (Left<EDGEDETECT) then
        Result := HTLEFT
      else if (Bottom<EDGEDETECT) then
        Result := HTBOTTOM
      else if (Right<EDGEDETECT) then
        Result := HTRIGHT
    end;  //with Message, deltaRect; if BorderStyle = bsNone

That's it!  Now Windows will take care of the resizing arrows and the resizing as you drag the edges.


last edited on May 7th, 2010 at 6:36 PM


No Comments Here. Add yours below!

Add your comment

Email: (Will not be displayed - Privacy policy)
  random image I can't read it!
Give me a different one!
Verify Post: Input the text from the image above to verify this post (helps prevent spam)

« Blog Home

The abbot shook his head.  “Michael and the others went too far when they went to the Kaiser.  It is not for us to order the affairs of kings, but to care for the poor and lowly.”
“That,” said Dietrich, “may require you to order the affairs of kings.”
an abbot & Dietrich, Eifelheim, Michael Flynn