⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getwindowdcu.pas

📁 Delphi Win32核心API参考光盘源码 本书包含了常用的Windows API函数
💻 PAS
字号:
unit GetWindowDCU;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMNCPaint(var Msg: TMessage); message WM_NCPAINT;
    procedure WMActivate(var Msg: TWMActivate); message WM_ACTIVATE;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMNCPaint(var Msg: TMessage);
var
  WinDC: HDC;        // holds the window device context
  OldFont: HFONT;    // holds the previous font
begin
  {call the inherited paint handler}
  inherited;

  {retrieve a handle to the window device context}
  WinDC := GetWindowDC(Form1.Handle);

  {initialize the font}
  Canvas.Font.Height := GetSystemMetrics(SM_CYCAPTION)-4;
  Canvas.Font.Name := 'Times New Roman';
  Canvas.Font.Style := [fsBold, fsItalic];

  {select the font into the window device context}
  OldFont := SelectObject(WinDC, Canvas.Font.Handle);

  {see if the window is active}
  if GetActiveWindow = 0 then
  begin
    {draw inactive colors}
    SetBkColor(WinDC, GetSysColor(COLOR_INACTIVECAPTION));
    SetTextColor(WinDC, GetSysColor(COLOR_INACTIVECAPTIONTEXT));
  end
  else
  begin
    {otherwise draw active colors}
    SetBkColor(WinDC, GetSysColor(COLOR_ACTIVECAPTION));
    SetTextColor(WinDC, GetSysColor(COLOR_CAPTIONTEXT));
  end;

  {draw the text of the caption in a bold, italic style}
  SetBkMode(WinDC, OPAQUE);

  TextOut(WinDC, GetSystemMetrics(SM_CXEDGE)+GetSystemMetrics(SM_CXSMICON)+6,
          GetSystemMetrics(SM_CYEDGE)+3, 'GetWindowDC Example    ',
          Length('GetWindowDC Example    '));

  {replace the original font and release the window device context}
  SelectObject(WinDC, OldFont);
  ReleaseDC(Form1.Handle, WinDC);
end;

procedure TForm1.WMActivate(var Msg: TWMActivate);
begin
  {call the inherited message handle and repaint the caption bar}
  inherited;
  PostMessage(Form1.Handle, WM_NCPAINT, 0, 0);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -