delphi怎样创建最小的exe 30k

baozhen 2003-12-16 04:27:54
..
...全文
112 13 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyforlove 2003-12-17
  • 打赏
  • 举报
回复
很不错,不过如果你有诚意的话,就应该把代码写出来,而不是只让人下载一个应用程序。
对别人没有任何的帮助。
halfdream 2003-12-17
  • 打赏
  • 举报
回复
使用MCL库吧,不用VCL。
另外,还要替换掉SYSTEM等单元
Sumie@Sam 2003-12-17
  • 打赏
  • 举报
回复
完全用API编写,不使用VCL。
panxiaosen 2003-12-17
  • 打赏
  • 举报
回复
我用delphi写的MP3播放器19K,用ASPACK压缩过 因为里面包含了一张96K的图片
http://fxmake.com/player.exe
flyforlove 2003-12-16
  • 打赏
  • 举报
回复
program Project2;
uses
Windows,
Messages;
var
Msg:TMsg;
wc:TWndClass; //RegisterClass()所需要的参数
hWnd:THandle; //主窗体的句柄
const
ClassName='MainWClass';
OutText='我爱你。';
Function MainWndProc(Handle:THandle;MsgID:UINT;wParam,lParam:Integer):LRESULT;stdcall;
var
pDC:HDC;
lpRect:TRECT;
begin
Result:=1;
case MsgID of
WM_CLOSE:
begin //关闭窗体所产生的消息
if MessageBox(Handle,'要关闭这个程序吗?','程序示例',MB_ICONQUESTION or MB_YESNO)=IDYES then
DestroyWindow(hWnd)
else
Result:=0;
Exit;
end;
WM_DESTROY: //DestroyWindow()所产生的消息
begin
PostQuitMessage(0);
end;
WM_PAINT:
begin
pDC:=GetDC(hWnd);
GetClientRect(hWnd,lpRect);
DrawText(pDC,OutText,8,lpRect,DT_SINGLELINE or DT_CENTER or DT_VCENTER);
ReleaseDC(hWnd,pDC);
end;
end;
//剩下的消息交给Windows预设的处理函数就可以了,比如画窗体的WM_NCPAINT消息等等
Result:=DefWindowProc(Handle,MsgID,wParam,lParam);
end;
//初始化,注册窗口类
Function InitApplication(hInstance:THANDLE):Boolean;
begin
//首先使用RegisterClass()注册窗体类,这可不是Delphi数据类型中的类哦
wc.style:=CS_HREDRAW OR CS_VREDRAW;
wc.lpfnWndProc:=@MainWndProc; //消息处理函数的地址
wc.hInstance:=hInstance; //程序的句柄,同时也是基地址
wc.hIcon:=LoadIcon(0,PChar(IDI_APPLICATION));
wc.hCursor:=LoadCursor(0,IDC_ARROW); //图标
wc.hbrBackground:=GetStockObject(WHITE_BRUSH); //背景画刷
wc.lpszClassName:=ClassName; //前面定义的常量
Result:=Boolean(RegisterClass(wc));//注册这个窗口类
end;
//InitInstance 生成窗口
Function InitInstance(hInstance:THANDLE;nCmdShow:Integer):Boolean;
begin
hWnd:=CreateWindowEx(0,
ClassName, //刚才注册的类的名字
'示例', //窗体的标题
WS_OVERLAPPEDWINDOW, //窗体的类型,有标题栏、系统菜单、最大化最小化菜单,以及拉伸边框
Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT),
Integer(CW_USEDEFAULT),
0,
0,
hInstance,
nil
);
if hWnd=0 then
begin
Result:=false;
Exit;
end;
ShowWindow(hWnd,CmdShow);
UpdateWindow(hWnd);
Result:=true;
end;
//主程序开始
begin
if Not InitApplication(hInstance) then Halt(0); //初始化注册窗口类
if Not InitInstance(hInstance,CmdShow) then Halt(0); //产生窗口
while GetMessage(Msg,0,0,0) do
begin
TranslateMessage(Msg);
DispatchMessage(Msg); //该API将消息分派到相应的窗体消息处理函数
end;
ExitCode:=Msg.wParam;
end.

whitetiger8 2003-12-16
  • 打赏
  • 举报
回复
呵呵。真的很小。给分啊。
whitetiger8 2003-12-16
  • 打赏
  • 举报
回复
program testwindow;

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.
Eastunfail 2003-12-16
  • 打赏
  • 举报
回复
没有必要啊。

Project->Options->Packages->Built with runtime packages
baozhen 2003-12-16
  • 打赏
  • 举报
回复
我只剩下 Windows 单元,现在只有15k多了。
baozhen 2003-12-16
  • 打赏
  • 举报
回复
to:noil0125(珏心)
我还要运行 winexec()程序。
baozhen 2003-12-16
  • 打赏
  • 举报
回复
to:flyforlove
我的email:javapattern@126.com

noil0125 2003-12-16
  • 打赏
  • 举报
回复
file ->new->other->console application
run后是生成一个30几K的exe,如果删除uses SysUtils;
run生产只有几k的exe
flyforlove 2003-12-16
  • 打赏
  • 举报
回复
最小的exe文件只有15k,如果你要的话,留下email,
晚上回去我发给你。

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