program Pontifex;uses
  Forms,
  Windows,
  ShellAPI,
  Messages,
  Sysutils, 
  exSystem,
  Pontifex_TLB in 'Pontifex_TLB.pas',
  Server_CORBA in '..\2.program\0.服务器\Server_CORBA.pas' {CORBAServer_WeiHai: TCorbaDataModule} {CORBAServer_WeiHai: CoClass},
  Server_System in '..\2.program\0.服务器\Server_System.pas',
  Server in '..\2.program\0.服务器\Server.pas' {Form_Server};{$R *.TLB} {CORBA}{$R *.res}{$R Server.res}var AboutStr: string;
var NID: TNotifyIconData;
    WndClass: array[0..50] of char;procedure Panic(szMessage: PChar);
begin
  if szMessage<>nil then MessageBox(0, szMessage, PChar(VG_AppName), MB_OK);
  Halt(0);
end;procedure HandleCommand(Wnd: hWnd; Cmd: Word);
begin
  case Cmd of
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //主窗口********************************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Ord('C'): if not Form_Server.Visible then Form_Server.ShowModal;
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //关于**********************************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Ord('A'): MessageBox(0, PChar(AboutStr), PChar('关于...'), MB_OK);
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    //退出系统******************************************************************
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Ord('E'): begin
                ServerOver; 
                if Form_Server.Visible then Form_Server.Close;
                PostMessage(Wnd, WM_CLOSE, 0, 0);
              end;
  end;
end;function DummyWindowProc(Wnd: hWnd; Msg, wParam: Word; lParam: LongInt): LongInt; stdcall;
var TrayHandle: THandle;
    DC: hDC;
    pm: HMenu;
    pt: TPoint;
begin
  DummyWindowProc := 0;
  StrPCopy(@WndClass[0], 'Quark');
  TrayHandle := FindWindow(@WndClass[0], nil);
  case Msg of
    WM_CREATE:  begin//Program initialisation - just set up a tray icon
                  NID.cbSize           := SizeOf(NID);
                  NID.Wnd              := Wnd;
                  NID.uID              := 1;
                  NID.uFlags           := nif_Message or nif_Icon or nif_Tip;
                  NID.uCallBackMessage := WM_User;
                  NID.hIcon            := LoadIcon(hInstance, 'TRAYICON');
                  Lstrcpy(NID.szTip,'Pontifex for Windows');
                  Shell_NotifyIcon(nim_Add, @NID);
                end;
    WM_DESTROY: begin
                  Shell_NotifyIcon(nim_Delete, @NID);
                  PostQuitMessage(0);
                  ShowWindow(TrayHandle, SW_RESTORE);
                end;
    WM_COMMAND: begin//Command notification
                  HandleCommand(Wnd, LoWord(wParam));
                  Exit;
                end;
    WM_USER:    case lParam of
                  //双击鼠标左键************************************************
                  WM_LBUTTONDBLCLK: if not Form_Server.Visible then Form_Server.ShowModal;
                  //单击鼠标右键************************************************
                  WM_RBUTTONDOWN:   begin
                                      GetCursorPos(pt);
                                      pm := CreatePopupMenu;
                                      AppendMenu(pm, 0,            Ord('C'), '客户端状态');
                                      AppendMenu(pm, MF_SEPARATOR, 0,        nil);
                                      AppendMenu(pm, 0,            Ord('A'), '关于Pontifex...');
                                      AppendMenu(pm, 0,            Ord('E'), '退出');
                                      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;//case lParam of
  end;
  DummyWindowProc := DefWindowProc(Wnd, Msg, wParam, lParam);
end;procedure WinMain;
var Wnd: hWnd;
    Msg: TMsg;
    WndClass: TWndClass;
begin
  { Previous instance running ?  If so, exit }
  if FindWindow(PChar(VG_AppName), nil)<>0 then Panic(PChar(VG_AppName + ' 已经运行。'));  { Register the window class }
  FillChar(WndClass, SizeOf(WndClass), 0);
  WndClass.lpfnWndProc := @DummyWindowProc;
  WndClass.hInstance := hInstance;
  WndClass.lpszClassName := PChar(VG_AppName);
  RegisterClass(WndClass);  { Now create the dummy window }
  Wnd := CreateWindow(PChar(VG_AppName), PChar(VG_AppName), WS_OVERLAPPEDWINDOW , 0, 0, 0, 0, 0, 0, hInstance, nil);
  if Wnd<>0 then
  begin
    ShowWindow(Wnd, SW_HIDE);
    while GetMessage(Msg, 0, 0, 0) do
    begin
      TranslateMessage(Msg);
      DispatchMessage(Msg);
    end;
  end;
end;begin
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //系统变量初始化**************************************************************
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  ServerInit;
  AboutStr :=            '北京博达新创科技发展有限公司(R)' + #13;
  AboutStr := AboutStr + '供热企业收费管理信息系统(C)'     + #13;
  AboutStr := AboutStr + 'Version of Server ' + GetApplicationVersion(Application.ExeName);  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  //创建主窗体,开始运行********************************************************
  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  Application.Initialize;
  Application.CreateForm(TForm_Server, Form_Server);
  WinMain;
end.

