program Altwind;
//程序5-5 AltWind
uses
Windows, Messages;
function WndProc(hWindow: HWND; Msg, wParam, lParam: LongInt): LRESULT; stdcall;
const
{$J+}
cxClient: Integer = 0;
cyClient: Integer = 0;
aptFigure: array[0..9] of TPoint = (
(X: 10; Y: 70), (X: 50; Y: 70), (X: 50; Y: 10), (X: 90; Y: 10), (X: 90; Y: 50),
(X: 30; Y: 50), (X: 30; Y: 90), (X: 70; Y: 90), (X: 70; Y: 30), (X: 10; Y: 30)
);
{$J-}
var
ps: TPaintStruct;
hdc1: HDC;
apt: array[0..9] of TPoint;
i: integer;
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);
//调整数据
for I := 0 to 9 do
begin
apt[i].X:= aptFigure[i].X * (cxClient div 200);
apt[i].Y:= aptFigure[i].Y * (cyClient div 100);
end;
SelectObject(hdc1, GetStockObject(GRAY_BRUSH));
SetPolyFillMode(hdc1, ALTERNATE);
Polygon(hdc1, apt, 10);
//向右平移
for I := 0 to 9 do
Inc(apt[i].X, cxClient div 2);
SetPolyFillMode(hdc1, WINDING);
Polygon(hdc1, apt, 10);
EndPaint(hdc1, ps);
end
else
Result:= DefWindowProc(hWindow, Msg, wParam, lParam);
end;
end;
const
szAppName = 'AltWind';
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, 'Alternate and Winding Fill Modes', 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.