求,做一个小程序,不需要DELPHI的FORM方式,只要几十KB就可以搞定的程序!!(50分)

K

knifepj

Unregistered / Unconfirmed
GUEST, unregistred user!
我需要整个代码,功能不限!
 
W

wwolf

Unregistered / Unconfirmed
GUEST, unregistred user!
在你的工程文件.dpr里写嘛。<br>不要加载form等东东就会很小的
 

一少

Unregistered / Unconfirmed
GUEST, unregistred user!
放dpr文件中编译<br>program M; <br>uses windows, Graphics; <br><br>var i,j:integer; <br>begin <br>with tcanvas.create do <br>&nbsp; begin <br>&nbsp; &nbsp; handle:=getdc(0); <br>&nbsp; &nbsp; for i:=1 to 400 do begin <br>&nbsp; &nbsp; &nbsp; MoveTo(400,300); <br>&nbsp; &nbsp; &nbsp; LineTo(2*i,1); <br>&nbsp; &nbsp; &nbsp; MoveTo(400,300); <br>&nbsp; &nbsp; &nbsp; LineTo(2*i,600); <br>&nbsp; &nbsp; &nbsp; MoveTo(400,300); <br>&nbsp; &nbsp; &nbsp; LineTo(1,round(i*1.5)); <br>&nbsp; &nbsp; &nbsp; MoveTo(400,300); <br>&nbsp; &nbsp; &nbsp; LineTo(800,round(i*1.5)) <br>&nbsp; &nbsp; end; <br>&nbsp; &nbsp; Pen.Color:=clred; <br>&nbsp; &nbsp; For j:=1 to 120 &nbsp;do begin <br>&nbsp; &nbsp; &nbsp;moveTo(600,1); <br>&nbsp; &nbsp; &nbsp;for i:=1 to 800 do <br>&nbsp; &nbsp; &nbsp; &nbsp;LineTo(i,600-round(i*i/(Sqr(j)/2))); <br>&nbsp; &nbsp; &nbsp;moveTo(1,1); <br>&nbsp; &nbsp; &nbsp;for i:=1 to 800 do <br>&nbsp; &nbsp; &nbsp; &nbsp;LineTo(i,round(i*i/(Sqr(j)/2))) <br>&nbsp; &nbsp; end; <br>&nbsp; &nbsp; Font.Size:=72 ; <br>&nbsp; &nbsp; Font.Color:=clblue; <br>&nbsp; &nbsp; Brush.Color:=clbackground; <br>&nbsp; &nbsp; textout(10,100,'看不到了吧!') <br>&nbsp; end <br>end.
 
J

jsxjd

