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

📄 createwindowexu.~pas

📁 DelphiWin32核心API参考光盘内容.是学习书籍中的源码,便于学习.
💻 ~PAS
字号:
unit CreateWindowExU;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

var
  hWindow: HWND;

{ Register the extended Window class }
function RegisterClassEx: Boolean;
var
  WindowClassEx: TWndClassEx;
begin
  {setup our new window class}
  WindowClassEx.cbSize := SizeOf(TWndClassEx);               {the size of the structure}
  WindowClassEx.Style := CS_HREDRAW or CS_VREDRAW;           {set the class styles}
  WindowClassEx.lpfnWndProc := @DefWindowProc;               {point to the default window procedure}
  WindowClassEx.cbClsExtra := 0;                             {no extra class memory}
  WindowClassEx.cbWndExtra := 0;                             {no extra window memory}
  WindowClassEx.hInstance := hInstance;                      {the application instance}
  WindowClassEx.hIcon := LoadIcon(0, IDI_APPLICATION);       {load a predefined logo}
  WindowClassEx.hCursor := LoadCursor(0, IDC_WAIT);          {load a predefined cursor}
  WindowClassEx.hbrBackground := COLOR_WINDOW;               {use a predefined color}
  WindowClassEx.lpszMenuName := nil;                         {no menu}
  WindowClassEx.lpszClassName := 'TestClass';                {the registered class name}
  WindowClassEx.hIconSm := 0;                                {no small icon}

  {now that we have our class set up, register it with the system}
  Result := Windows.RegisterClassEx(WindowClassEx) <> 0;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  {register our new class first}
  if not RegisterClassEx then
  begin
    ShowMessage('RegisterClassEx failed');
    Exit;
  end;

  {now, create a window based on our new class}
  hWindow := CreateWindowEx(WS_EX_CLIENTEDGE OR      {this window has a sunken edge}
                            WS_EX_CONTEXTHELP,       {and a context sensitive help button}
                            'TestClass',             {the registered class name}
                            'API Window',            {the title bar text}
                            WS_OVERLAPPEDWINDOW AND  {a normal window}
                            NOT WS_MAXIMIZEBOX AND   {without a minimize or mazimize button}
                            NOT WS_MINIMIZEBOX,      {so the help button is not obscured}
                            CW_USEDEFAULT,           {default horizontal position}
                            CW_USEDEFAULT,           {default vertical position}
                            CW_USEDEFAULT,           {default width}
                            CW_USEDEFAULT,           {default height}
                            0,                       {no parent window}
                            0,                       {no menu}
                            hInstance,               {the application instance}
                            nil                      {no additional information}
                            );

  {if our window was created successfully, show it}
  if hWindow <> 0 then
  begin
    ShowWindow(hWindow, SW_SHOWNORMAL);
    UpdateWindow(hWindow);
  end
  else
  begin
    ShowMessage('CreateWindow failed');
    Exit;
  end;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  {first, destroy our window}
  DestroyWindow(hWindow);

  {now we can unregister our new class}
  Windows.UnregisterClass('TestClass', hInstance);
end;

end.

⌨️ 快捷键说明

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