program Sysmets1;
uses
Windows, Messages,
sysmets in '..\sysmets.pas';
function WndProc(hwindow: HWND; message, wParam, lParam: LongInt): LRESULT; stdcall;
const
{$J+}
cxChar: Integer = 0;
cxCaps: Integer = 0;
cyChar: Integer = 0;
{$J-}
var
tm: TTextMetric;
hdc1: HDC;
ps: TPaintStruct;
i: integer;
szBuffer: array[0..4] of Char;
tmp: integer;
begin
Result:= 0;
case message of
WM_CREATE:
begin
hdc1:= GetDC(hwindow);
GetTextMetrics(hdc1, tm);
cxChar:= tm.tmAveCharWidth;
cyChar:= tm.tmHeight + tm.tmExternalLeading;
if tm.tmPitchAndFamily and $1 = 0 then
cxCaps:= cxChar
else
cxCaps:= (cxChar * 3) div 2;
ReleaseDC(hwindow, hdc1);
end;
WM_DESTROY:
begin
PostQuitMessage(0);
end;
WM_PAINT:
begin
hdc1:= BeginPaint(hwindow, ps);
for i:= 0 to NUMLINES-1 do
begin
TextOut(hdc1, 0, cyChar*i, SysMetrics[i].szLabel, lstrlen(SysMetrics[i].szLabel));// 显示索引名
TextOut(hdc1, 22*cxCaps, cyChar*i, SysMetrics[i].szDesc, lstrlen(SysMetrics[i].szDesc));// 显示描述
SetTextAlign(hdc1, TA_RIGHT or TA_TOP);
tmp:= GetSystemMetrics(SysMetrics[i].Index);
wvsprintf(szBuffer, '%5d', @tmp);
TextOut(hdc1, 22*cxCaps+40*cxChar, cyChar*i, szBuffer, 5);// 实际数值
//TextOut(hdc1, 22*cxCaps+40*cxChar, cyChar*i, szBuffer,
// wvsprintf(szBuffer, '%5d', @GetSystemMetrics(SysMetrics[i].Index)));
SetTextAlign(hdc1, TA_LEFT or TA_TOP);
end;
EndPaint(hwindow, ps);
end;
else
begin
Result:= DefWindowProc(hwindow, message, wParam, lParam);
end;
end;
end;
const
szAppName = 'Sysmets1';
var
hwindow: HWND;
msg1: MSG;
wndclass1: WNDCLASS;
begin
wndclass1.style:= CS_VREDRAW or CS_HREDRAW;
wndclass1.lpfnWndProc:= @WndProc;
wndclass1.cbClsExtra:= 0;
wndclass1.cbWndExtra:= 0;
wndclass1.hInstance:= HInstance;
wndclass1.hIcon:= LoadIcon(0, IDI_APPLICATION);
wndclass1.hCursor:= LoadCursor(0, IDC_ARROW);
wndclass1.hbrBackground:= GetStockObject(WHITE_BRUSH);
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, 'Get System Metrics No.1', WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
0, 0, HInstance, nil);
ShowWindow(hwindow, CmdShow);
UpdateWindow(hwindow);
while GetMessage(msg1, 0, 0, 0) do
begin
TranslateMessage(msg1);
DispatchMessage(msg1);
end;
end.