Delphi能编译的容量最小的程式是什么样子的?(50分)

  • 主题发起人 主题发起人 erx
  • 开始时间 开始时间
E

erx

Unregistered / Unconfirmed
GUEST, unregistred user!
Delphi能编译的容量最小的程式是什么样子的?
另外,控制台程式是一个什么样字的概念?驻留在内存中么?
 
9K左右吧
 
是的,但是最简单的原码是什么样子的?可以显示窗体的

不是
program ABC;
begin
end.
 
//这样子小得可怜了(17K),给分吧!!!

program Small;
uses
windows,messages;
var
wClass: TWndClass
// class struct for main window
hInst, // handle of program (hinstance)
Handle: Hwnd
// handle of main window
Msg: TMSG
// message struct
(*------------------------------------------------*)
// This is to cleanup and stop the program

procedure ShutDown;
begin
UnRegisterClass('Sample Class',hInst);
ExitProcess(hInst)
//end program
end;

(*------------------------------------------------*)
// This function processes every message sent to our Main window
function WindowProc(hWnd,Msg,wParam,lParam:Longint):Longint
stdcall;
begin
// Always pass the message to the Default procedure
Result:=DefWindowProc(hWnd,Msg,wParam,lParam);
case Msg of
WM_DESTROY: ShutDown;
end;
end;
(*------------------------------------------------*)
// 主过程,类似于 C语言 中的 WinMain()
begin
//取得应用程序实例句柄
hInst:=GetModuleHandle(nil);
with wClass do
begin
Style:= CS_PARENTDC;
hIcon:= LoadIcon(hInst,'MAINICON');
lpfnWndProc:= @WindowProc;
hInstance:= hInst;
hbrBackground:= COLOR_BTNFACE+1;
lpszClassName:= 'MainClass';
hCursor:= LoadCursor(0,IDC_ARROW);
end;
// 注册窗口类
RegisterClass(wClass);
// 建立主窗口
Handle:=CreateWindow(wClass.lpszClassName,'Main',WS_OVERLAPPEDWINDOW or WS_VISIBLE,10,10,400,300,0,0,hInst,nil);
while(GetMessage(Msg,Handle,0,0))do
begin
TranslateMessage(Msg);
DispatchMessage(Msg);
end;
end.
 
program MiniExe;

uses
Windows,
Messages;

var
WinClass: TWndClassA;
Inst, Handle, Button1, Label1, Edit1: Integer;
Msg: TMsg;
hFont: Integer;

{ Checks if typed password is 'Amigreen' and shows Message }
procedure CheckPassword;
var
Textlength: Integer;
Text: PChar;
begin
TextLength := GetWindowTextLength(Edit1);
if TextLength = 8 then
begin
GetMem(Text, TextLength + 1);
GetWindowText(Edit1, Text, TextLength + 1);
if Text = 'Amigreen' then
begin
MessageBoxA(Handle, 'Password is correct.', 'Password check', MB_OK);
FreeMem(Text, TextLength + 1);
Exit;
end;
end;
MessageBoxA(Handle, 'Password is incorrect.', 'Password check', MB_OK);
end;

{ Custom WindowProc function }
function WindowProc(hWnd, uMsg, wParam, lParam: Integer): Integer
stdcall;
begin
Result := DefWindowProc(hWnd, uMsg, wParam, lParam);
{ Checks for messages }
if (lParam = Button1) and (uMsg = WM_COMMAND) then
CheckPassword;
if uMsg = WM_DESTROY then
Halt;
end;

begin
{ ** Register Custom WndClass ** }
Inst := hInstance;
with WinClass do
begin
style := CS_CLASSDC or CS_PARENTDC;
lpfnWndProc := @WindowProc;
hInstance := Inst;
hbrBackground := color_btnface + 1;
lpszClassname := 'AG_TESTWINDOW';
hCursor := LoadCursor(0, IDC_ARROW);
end
{ with }
RegisterClass(WinClass);

{ ** Create Main Window ** }
Handle := CreateWindowEx(WS_EX_WINDOWEDGE, 'AG_TESTWINDOW', 'Amigreen TestWindow 1.00',
WS_VISIBLE or WS_SIZEBOX or WS_CAPTION or WS_SYSMENU,
363, 278, 305, 65, 0, 0, Inst, nil);
{ ** Create a button ** }
Button1 := CreateWindow('Button', 'OK', WS_VISIBLE or WS_CHILD or BS_PUSHLIKE or BS_TEXT,
216, 8, 75, 25, handle, 0, Inst, nil);
{ ** Create a label (static) ** }
Label1 := Createwindow('Static', '', WS_VISIBLE or WS_CHILD or SS_LEFT,
8, 12, 76, 13, Handle, 0, Inst, nil);

{ ** Create an edit field ** }
Edit1 := CreateWindowEx(WS_EX_CLIENTEDGE, 'Edit', '', WS_CHILD or WS_VISIBLE or
WS_BORDER or ES_PASSWORD, 88, 8, 121, 21, Handle, 0, Inst, nil);

{ ** Create Font Handle ** }
hFont := CreateFont(-11, 0, 0, 0, 400, 0, 0, 0, DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH or FF_DONTCARE, 'MS Sans Serif');

{ Change fonts }
if hFont <> 0 then
begin
SendMessage(Button1, WM_SETFONT, hFont, 0);
SendMessage(Label1, WM_SETFONT, hFont, 0);
SendMessage(Edit1, WM_SETFONT, hFont, 0);
end;
{ Change label (static) text }
SetWindowText(Label1, 'Enter password:');
{ Set the focus to the edit control }
SetFocus(Edit1);

UpdateWindow(Handle);

{ ** Message Loop ** }
while(GetMessage(Msg, Handle, 0, 0)) do
begin
TranslateMessage(msg);
DispatchMessage(msg);
end
{ with }
end.

差不多是最小的了,10k左右。
 
去掉FORM单元
什么也不写,应该很小吧
要这么小做什么呢
 
写木马最好
 
上面的真的只有10k左右?

我的是下面这样,还有16k呢.

program test

uses
windows;

begin
messagebox('好','大家',MB_OK);
end.
 
EXE+Package,EXE就只有10K了
 
废话,光PACKAGE就有几M,EXE能不小吗?
要想让程序真的小,只能直接用API写,一且用了任何VCL,那几百K是少不了了。
 
总之,没引用或间接引用Forms单元程序就小
 
多人接受答案了。
 
后退
顶部