用DELPHI编制原始的API小程序:
program myapp;
uses
Windows,
Messages;
function AppWindowProc( hWnd:HWND; uMsg:UINT; wParam:WPARAM; lParam:LPARAM) :LRESULT ;stdcall; // 回调函数
var
myhdc : hdc;
ps : TPaintstruct;
myrect : TRect;
begin
Result := 0;
case uMsg of
WM_DESTROY:begin
PostQuitMessage(0);
Exit;
end;
WM_PAINT : begin
myhdc :=BeginPaint(hwnd,ps);
GetClientRect(hwnd,myrect);
DrawText(myhdc,'你好,Windows98!',-1,myrect,DT_SINGLELINE OR DT_CENTER OR DT_VCENTER);
endPaint(hwnd,ps);
exit;
end;
end;
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
end;
var
wc: TWndClass;
hWnd: Integer;
MSG: TMsg;
begin //主程序从此开始
wc.style := CS_VREDRAW or CS_HREDRAW;
wc.lpfnWndProc := @AppWindowProc;
wc.cbClsExtra := 0;
wc.cbWndExtra := 0;
wc.hInstance := HInstance;
wc.hIcon := LoadIcon(0, IDI_APPLICATION);
wc.hCursor := LoadCursor(0, IDC_ARROW);
// wc.hbrBackground := (COLOR_BTNFACE+1);
// wc.hbrBackground :=GetStockObject(WHITE_BRUSH);
wc.hbrBackground :=6; //0:透明 1:灰色 2:蓝色 3:深蓝色 4:无效灰色 5:灰色 6:白色 7:黑色
wc.lpszMenuName := nil;
wc.lpszClassName := 'My App';
if RegisterClass(wc)=0 then Exit;
hWnd := CreateWindow( wc.lpszClassName,
'用最原始的Pascal的方法编制的Windows程序',
WS_OVERLAPPEDWINDOW,
100,
50,
400,
300,
0,
0,
HInstance,
nil);
if hWnd=0 then Exit;
ShowWindow(hWnd, SW_SHOWNORMAL);
while GetMessage(MSG, 0, 0, 0) do
begin
TranslateMessage(MSG);
DispatchMessage(MSG);
end;
Halt(MSG.wParam);
end.