Home > Back-end >  How do I add borders to window
How do I add borders to window

Time:10-08

 unit Unit1; 
//download by http://www.codefans.net
Interface

USES the
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,

Type
TForm1=class (TForm)
Private
Procedure WMNCPaint (var Msg: TWMNCPaint); The message WM_NCPAINT;
{Private declarations}
Public
{Public declarations}
end;

Var
Form1: TForm1;

Implementation

{$R *. DFM}

{TForm1}

Procedure TForm1. WMNCPaint (var Msg: TWMNCPaint);
Var
Dc: hDc.
Pen: hPen;
OldPen: hPen;
OldBrush: hBrush;
The begin
Inherited;
Dc:=GetWindowDC (Handle);
MSG. Result:=1;

Pen:=CreatePen (PS_SOLID, 3, RGB (255, 0, 0));
OldPen:=SelectObject (dc, Pen);
OldBrush:=SelectObject (dc, GetStockObject (NULL_BRUSH));
A Rectangle (dc, 0, 0, Form1. Width, Form1, Height);
SelectObject (dc, OldBrush);
SelectObject (dc, OldPen);

DeleteObject (Pen).
ReleaseDC (Handle, Canvas. Handle);
end;

End.


The code above delphi2010 compiled in Windows 7 doesn't work, for help how to do

CodePudding user response:

The building Lord to find some information to draw the the news of the client area is that!

CodePudding user response:

In the event of an OnPaint draw a rectangle

CodePudding user response:

I put my code:
Procedure TForm1. WMNCPaint (var Message: TWMNCPaint);
The begin
DrawTitle;
Message. The Result:=1;
end;

Procedure TForm1. WMNCCALCSIZE (var MSG: TMessage);
The begin
With TWMNCCALCSIZE (MSG). CalcSize_Params ^ do
The begin
Inc (RGRC [0] Left, CFRAMEW);
Inc (RGRC [0]. Top CTITLEHEIGTH);
Dec (RGRC [0]. Right, CFRAMEW);
Dec (RGRC [0]. Bottom, CFRAMEW);
end;
MSG. Result:=0;
Inherited;
end;

Procedure TForm1. DrawCaption;
Var
CaptionBmp: TBitmap;
DC: HDC.
C: TCanvas;
R: TRect;
Style: DWORD;
The begin
C:=TCanvas. Create;
DC:=GetWindowDC (Handle);
Try
C. andle:=DC;
Mount rush. Color:=FColor;
C.F illRect (the Rect (0, 0, Width, CTITLEHEIGTH));//title
Mount rush. Color:=FColor;
C.F illRect (the Rect (0, 0, CFRAMEW, Height));//the left
Mount rush. Color:=FColor;
C.F illRect (the Rect (Width - CFRAMEW, 0, Width, Height));//right
Mount rush. Color:=FColor;
C.F illRect (the Rect (0, Height - CFRAMEW, Width, Height));//bottom
The finally
C.F ree;
ReleaseDC (Handle, DC);
end;
end;
You can draw frame basic process these messages!

CodePudding user response:

DrawTitle; Is amended as: DrawCaption

CodePudding user response:

Const
CFRAMEW=2;
CTITLEHEIGTH=50;
CHITTESTWIDTH=1;//reserve HitTest thickness

These are constants

CodePudding user response:

Procedure TFMain. DrawLine;
Var
Dc: hDc.
Pen: hPen;
OldPen: hPen;
OldBrush: hBrush;
The begin
Dc:=GetWindowDC (Handle);
Self. Refresh;
Pen:=CreatePen (PS_SOLID, 1, RGB (0, 0, 200));
OldPen:=SelectObject (dc, Pen);
OldBrush:=SelectObject (dc, GetStockObject (NULL_BRUSH));
RoundRect (dc, 0, 0, Width 1,,10,10 Height - 1);
SelectObject (dc, OldBrush);
SelectObject (dc, OldPen);
DeleteObject (Pen).
Pen:=CreatePen (PS_SOLID, 1, RGB (137, 245, 255));
OldPen:=SelectObject (dc, Pen);
OldBrush:=SelectObject (dc, GetStockObject (NULL_BRUSH));
RoundRect (dc, 1, 1, Width - 2, Height - 2,10,10);
SelectObject (dc, OldBrush);
SelectObject (dc, OldPen);
DeleteObject (Pen).
ReleaseDC (Handle, Canvas. Handle);
end;
  • Related