程序5-3 LineDemo

program LineDemo;

uses
  Windows, Messages;

function WndProc(hWindow: HWND; msg, wParam, lParam: LongInt): LRESULT; stdcall;
const
{$J+}
  cxClient: Integer = 0;
  cyClient: Integer = 0;
{$J-}
var
  ps: TPaintStruct;
  hdc1: HDC;
begin
  Result:= 0;
  case msg of
  WM_CREATE:
  begin

  end;
  WM_DESTROY:
  begin
    PostQuitMessage(0);
  end;
  WM_SIZE:
  begin
    cxClient:= LoWord(lParam);
    cyClient:= HiWord(lParam);
  end;
  WM_PAINT:
  begin
    hdc1:= BeginPaint(hWindow, ps);
    Rectangle(hdc1, cxClient div 8, cyClient div 8,
                    7 * cxClient div 8, 7 * cyClient div 8);
    MoveToEx(hdc1, 0, 0, nil);
    LineTo(hdc1, cxClient, cyClient);
    MoveToEx(hdc1, 0, cyClient, nil);
    LineTo(hdc1, cxClient, 0);

    Ellipse(hdc1, cxClient div 8, cyClient div 8,
                    7 * cxClient div 8, 7 * cyClient div 8);
    RoundRect(hdc1, cxClient div 4, cyClient div 4,
              3 * cxClient div 4, 3 * cyClient div 4,
              cxClient div 4, cyClient div 4);
    EndPaint(hWindow, ps);
  end
  else
    Result:= DefWindowProc(hWindow, msg, wParam, lParam);
  end;
end;
const
  szAppName = 'LineDemo';
var
  wndclass1: TWndClass;
  hWindow: HWND;
  msg: TMsg;
begin
  wndclass1.style:= CS_VREDRAW or CS_HREDRAW;
  wndclass1.lpfnWndProc:= @WndProc;
  wndclass1.cbClsExtra:= 0;
  wndclass1.cbWndExtra:= 0;
  wndclass1.hInstance:= HInstance;
  wndclass1.hIcon:= LoadIcon(0, 0);
  wndclass1.hCursor:= LoadCursor(0, 0);
  wndclass1.hbrBackground:= GetStockObject(0);
  wndclass1.lpszMenuName:= nil;
  wndclass1.lpszClassName:= szAppName;

  if RegisterClass(wndclass1) = 0 then
  begin
    MessageBox(0, 'This program requires Windows NT!', szAppName, MB_ICONERROR);
    exit;
  end;

  hWindow:= CreateWindow(szAppName, 'Line Demonstration', WS_OVERLAPPEDWINDOW,
    CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
    0, 0, HInstance, nil);

  ShowWindow(hWindow, CmdShow);
  UpdateWindow(hWindow);

  while GetMessage(msg, 0, 0, 0) do
  begin
    TranslateMessage(msg);
    DispatchMessage(msg);
  end;

end.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值