//点击button 启动QQ
procedure TForm1.Button1Click(Sender: TObject);
var
  StartUpInfo: TStartUpInfo;   // holds startup information
begin
  {initialize the startup information}
  FillChar(StartupInfo, SizeOf(TStartupInfo), 0);
  with StartupInfo do  begin
    cb := SizeOf(TStartupInfo);
    dwFlags := STARTF_USESHOWWINDOW;
    wShowWindow := SW_SHOWNORMAL;
  end;  {launch a process}
  CreateProcess('C:\Program Files\Tencent\QQ\QQ.exe', nil, nil, nil, False,
      NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo);
end;//点击button 关闭qq
procedure TForm1.Button2Click(Sender: TObject);
begin
  TerminateProcess(ProcessInfo.hProcess,0);
end;每次关闭qq时,托盘图标不消失  ? 如何解决

解决方案 »

  1.   

    没人知道吗? help me !
      

  2.   

    http://www3.ccw.com.cn/club/essence/200303/13384.htm
      

  3.   

    楼上的跟我想到一块去了。如果能得到QQ的主窗体,可以用PostMessage关闭QQ
      

  4.   

    用MaskEdit就可以了:
    将MaskEdit.EditMask设为!999\.999\.999\.999;1;_,然后写个函数过滤一下得到文本串:  function DeleteBlank(const Source: String): String;
      var
        i: integer;
      begin
        Result := Source;
        i := 1;
        while i <= Length(Result) do
          if (Result[i] = ' ')        //删除空白
             or ( (Result[i] = '0')   //删除多余的零
                  and ((i = 1) or (Result[i - 1] = '.'))
                       and ((i = Length(Result)) or (Result[i + 1] in ['0'..'9']))
                ) then
            Delete(Result, i, 1)
          else
            Inc(i);
      end;
    IP地址 := DeleteBlank(MaskEdit1.Text);
      

  5.   

    Mark先。不过应该是先删除图标再结束进程。
    提示一个方法,先找到任务栏窗体句柄,EnumChildWind找到托盘句柄,再找子窗体,然后判断是否属于QQ进程,是则使用五楼朋友贴出来的链接上的代码,一个删除图标的方法删除,然后再结束应用程序。
      

  6.   

    先找到任务栏窗体句柄,EnumChildWind找到托盘句柄,再找子窗体,然后判断是否属于QQ进程
    具体怎么弄 不是很清楚啊
      

  7.   

    系统托盘句柄倒是找到了,但是我用的是2003的系统,根本找不出除Explorer.exe以外的其它进程相关的句柄……
       TaskBar:=FindWindow('Shell_TrayWnd',nil);
       TrayWnd:=FindWindowEx(TaskBar,0,'TrayNotifyWnd',nil);
      

  8.   

    呵呵!!一个简单的方法!!在关闭的之前先让那个托盘程序窗口正常化,但是不窗口的Visible为False然后执行Application.termina
      

  9.   

    以下是我的代码!解决了你说的这个问题哈!!!//----------------------------
    unit UnitfrmTuoPanMain;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,ShellAPI, Menus, StdCtrls, ExtCtrls;const
      mymsg = wm_user + 1;
      iid = 100;type
      TfrmTuoPanMain = class(TForm)
        Button1: TButton;
        PopupMenu1: TPopupMenu;
        all: TMenuItem;
        cll: TMenuItem;
        Image1: TImage;
        Label1: TLabel;
        Image2: TImage;
        Button2: TButton;
        procedure Button1Click(Sender: TObject);
        procedure allClick(Sender: TObject);
        procedure cllClick(Sender: TObject);
        procedure FormClose(Sender: TObject; var Action: TCloseAction);
        procedure Button2Click(Sender: TObject);
      private
        { Private declarations }
        //--消息处理
        procedure mymessage(var message:tmessage);
        message mymsg;    //--还原窗口
        procedure HyWindow();
        //--最小化窗口
        procedure ZxhWindow();
        //--在托盘中退出
        procedure ExitInTuoPan();  public
        { Public declarations }
      end;var
      frmTuoPanMain: TfrmTuoPanMain;
      ntid: TnotifyIconDataA;
    implementation{$R *.dfm}
    //**私有函数实现区******************
    //处理鼠标右键,弹出菜单
    procedure TfrmTuoPanMain.mymessage(var message:tmessage );
    var
      mypt:Tpoint;
    begin
      Inherited;
      if message.LParam = WM_RBUTTONUP then
      begin
        getCursorPos(mypt);
        PopupMenu1.Popup(mypt.X, mypt.Y);
      end
      else if message.LParam = WM_LBUTTONUP then
      begin
        self.HyWindow;
      end;  message.Result := 0;
    end;
    //----------------------------
    //--还原窗口
    procedure TfrmTuoPanMain.HyWindow();
    begin
      ntid.cbSize := sizeof(TnotifyIconDataA);
      ntid.Wnd := Handle;
      ntid.uID := iid;
      ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
      ntid.uCallbackMessage := mymsg;
      ntid.hIcon := image1.Picture.Icon.Handle;
      ntid.szTip := '联网办公';
      shell_notifyicona(NIM_DELETE,@ntid);  self.Visible := true;end;
    //----------------------------
    //--最小化窗口
    procedure TfrmTuoPanMain.ZxhWindow();
    begin
      ntid.cbsize := sizeof(TnotifyIconDataA);
      ntid.Wnd := Handle;
      ntid.uID := iid;
      ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
      ntid.uCallbackMessage := mymsg;
      ntid.hIcon := image1.Picture.Icon.Handle;
      ntid.szTip := '联网办公';
      shell_notifyicona(NIM_ADD,@ntid);  self.Visible := false;end;//----------------------------
    //--在托盘中退出
    procedure TfrmTuoPanMain.ExitInTuoPan();
    begin
       ntid.cbSize := sizeof(TnotifyIconDataA);
       ntid.Wnd := Handle;
       ntid.uID := iid;
       ntid.uFlags := NIF_ICON + NIF_TIP + NIF_MESSAGE;
       ntid.uCallbackMessage := mymsg;
       ntid.hIcon := image1.Picture.Icon.Handle;
       ntid.szTip := '联网办公';
       shell_notifyicona(NIM_DELETE,@ntid);   self.Visible := false;   application.Terminate;end;//**Form构件事件处理区******************
    //隐藏窗口,在托盘上显示图标
    procedure TfrmTuoPanMain.Button1Click(Sender: TObject);
    begin
        self.ZxhWindow;
    end;//还原窗口,托盘图标消失
    procedure TfrmTuoPanMain.allClick(Sender: TObject);
    begin
      self.HyWindow;
    end;procedure TfrmTuoPanMain.cllClick(Sender: TObject);
    begin
        self.ExitInTuoPan;
    end;procedure TfrmTuoPanMain.FormClose(Sender: TObject;
      var Action: TCloseAction);
    begin
        self.ZxhWindow;
        abort;
    end;procedure TfrmTuoPanMain.Button2Click(Sender: TObject);
    begin
        application.Terminate;
    end;end.
      

  10.   

    terminalprocess是一个强制关闭进程函数
    ms中提到过,这个函数不推荐使用,因为很多内部的析构函数,如dll释放等
    都不会被调用到,从而引起内存的泄漏