解决方案 »

  1.   

    你搜索一下吧,以前有很多,我当时就是搜索找到的。
    要是没有用google,这方面的文章挺多的
      

  2.   

    program Pontifex;uses
      Forms,
      Windows,
      ShellAPI,
      Messages,
      Sysutils, 
      exSystem,
      Pontifex_TLB in 'Pontifex_TLB.pas',
      Server_CORBA in '..\2.program\0.服务器\Server_CORBA.pas' {CORBAServer_WeiHai: TCorbaDataModule} {CORBAServer_WeiHai: CoClass},
      Server_System in '..\2.program\0.服务器\Server_System.pas',
      Server in '..\2.program\0.服务器\Server.pas' {Form_Server};{$R *.TLB} {CORBA}{$R *.res}{$R Server.res}var AboutStr: string;
    var NID: TNotifyIconData;
        WndClass: array[0..50] of char;procedure Panic(szMessage: PChar);
    begin
      if szMessage<>nil then MessageBox(0, szMessage, PChar(VG_AppName), MB_OK);
      Halt(0);
    end;procedure HandleCommand(Wnd: hWnd; Cmd: Word);
    begin
      case Cmd of
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //主窗口********************************************************************
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Ord('C'): if not Form_Server.Visible then Form_Server.ShowModal;
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //关于**********************************************************************
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Ord('A'): MessageBox(0, PChar(AboutStr), PChar('关于...'), MB_OK);
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //退出系统******************************************************************
        //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        Ord('E'): begin
                    ServerOver; 
                    if Form_Server.Visible then Form_Server.Close;
                    PostMessage(Wnd, WM_CLOSE, 0, 0);
                  end;
      end;
    end;function DummyWindowProc(Wnd: hWnd; Msg, wParam: Word; lParam: LongInt): LongInt; stdcall;
    var TrayHandle: THandle;
        DC: hDC;
        pm: HMenu;
        pt: TPoint;
    begin
      DummyWindowProc := 0;
      StrPCopy(@WndClass[0], 'Quark');
      TrayHandle := FindWindow(@WndClass[0], nil);
      case Msg of
        WM_CREATE:  begin//Program initialisation - just set up a tray icon
                      NID.cbSize           := SizeOf(NID);
                      NID.Wnd              := Wnd;
                      NID.uID              := 1;
                      NID.uFlags           := nif_Message or nif_Icon or nif_Tip;
                      NID.uCallBackMessage := WM_User;
                      NID.hIcon            := LoadIcon(hInstance, 'TRAYICON');
                      Lstrcpy(NID.szTip,'Pontifex for Windows');
                      Shell_NotifyIcon(nim_Add, @NID);
                    end;
        WM_DESTROY: begin
                      Shell_NotifyIcon(nim_Delete, @NID);
                      PostQuitMessage(0);
                      ShowWindow(TrayHandle, SW_RESTORE);
                    end;
        WM_COMMAND: begin//Command notification
                      HandleCommand(Wnd, LoWord(wParam));
                      Exit;
                    end;
        WM_USER:    case lParam of
                      //双击鼠标左键************************************************
                      WM_LBUTTONDBLCLK: if not Form_Server.Visible then Form_Server.ShowModal;
                      //单击鼠标右键************************************************
                      WM_RBUTTONDOWN:   begin
                                          GetCursorPos(pt);
                                          pm := CreatePopupMenu;
                                          AppendMenu(pm, 0,            Ord('C'), '客户端状态');
                                          AppendMenu(pm, MF_SEPARATOR, 0,        nil);
                                          AppendMenu(pm, 0,            Ord('A'), '关于Pontifex...');
                                          AppendMenu(pm, 0,            Ord('E'), '退出');
                                          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;//case lParam of
      end;
      DummyWindowProc := DefWindowProc(Wnd, Msg, wParam, lParam);
    end;procedure WinMain;
    var Wnd: hWnd;
        Msg: TMsg;
        WndClass: TWndClass;
    begin
      { Previous instance running ?  If so, exit }
      if FindWindow(PChar(VG_AppName), nil)<>0 then Panic(PChar(VG_AppName + ' 已经运行。'));  { Register the window class }
      FillChar(WndClass, SizeOf(WndClass), 0);
      WndClass.lpfnWndProc := @DummyWindowProc;
      WndClass.hInstance := hInstance;
      WndClass.lpszClassName := PChar(VG_AppName);
      RegisterClass(WndClass);  { Now create the dummy window }
      Wnd := CreateWindow(PChar(VG_AppName), PChar(VG_AppName), WS_OVERLAPPEDWINDOW , 0, 0, 0, 0, 0, 0, hInstance, nil);
      if Wnd<>0 then
      begin
        ShowWindow(Wnd, SW_HIDE);
        while GetMessage(Msg, 0, 0, 0) do
        begin
          TranslateMessage(Msg);
          DispatchMessage(Msg);
        end;
      end;
    end;begin
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //系统变量初始化**************************************************************
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      ServerInit;
      AboutStr :=            '北京博达新创科技发展有限公司(R)' + #13;
      AboutStr := AboutStr + '供热企业收费管理信息系统(C)'     + #13;
      AboutStr := AboutStr + 'Version of Server ' + GetApplicationVersion(Application.ExeName);  //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      //创建主窗体,开始运行********************************************************
      //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Application.Initialize;
      Application.CreateForm(TForm_Server, Form_Server);
      WinMain;
    end.
      

  3.   

    直接使用TrayIcon这个VCL就行,很Easy的
    Delphi还有例子
    Samples->TrayIcon
      

  4.   

    其实就是截获WM_SYSCOMMAND消息;
        procedure WMSysCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
    procedure TForm1.WMSysCommand(var Msg: TWMSysCommand);
    begin
      if Msg.CmdType = SC_MINIMIZE then
      begin
        //最小化,关闭窗口即可    Hide;
      end;
    end;
    至于放到 系统托盘 中看看别人的文章或用控件;
    rxlib
      

  5.   

    在实现部分
    procedure Tform1.ll(var message:TMessage);
    begin
      if (message.wParam=SC_MINIMIZE) then
      begin
        message.wParam:=0;
        application.ShowMainForm:=false;
      end;
      inherited;
    end;
    在定义部分
          procedure ll(var message:TMessage);
          message WM_syscommand;