Unregistered / Unconfirmed
GUEST, unregistred user!
一个功能很强的程序<br>本程序象C语言一样,用Delphi也能写出只有几十K、十几K、甚至只有几K的小程序,本文以一个能将Win95桌面藏起来的小程序为例,还涉及Win95 TrayIcon的显示。<br>本程序能写得很小的诀窍是:根本没有用任何的 Form 。也就是说,源程序只有一个Prog1.dpr 文件,当然资源文件是不能少的。资源中包括桌机两种状态的图标。程序完全用标准的 WINAPI 写成,由于用到的资源很少,所以程序的体积也很小。当然,用这样的方法编程时不能使用 Delphi的所见即所得的编程方式。<br>本程序用到了如下一些功能:<br><br>在任务栏上显示图标,不同状态的切换 <br>只用一个工程文件,运行中注册建立窗口 <br>点击任务栏显隐桌面<br>ShowWindow(FindWindow('Progman',nil),SW_RESTORE|SW_HIDE); <br>运行中建立弹出菜单,对菜单命令的处理 <br>不显示程序窗口,程序不能重复运行 <br>注册窗口对不同消息的控制 <br>program prog1;<br>{prog1.dpr}<br>uses Windows, Messages, ShellAPI, sysutils;<br>{$R *.RES}<br>{可以看出本程序比普通的 Delphi 程序用到的 Unit 少的多。 下面声明了全局常量和变量,暂时可以不管他们。}<br>const<br>&nbsp; AppName = 'DeskTop Hide';<br>var<br>&nbsp; x: integer;<br>&nbsp; tid: TNotifyIconData;<br>&nbsp; WndClass: array[0..50] of char;<br><br>procedure HandleCommand (Wnd: hWnd; Cmd: Word);<br>begin<br>&nbsp; case Cmd of<br>&nbsp; &nbsp; Ord ('A'): MessageBox (0, 'Freeware brian.slack@strath.ac.uk 1997',AppName, mb_ok);<br>&nbsp; &nbsp; Ord ('E'): PostMessage (Wnd, wm_Close, 0, 0);<br>&nbsp; end;<br>end;<br><br><br>function DummyWindowProc (Wnd: hWnd; Msg, wParam: Word; lParam: LongInt):LongInt; stdcall;<br>{注意这里有一个 stdcall;定义了回调函数}<br>var<br>&nbsp; TrayHandle: Thandle;<br>&nbsp; dc: hDC;<br>&nbsp; pm: Hmenu;<br>&nbsp; pt: Tpoint;<br>begin<br>&nbsp; DummyWindowProc := 0;<br>&nbsp; {下面两句是找到 Win95 任务栏的句柄}<br>&nbsp; StrPCopy(@WndClass[0], 'Progman');<br>&nbsp; TrayHandle := FindWindow(@WndClass[0], nil);<br>&nbsp; {下面开始处理消息}<br>&nbsp; case Msg of<br>&nbsp; {收到窗口创建消息 - 在任务栏上显示一个图标}<br>&nbsp; wm_Create: // Program initialisation - just set up a tray icon<br>&nbsp; begin<br>&nbsp; &nbsp; tid.cbSize := sizeof (tid);<br>&nbsp; &nbsp; tid.Wnd := Wnd;<br>&nbsp; &nbsp; tid.uID := 1;<br>&nbsp; &nbsp; tid.uFlags := nif_Message or nif_Icon or nif_Tip;<br>&nbsp; &nbsp; tid.uCallBackMessage := wm_User;<br>&nbsp; &nbsp; tid.hIcon := LoadIcon (hInstance, 'mainICON');<br>&nbsp; &nbsp; lstrcpy (tid.szTip,'Desktop is on');<br>&nbsp; &nbsp; Shell_NotifyIcon (nim_Add, @tid);<br>&nbsp; end;<br>&nbsp; wm_Destroy: {收到关闭窗口消息时的处理}<br>&nbsp; begin<br>&nbsp; &nbsp; Shell_NotifyIcon (nim_Delete, @tid);<br>&nbsp; &nbsp; PostQuitMessage (0);<br>&nbsp; &nbsp; ShowWindow(TrayHandle, SW_RESTORE);<br>&nbsp; end;<br><br>&nbsp; {收到菜单消息时调用 HandleCommand 过程,并退出函数}<br>&nbsp; wm_Command: // Command notification<br>&nbsp; begin<br>&nbsp; &nbsp; HandleCommand (Wnd, LoWord (wParam));<br>&nbsp; &nbsp; Exit;<br>&nbsp; end;<br><br>&nbsp; {收到其他用户消息时的处理}<br>&nbsp; wm_User: // Had a tray notification - see what to do<br>&nbsp; {如果单击了鼠标左键, 则打开或关闭桌面}<br>&nbsp; if (lParam = wm_LButtonDown) then<br>&nbsp; begin<br>&nbsp; &nbsp; if x = 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ShowWindow(TrayHandle, SW_HIDE);<br>&nbsp; &nbsp; &nbsp; tid.hIcon := LoadIcon (hInstance, 'OFFICON');<br>&nbsp; &nbsp; &nbsp; lstrcpy (tid.szTip,'Desktop is off');<br>&nbsp; &nbsp; &nbsp; Shell_NotifyIcon (NIM_MODIFY, @tid);<br>&nbsp; &nbsp; &nbsp; x:=1<br>&nbsp; &nbsp; end else<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; ShowWindow(TrayHandle, SW_RESTORE);<br>&nbsp; &nbsp; &nbsp; tid.hIcon := LoadIcon (hInstance, 'ONICON');<br>&nbsp; &nbsp; &nbsp; lstrcpy (tid.szTip,'Desktop is on');<br>&nbsp; &nbsp; &nbsp; Shell_NotifyIcon (NIM_MODIFY, @tid);<br>&nbsp; &nbsp; &nbsp; x:= 0;<br>&nbsp; &nbsp; end; {end of if}<br>&nbsp; end else<br>&nbsp; &nbsp; {如果是鼠标右键,则动态生成一个弹出式菜单}<br>&nbsp; &nbsp; if (lParam = wm_RButtonDown) then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; GetCursorPos (pt);<br>&nbsp; &nbsp; &nbsp; pm := CreatePopupMenu;<br>&nbsp; &nbsp; &nbsp; AppendMenu (pm, 0, Ord ('A'), 'About DeskTop Hide...');<br>&nbsp; &nbsp; &nbsp; AppendMenu (pm, mf_Separator, 0, Nil);<br>&nbsp; &nbsp; &nbsp; AppendMenu (pm, 0, Ord ('E'), 'Exit DeskTop Hide');<br>&nbsp; &nbsp; &nbsp; SetForegroundWindow (Wnd);<br>&nbsp; &nbsp; &nbsp; dc := GetDC (0);<br>&nbsp; &nbsp; &nbsp; if TrackPopupMenu (pm, tpm_BottomAlign or tpm_RightAlign,<br>&nbsp; &nbsp; &nbsp; &nbsp; pt.x,pt.y, 0, Wnd, Nil)<br>&nbsp; &nbsp; &nbsp; then SetForegroundWindow (Wnd);<br>&nbsp; &nbsp; &nbsp; DestroyMenu (pm)<br>&nbsp; &nbsp; end; {end of if}<br>&nbsp; end; {end of case}<br>&nbsp; {在处理过消息之后,还要调用默认函数,<br>以完成标准的Windows程序应该执行的任务,<br>所以这一句非常重要}<br>&nbsp; DummyWindowProc := DefWindowProc (Wnd, Msg, wParam, lParam);<br>end;<br>{这个就是处理菜单消息的过程}<br>{现在看来,程序的主框架很明了,但是它还不能完成任何任务。<br>过程 Panic将显示一个对话框后退出程序,<br>它在 Winmain 过程的开始部分被调用,<br>其实 Panic的功能很简单,之所以要写成一个函数的原因<br>恐怕一方面是结构化编程的需要,<br>另一方面借此避开了 String 和 Pchar 的转换。}<br>procedure Panic (szMessage: Pchar);<br>begin<br>&nbsp; if szMessage &lt;&gt; Nil then<br>&nbsp; &nbsp; &nbsp; MessageBox (0, szMessage, AppName, mb_ok);<br>&nbsp; Halt (0);<br>end;<br><br><br>{现在进入程序的主要部分,首先是定义了一批过程,<br>为了能让读者更好地理解,我们先把这些过程跳过去,<br>先说主程序。主程序位于程序的最后,<br>这样做的好处是可以直接使用程序中定义的过程。<br>主程序十分简单:}<br>procedure WinMain;<br>var<br>&nbsp; Wnd: hWnd; {声明窗口句柄(Handle)变量}<br>&nbsp; Msg: TMsg; {声明消息变量}<br>&nbsp; cls: TWndClass; {窗口类变量}<br>begin<br>&nbsp; { Previous instance running ? If so, exit }<br>&nbsp; { 检查是否程序已经运行,如果已经运行则调用Panic过程退出 }<br>&nbsp; if FindWindow (AppName, Nil) &lt;&gt; 0 then<br>&nbsp; &nbsp; Panic (AppName + ' is already running.');<br>&nbsp; { Register the window class }<br>&nbsp; { 这里的注册窗口类程序是例行公事,照抄即可}<br>&nbsp; FillChar (cls, sizeof (cls), 0); {用这一句将窗口类变量cls清零}<br>&nbsp; cls.lpfnWndProc := @DummyWindowProc; {取回调函数DummyWindowProc的地址}<br>&nbsp; cls.hInstance := hInstance; {实例句柄}<br>&nbsp; cls.lpszClassName := AppName; {窗口类名}<br>&nbsp; RegisterClass (cls); {注册窗口类cls}<br>&nbsp; { 现在可以创建程序的主窗口了-在本程序中是个虚拟窗口}<br>&nbsp; { Now create the dummy window }<br>&nbsp; Wnd := CreateWindow (AppName, AppName, ws_OverlappedWindow,0, 0, 100, 100,<br>&nbsp; &nbsp; 0, 0, hInstance, Nil);<br>&nbsp; x:= 0; {变量X其实是个开关变量,记录现在是否已经隐藏了桌面}<br>&nbsp; { 如果窗口创建成功,则显示窗口,并进入消息循环 }<br>&nbsp; if Wnd &lt;&gt; 0 then<br>&nbsp; begin<br>&nbsp; &nbsp; ShowWindow (Wnd, sw_Hide);{本例中窗口是隐藏的}<br>&nbsp; &nbsp; { 下面进入消息循环,该循环将不断运行直到 GetMessage返回0 }<br>&nbsp; &nbsp; while GetMessage (Msg, 0, 0, 0) do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; TranslateMessage (Msg);<br>&nbsp; &nbsp; &nbsp; DispatchMessage (Msg);<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br>{主程序}<br>begin<br>WinMain;<br>end.<br><br><br>
 
