我有一主程序,使用CrateProcess方法,创建了一些程序。
现在我的主程序,需要在关闭的时候,先关闭打开的这些程序,现在我只有没有程序的进程ID,如何想鼠标单击任务栏程序那样,激活程序,界面按照当时的状态显示出来,并显示在最前面?
提示:每个小程序不一定显示的都是主Form,每个Form上还可能已经弹出来了模式窗体,这些如何正确激活并显示在最前面?就像鼠标单击windows下面的任务栏一样激活程序,程序的界面按照弹出的顺序显示

解决方案 »

  1.   

    EnumWindows, SendMessage, WndProc
    哈哈
      

  2.   

    一楼的,不要说空话,发个例子或者直接的代码上来,上面的东西我差试过,但是没有找到我要的东西,使用EnumWindows可以找到主Form,如果上面还有窗体的话,显示顺序就不正确了!
    我要的是实际的例子或代码,不要说个一句半句了,我现在都迷茫了,脑子已经归零了!
      

  3.   

    如果放上类似这样的代码还不行的话,
    你就告诉我你的邮箱,我把我做的测试程序发给你玩玩.procedure TForm1.WndProc(var AMessage: TMessage);
    begin
      if AMessage.Msg = WM_TEST then
      begin
        Application.Minimize;
        Application.Restore;
        Application.BringToFront;
        AMessage.Result := 0;
      end else
        inherited WndProc(AMessage);
    end;当然,也希望把你工资一并领了.
    哈哈
      

  4.   


    const
      LSFW_LOCK     = 1;
      LSFW_UNLOCK   = 2;
      function LockSetForegroundWindow(uLockCode: DWORD): BOOL; stdcall;
    var
      Form1: TForm1;
    implementation
      function LockSetForegroundWindow; external  'user32.dll' name 'LockSetForegroundWindow';
    {$R *.dfm}{ TForm1 }function wdSetForegroundWindow(Handle: THandle): Boolean;
    begin
      if ((Win32Platform = VER_PLATFORM_WIN32_NT) and (Win32MajorVersion> 4))//up win 2000
        or ((Win32Platform = VER_PLATFORM_WIN32_WINDOWS) and  //up win 98
        ((Win32MajorVersion > 4) or
        ((Win32MajorVersion = 4) and
        (Win32MinorVersion > 0)))) then
        LockSetForegroundWindow(LSFW_UNLOCK);
      Result := SetForegroundWindow(Handle);
    end;procedure TForm1.tmr1Timer(Sender: TObject);
    begin
      // Timer的Timer事件
      Application.Restore;
      wdSetForegroundWindow(Handle);
    end;
      

  5.   

    供参考:const
      CM_RESTORE=WM_USER+$1000;
      WZGL_APP_NAME='WZGL_System' ;  WM_WZGLNOTIFY=WM_USER+100;
      strNotifyTip='应用服务器';
      ID_MAIN=100;
    type
      TfrmMain = class(TForm)
        PopupMenu1: TPopupMenu;
        N1: TMenuItem;
        N2: TMenuItem;
        Database: TDatabase;
        procedure N1Click(Sender: TObject);
        procedure N2Click(Sender: TObject);
        procedure FormCreate(Sender: TObject);
        procedure FormDestroy(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure CreateParams(var Params:TCreateParams);override;
        procedure RestoreRequest(var message:TMessage);message CM_RESTORE;    function AddIcon(hwnd:HWND):Boolean;
        function RemoveIcon(hwnd:HWND):Boolean;
        procedure Notify(var Msg:Tmessage);message WM_WZGLNOTIFY;
        procedure minimize(Sender:Tobject);
        function DBConnect(aServerName,aDatabaseName,aUserName,aPassword:string):boolean;
      end;var
      frmMain: TfrmMain;
      nid:NOTIFYICONDATA;implementation
    uses DBConnectFrm;{$R *.dfm}
    function Tfrmmain.DBConnect(aServerName,aDatabaseName,aUserName,aPassword:string):boolean;
    begin
      Result:=True;
      Database.Connected:=false;
      Database.DriverName:='Mssql';
      Database.Params.Values['Server Name']:=aServerName;
      Database.Params.Values['Database Name']:=aDatabaseName;
      Database.Params.Values['User Name']:=aUserName;
      Database.Params.Values['Password']:=aPassword;  try
        Database.Connected:=true;
      except
        result:=false;
      end;    
    end;procedure Tfrmmain.CreateParams(var Params:TCreateParams);
    begin
      inherited CreateParams(Params);
      Params.WinClassName:=WZGL_APP_NAME;
    end;
    procedure Tfrmmain.RestoreRequest(var message:TMessage);
    begin
      if isIconic(Application.Handle)=true then
        Application.Restore
      else
        Application.BringToFront;
    end;
    function Tfrmmain.AddIcon(hwnd:HWND):Boolean;
    begin
      nid.cbSize:=sizeof(NOTIFYICONDATA);
      nid.Wnd:=Hwnd;
      nid.uID:=ID_Main;
      nid.uFlags:=NIF_MESSAGE or NIF_ICON OR NIF_TIP;
      nid.uCallbackMessage:=WM_WZGLNOTIFY;
      nid.hIcon:=loadicon(hinstance,'MAINICON');
      strcopy(nid.szTip,strnotifytip);
      addicon:=shell_Notifyicon(NIM_ADD,@nid);
    end;
    function Tfrmmain.RemoveIcon(hwnd:HWND):Boolean;
    var
      nid:NOTIFYICONDATA;
    begin
      nid.cbSize:=sizeof(NOTIFYICONDATA);
      nid.Wnd:=Hwnd;
      nid.uID:=ID_Main;
      nid.uFlags:= 0;
      RemoveIcon:=shell_Notifyicon(NIM_DELETE,@nid);
    end;
    procedure Tfrmmain.Notify(var Msg:Tmessage);
    var
      Pt:Tpoint;
    begin
      Case msg.LParam of
        WM_RBUTTONDOWN:
          begin
            SetForeGroundWindow(nid.Wnd);
            GetCursorPos(Pt);
            Popupmenu1.Popup(Pt.X,Pt.Y);
          end;
    end;
    end;
    procedure Tfrmmain.minimize(Sender:Tobject);
    begin
      Addicon(handle);
      Showwindow(Application.Handle,sw_hide);
    end;procedure TfrmMain.N1Click(Sender: TObject);
    begin
      removeicon(handle);
      showwindow(application.Handle,SW_SHOWNORMAL);
    end;