你给微软打个电话,让它把Delphi的bpl文件集成在windows中,你就可以编译几十KB的程序了。
真想让程序变小(不使用动态编译),只有:
1.使用纯Win API,不使用VCL相关组件,一些小的单元可以用一用,里面有许多不错的方法,象Forms, Dialogs这类不能碰,一碰就立马几百KB出去了。
2.控制台程序,不过现在一般人也不愿意编写累死DOS的程序了吧。。。
给你贴一个我曾经练Win32的时候弄的一段代码
program DateTimePicker;
uses
Messages,
Windows,
CommCtrl,
SysUtils,
XPMan;
var
WinClass: TWndClassA;
hIns: HINST;
hMainWnd: HWND;
Msgs: TMsg;
MainWndFont: HFONT;
LogFont: TLogFont;
dtpDateTime, btnClose, edtDate: HWND;
function MainWndProc(hMainWnd: HWnd; Msg, wParam, lParam: Integer): Integer;
stdcall;
var
SysTime: TSYSTEMTIME;
SelDate: String;
begin
Result := 0;
case Msg of
WM_COMMAND: begin
if HWND(lParam) = btnClose then
SendMessage(hMainWnd, WM_DESTROY, 0, 0);
Exit;
end;
WM_NOTIFY: begin
if TNMDATETIMECHANGE(Pointer(lParam)^).nmhdr.hwndFrom =
dtpDateTime then begin
MonthCal_GetCurSel(DateTime_GetMonthCal(dtpDateTime), SysTime);
DateTime_GetSystemtime(dtpDateTime, SysTime);
SelDate := IntToStr(SysTime.wYear) + '年' + IntToStr(SysTime.wMonth) +
'月' + IntToStr(SysTime.wDay) + '日';
SetWindowText(edtDate, PChar(SelDate));
end;
end;
WM_DESTROY: begin
DeleteObject(MainWndFont);
PostQuitMessage(0);
Exit;
end;
else
Result := DefWindowProc(hMainWnd, Msg, wParam, lParam);
end;
end;
begin
hIns := hInstance;
with WinClass do begin
style := CS_CLASSDC or CS_PARENTDC;
lpfnWndProc := @MainWndProc;
hInstance := hIns;
hbrBackground := COLOR_BTNFACE + 1;
lpszClassname := 'DateTimePicker';
hIcon := 0;
hCursor := LoadCursor(0, IDC_ARROW);
end;
RegisterClass(WinClass);
hMainWnd := CreateWindowEx(WS_EX_WINDOWEDGE, 'DateTimePicker',
PChar('DateTimePicker'),
WS_MINIMIZEBOX or WS_SYSMENU,
Round((GetSystemMetrics(SM_CXSCREEN) - 300) / 2),
Round((GetSystemMetrics(SM_CYSCREEN) - 300) / 2),
300, 300, 0, 0, hIns, nil);
dtpDateTime := CreateWindow('SysDateTimePick32', '',
WS_VISIBLE or WS_CHILD or WS_TABSTOP,
8, 8, 140, 22, hMainWnd, 0, hIns, nil);
edtDate := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit','',
WS_CHILD or WS_VISIBLE or WS_TABSTOP or ES_AUTOHSCROLL,
8, 36, 96, 20, hMainWnd, 0, hIns, nil);
btnClose := CreateWindow('Button', '&Close',
WS_VISIBLE or WS_CHILD or WS_TABSTOP or WS_GROUP or BS_PUSHBUTTON,
220, 240, 65, 21, hMainWnd, 0, hIns, nil);
if SystemParametersInfo(SPI_GETICONTITLELOGFONT, SizeOf(LogFont), @LogFont,
0) then
MainWndFont := CreateFontIndirect(LogFont)
else
MainWndFont := CreateFont(-12, 0, 0, 0, FW_NORMAL, 0, 0, 0, DEFAULT_CHARSET,
0, 0, 0, 0, '宋体');
if MainWndFont <> 0 then begin
SendMessage(dtpDateTime, WM_SETFONT, MainWndFont, 0);
SendMessage(edtDate, WM_SETFONT, MainWndFont, 0);
SendMessage(btnClose, WM_SETFONT, MainWndFont, 0);
end;
ShowWindow(hMainWnd, SW_SHOW);
UpdateWindow(hMainWnd);
while GetMessage(Msgs, 0, 0, 0) do begin
if not IsDialogMessage(hMainWnd, Msgs) then begin
TranslateMessage(Msgs);
DispatchMessage(Msgs);
end;
end;
end.