1 SetWindowLong(Handle, GWL_EXSTYLE, GetWindowLong(Handle, GWL_EXSTYLE) or WS_EX_RIGHT);
2.procedure CreateParams(var Params:TCreateParams);override;
procedure TForm1.CreateParams(var Params:TCreateParams);
begin
inherited;
Params.Style:=Params.Style+WS_EX_RIGHT;
end;
3.var
Dc: HDC;
R: TRect;
begin
Dc := GetWindowDC(Handle);
R := Rect(2, 2, Width - 4, Height - ClientHeight);
SetBkMode(Dc, TRANSPARENT);
SetTextColor(Dc, clWhite);
Windows.DrawText(Dc, PChar('dd'), -1, R, DT_VCENTER or DT_EDITCONTROL or DT_WORDBREAK);
end;
DT_VCENTER 居中
DT_RIGHT 居右
DT_Left 居左
用API不能居中显示的
4.下面的代码不仅可以使标题栏文字从随意位置(本例为30,你可以调整它),而且还可以改标题字体,样式等。
希望对楼主有所帮助!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
procedure WMNCPaint(var Msg: TMessage);message wm_ncpaint;
procedure WMActivate(var Msg: TWMActivate);message wm_activate;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.WMActivate(var Msg: TWMActivate);
begin
inherited;
PostMessage(Form1.Handle, WM_NCPAINT, 0, 0);
end;
procedure TForm1.WMNCPaint(var Msg: TMessage);
var
WinDC: HDC;
OldFont: HFONT;
begin
inherited;
WinDC := GetWindowDC(Form1.Handle);
Canvas.Font.Height := GetSystemMetrics(SM_CYCAPTION)-4;
Canvas.Font.Name := 'Times New Roman';
Canvas.Font.Style := [fsBold, fsItalic];
OldFont := SelectObject(WinDC, Canvas.Font.Handle);
if GetActiveWindow=0 then
begin
SetBkColor(WinDC, GetSysColor(COLOR_INACTIVECAPTION));
SetTextColor(WinDC, GetSysColor(COLOR_INACTIVECAPTIONTEXT));
end
else
begin
SetBkColor(WinDC, GetSysColor(COLOR_ACTIVECAPTION));
SetTextColor(WinDC, GetSysColor(COLOR_CAPTIONTEXT));
end;
SetBkMode(WinDC, OPAQUE);
TextOut(WinDC, GetSystemMetrics(SM_CXEDGE)+GetSystemMetrics(SM_CXSMICON)+6,
GetSystemMetrics(SM_CYEDGE)+3, PChar(StringOfChar(' ',30)+'QQ5555044提供 f'),
Length(StringOfChar(' ',30)+'QQ5555044提供 f'));
SelectObject(WinDC, OldFont);
ReleaseDC(Form1.Handle, WinDC);
end;
end.