program demo;uses
  windows, Messages, ShellApi;{$R *.res}
const
  id_Button=100;function PlainWinProc(hWnd:THandle; nMsg:UINT;
  wParam,lParam:Cardinal):Cardinal;export;stdcall;
var
  hdc:THandle;
  ps:TPaintStruct;
  Rect:TRect;
begin
  result:=0;
  case nMsg of
    wm_Create:
      CreateWindowEx(0,'Button','&Click Me',ws_Child or ws_Visible or
                     ws_Border or bs_PushButton,
                     0,0,200,80,hWnd,id_Button,hInstance,nil);
    wm_Size:
    begin
      GetClientRect(hWnd,Rect);
      SetWindowPos(GetDlgItem(hWnd,id_Button),0,Rect.Right div 2-100,
                   Rect.Bottom div 2-40,0,0,swp_NoZOrder or swp_NoSize);
    end;
    wm_Command:
      if LoWord(wParam)=id_Button then
        if HiWord(wParam)=bn_Clicked then
          MessageBox(hWnd,'Button Clicked','Plain API',MB_OK);
    wm_lButtonDown:
      MessageBox(hWnd,'Left Mouse Button Clicked','Plain API',MB_OK);
    wm_Paint:
    begin
      hdc:=BeginPaint(hWnd,ps);
      Ellipse(hdc,100,100,300,300);
      EndPaint(hWnd,ps);
    end;
    wm_DropFiles:
    begin
      MessageBox(hWnd,'Drop File','Plain API',MB_OK);
      DragFinish(wParam);
    end;  
    wm_Destroy: PostQuitMessage(0);
    else
      result:=DefWindowProc(hWnd,nMsg,wParam,lParam);
  end;
end;procedure WinMain;
var
  hWnd:THandle;
  Msg:TMsg;
  WndClassEx:TWndClassEx;
begin
  WndClassEx.cbSize:=SizeOf(TWndClassEx);
  WndClassEx.lpszClassName:='PlainWindow';
  WndClassEx.style:=cs_VRedraw or cs_HRedraw;
  WndClassEx.hInstance:=Hinstance;
  WndClassEx.lpfnWndProc:=@PlainWinProc;
  WndClassEx.cbClsExtra:=0;
  WndClassEx.cbWndExtra:=0;
  WndClassEx.hIcon:=LoadIcon(Hinstance,Pchar('MAINICON'));
  WndClassEx.hIconSm:=LoadIcon(Hinstance,Pchar('MAINICON'));
  WndClassEx.hCursor:=LoadCursor(0,idc_Arrow);
  WndClassEx.hbrBackground:=GetStockObject(gray_Brush);
  WndClassEx.lpszMenuName:=nil;
  if RegisterClassEx(WndClassEx)=0 then
  begin
    MessageBox(0,'Invaild Class registration','Plain API',MB_OK);
    exit;
  end
  else begin
    hWnd:=CreateWindowEx(WS_EX_TOPMOST or WS_EX_ACCEPTFILES,
                         WndClassEx.lpszClassName,
                         'Plain API Demo',ws_OverlappedWindow,
                         cw_UseDefault,0,cw_UseDefault,0,0,0,
                         Hinstance,nil);
    if hWnd=0 then
      MessageBox(0,'Window not Created','Plain API',MB_OK)
    else begin
      ShowWindow(hwnd,SW_ShowNormal);
      while GetMessage(Msg,0,0,0) do
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    end;
  end;
end;begin
  WinMain;
end.

解决方案 »

  1.   

    你的这个问题已经有人作了很好的解答(搜一下先)
    //推荐你看看CSDN帮助文档[http://www.csdn.net/expert/topic/410/410056.shtm]
      

  2.   

    这个方面<<Delphi深度历险>>里第二章有详细说明.
    并且还说明减小他需要代价的.
      

  3.   

    只要USE了FORM就会这样,它是建立窗体所必须的,系统默认如此,要想编写小程序,不要自动生成窗体,将USE中能去掉的都删掉,将主FORM 删掉,然后使用API编写窗体,具体实现原理基本如此,具体代码以后再讨论。
    也可以搜索一下,类似的文章在网上很多!
      

  4.   

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

  5.   

    Windows的程序能小到300K已经够小的了。
    如果要追究,就去问MicroSoft吧。
      

  6.   

    KOL - Key Objects Library is a set of objects to develop applications using Delphi. It is distributed free of charge, with source code.
       Why not use KOL ????
        Delphi2, Delphi3, Delphi4, Delphi5 and Delphi6 are supported. KOL allows to create very compact GUI applications (starting from ~13,5K without compression - if suggested system units replacement used). The most of code is converted to assembler.
      

  7.   

    选项中的Use VCL取消;
    还有...
      

  8.   

    可以创建控制台应用程序。NEW\console application,代码如下:
    program Project1;{$APPTYPE CONSOLE}
    VAR ZXB:STRING;begin
      { TODO -oUser -cConsole Main : Insert code here }
    **  WRITE('WHO ARE YOU ?');
      readln(zxb);
      writeln('hello!',zxb,',welcome');
      readln;
    **
    end.
    **中间是自己添加的代码,并将USE语句删除。
    编译看看吧!
      

  9.   

    最简单得方法是什么都不要动, 编译好用 ASPACK 压缩一下就都搞定了
      

  10.   

    build with runtime package以后,我保证空白窗体编译只有十多K
      

  11.   

    VSaber(☆浪人☆) 兄:说清楚好吗可以加分!! 
      

  12.   

    就是在Project菜单下面的option,打开以后,选择package,选中下面的biuld with runtime package,
    但是,要记得,你发布程序,必须带你需要的运行时间包文件,*.bpl.至于需要哪些bpl就要看你用了哪些vcl控件了!