Z

zlwnet

Unregistered / Unconfirmed
GUEST, unregistred user!
T

testnet

Unregistered / Unconfirmed
GUEST, unregistred user!
有KOF组件,好像叫这个名字,能写很小的程序。在大富翁里找找,
 
H

hq_pan

Unregistered / Unconfirmed
GUEST, unregistred user!
to jsxjd:<br>&nbsp; 你的程序我运行了一下,没有隐藏桌面啊?点击程序的任务栏图标后只是隐藏了程序的<br>任务栏图标,其它毫无变化,而且只能隐藏,不能从隐藏转换为显示。<br>&nbsp; 使用Delphi7编译,42k,用ASPack压缩后27.5k。
 
B

beta

Unregistered / Unconfirmed
GUEST, unregistred user!
清空历史记录的,10K:<br><br>program Clean;<br><br>uses<br>&nbsp; ShellAPI, Windows;<br><br>{$R *.res}<br><br>begin<br>&nbsp; ShellExecute(0, 'open', 'command.com',<br>&nbsp; &nbsp; '/c del c:/windows/recent/*.lnk', nil, 0);<br>&nbsp; MessageBox(0, '历史记录清空完毕', ' --- by beta', 0);<br>end.<br>
 
Z

zlwnet

Unregistered / Unconfirmed
GUEST, unregistred user!
jsxjd, 怎么样在你给的这个程序中加上 TTimer 这个功能呢?<br>就是能响应时钟定时工作!
 
M

Milpas

Unregistered / Unconfirmed
GUEST, unregistred user!
我来一个最简单的吧[:D]<br>abc.dpr<br><br>program abc;<br>{$ *.res}<br>begin<br>end;<br><br>只有14K。
 
J

jsxjd

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我几年前刚接触 delphi 时写的,是特地为你找出来的。
 

汪向阳

Unregistered / Unconfirmed
GUEST, unregistred user!
最简单的<br>program Project1;<br>end.<br><br>
 
K

knifepj

Unregistered / Unconfirmed
GUEST, unregistred user!
多人接受答案了。
 
顶部