首先新建一个工程,不用单元,把窗口关掉,我们用WINDOWS API函数来创建一个窗口。
program Project1;
uses
Windows,Messages;
function WindowProc(HWndow:HWND;msg,wparam,lparam:UINT):UINT;stdcall;
begin
case msg of
WM_DESTROY: begin
PostQuitMessage(0);
end;
end;
Result:=DefWindowProc(HWndow,msg,wparam,lparam);
end;
var
hWindow:HWND;
message:TMsg;
wndclass:TWndClass;
begin
wndclass.style:=CS_HREDRAW or CS_VREDRAW;
wndclass.lpfnWndProc:=@WindowProc;
wndclass.cbClsExtra:=0;
wndclass.cbWndExtra:=0;
wndclass.hInstance:=HInstance;
wndclass.hIcon:=LoadIcon(0,IDI_APPLICATION);
wndclass.hCursor:=LoadCursor(0,IDC_ARROW);
wndclass.hbrBackground:=COLOR_WINDOW;
wndclass.lpszMenuName:=nil;
wndclass.lpszClassName:='MyWindow';
RegisterClass(wndclass);
hwindow:=CreateWindowEx(0,'MyWindow','我的窗口',WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
0,0,HInstance,nil);
if hWindow <> 0 then
begin
ShowWindow(hWindow,SW_SHOWNORMAL);
UpdateWindow(hWindow);
end;
while GetMessage(message,0,0,0) do
begin
TranslateMessage(message);
DispatchMessage(message);
end;
end.
试着运行一下看看~~。