用API创建简单的窗体,只是引用Windows,Message,如果加入Dialogs程序会增大导380K,如果不引用只有15K。看来编写高质量的程序还是要用API啊,不过也是挺麻烦的。<br>program Project1;<br><br>uses<br> windows,<br> Messages;<br><br>var<br> TheMessage: TMsg;<br><br>function WindowProc(TheWindow: HWND; TheMessage, WParam,LParam: LongInt):LongInt;<br> stdcall;export;<br>begin<br> Case TheMessage of<br> WM_Destroy : begin<br> PostQuitMessage(0);<br> exit;<br> end;<br> WM_SIZE : begin<br> MessageBox(0,'Size','Form',0);<br> end;<br> end;<br> Result := DefWindowProc(TheWindow,TheMessage,WParam,LParam);<br>end;<br><br>function RegisterFormClass(FormClassName: Pchar):Boolean;<br>var<br> FormClass : TWndClass;<br>begin<br> FormClass.style := CS_HREDRAW or CS_VREDRAW;<br> FormClass.lpfnWndProc := @WindowProc;<br> FormClass.cbClsExtra := 0;<br> FormClass.cbWndExtra := 0;<br> FormClass.hInstance := HInstance;<br> FormClass.hIcon := 0;<br> FormClass.hCursor := 0;<br> FormClass.hbrBackground := COLOR_WINDOW;<br> FormClass.lpszMenuName := nil;<br> FormClass.lpszClassName := FormClassName;<br><br> Result := windows.RegisterClass(FormClass) <> 0;<br>end;<br><br>function CreateForm(FormClassName : PChar): HWND;<br>begin<br> Result := CreateWindowEx(0,FormClassName,'Form',WS_OVERLAPPEDWINDOW,<br> cw_usedefault,<br> cw_usedefault,<br> cw_usedefault,<br> cw_usedefault,<br> 0,<br> 0,<br> HInstance,<br> nil);<br>end;<br><br>procedure ShowForm(aForm: HWND);<br>begin<br> ShowWindow(aForm,SW_SHOWNORMAL);<br> UpdateWindow(aForm);<br>end;<br><br>begin<br> { TODO -oUser -cConsole Main : Insert code here }<br> if not RegisterFormClass('test') then<br> begin<br> MessageBox(0,'Register class failed','Error',0);<br> exit;<br> end;<br> ShowForm(CreateForm('test'));<br> while GetMessage(TheMessage,0,0,0) do<br> begin<br> TranslateMessage(TheMessage);<br> DispatchMessage(TheMessage);<br> end;<br>end.