Recent

Author Topic: [SOLVED] Form without borders and title bar  (Read 568 times)

Pe3s

  • Hero Member
  • *****
  • Posts: 641
[SOLVED] Form without borders and title bar
« on: October 26, 2025, 10:04:42 pm »
Hello forum users, if we scale the form without frames on the right side, it scales very nicely, but when we scale it on the left side, the right side of the form jumps, as does the bottom of the form. Can this be corrected so that this effect does not occur?

Code: Pascal  [Select][+][-]
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, Forms, Controls, Graphics, LCLIntf, LCLType, Windows;
  9.  
  10. type
  11.   { TForm1 }
  12.   TForm1 = class(TForm)
  13.     procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
  14.       Shift: TShiftState; X, Y: Integer);
  15.   private
  16.   public
  17.   protected
  18.     procedure CreateParams(var Params: TCreateParams); override;
  19.     procedure WndProc(var Msg: TMessage); override;
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.lfm}
  28.  
  29. const
  30.   Margin = 30;
  31.  
  32. { TForm1 }
  33.  
  34. procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  35.   Shift: TShiftState; X, Y: Integer);
  36. begin
  37.   if Button = mbLeft then
  38.   begin
  39.     ReleaseCapture;
  40.     SendMessage(Handle, WM_SYSCOMMAND, SC_MOVE + $2, 0);
  41.   end;
  42. end;
  43.  
  44. procedure TForm1.CreateParams(var Params: TCreateParams);
  45. begin
  46.   inherited CreateParams(Params);
  47.   BorderStyle := bsNone;
  48.   Params.Style := Params.Style or WS_THICKFRAME;
  49.   Params.ExStyle := Params.ExStyle or WS_EX_COMPOSITED;
  50. end;
  51.  
  52. procedure TForm1.WndProc(var Msg: TMessage);
  53. var
  54.   P: TPoint;
  55. begin
  56.   case Msg.Msg of
  57.     WM_NCHITTEST:
  58.       begin
  59.         P.X := GET_X_LPARAM(Msg.LParam);
  60.         P.Y := GET_Y_LPARAM(Msg.LParam);
  61.         P := ScreenToClient(P);
  62.  
  63.         if (P.Y < Margin) and (P.X < Margin) then
  64.           Msg.Result := HTTOPLEFT
  65.         else if (P.Y < Margin) and (P.X >= ClientWidth - Margin) then
  66.           Msg.Result := HTTOPRIGHT
  67.         else if (P.Y >= ClientHeight - Margin) and (P.X < Margin) then
  68.           Msg.Result := HTBOTTOMLEFT
  69.         else if (P.Y >= ClientHeight - Margin) and (P.X >= ClientWidth - Margin) then
  70.           Msg.Result := HTBOTTOMRIGHT
  71.         else
  72.         begin
  73.           inherited WndProc(Msg); // reszta pozostaje standardowa
  74.           Exit;
  75.         end;
  76.         Exit;
  77.       end;
  78.  
  79.     WM_ENTERSIZEMOVE:
  80.       begin
  81.         SendMessage(Handle, WM_SETREDRAW, 0, 0);
  82.         inherited;
  83.         Exit;
  84.       end;
  85.  
  86.     WM_EXITSIZEMOVE:
  87.       begin
  88.         SendMessage(Handle, WM_SETREDRAW, 1, 0);
  89.         Invalidate; // LCL
  90.         inherited;
  91.         Exit;
  92.       end;
  93.   end;
  94.  
  95.   inherited WndProc(Msg);
  96. end;
  97.  
  98. end.
  99.  
  100.  
« Last Edit: October 28, 2025, 06:54:10 pm by Pe3s »

jamie

  • Hero Member
  • *****
  • Posts: 7599
Re: Form without borders and title bar
« Reply #1 on: October 26, 2025, 11:44:29 pm »
Its windows, just about everything on my desktop does that when sizing the left side.

Its the slow update to the screen, $MS does not put a lot of attention on screen updates.

I just checked my browser, and couple of other apps on Win10. They all do it.

Jamie
The only true wisdom is knowing you know nothing

Pe3s

  • Hero Member
  • *****
  • Posts: 641
Re: Form without borders and title bar
« Reply #2 on: October 27, 2025, 10:07:50 pm »
Thank you for the explanation. I have another problem, namely, on the form I have an MPVPlayer component set to allClient, and resize does not work. How can I fix this?

 

TinyPortal © 2005-2018