Windows XP中的问题两个程序,一个程序A,一个程序B,其中,A是MDI风格的程序。当A程序运行的时候,单击右上角的最小化按钮,程序就最小化到任务栏中了,如何在程序B中将程序A最大化,并让程序A获得焦点

解决方案 »

  1.   

    在程序B的按钮中写如下代码:
    var
      handle : THandle;
    begin 
      handle := FindWindow('','B程序的标题');
      SendMessage(handle,WM_SYSCOMMAND,SC_MAXIMIZE,0);
      SetActiveWindow(handle);
    end;
      

  2.   

    To  Drate(小虫)
    其实我是要做一个只允许运行一次的程序,我希望,如果程序已经启动了,再次启动的时候代码如下:自动切换到已经启动的程序上。
    当我第一次启动的程序不是最小化的时候,第二次启动程序的时候可以自动机获第一次启动的程序,但是如果我把第一次启动的程序最小化的时候,第二次在运行程序就不行了。不知道是不是WindowsXP的原因。我只有WindowsXP.program MobileTest;uses
      Controls,
      Forms,
      Windows,
      SysUtils,
      Messages,
      uForm1 in 'uMDIFrame.pas' {Form1};
    {$R *.res}var
      hMutex:hwnd;
      ret,iHandle:integer;
      sName:String;
    begin
      Application.Initialize;  sName:=Lowercase(StringReplace(Application.ExeName,'\','',[rfReplaceAll]));
      hMutex:=CreateMutex(nil,false,PChar(sName));
      ret:=GetLastError;
      if ret=ERROR_ALREADY_EXISTS then
      begin
        ReleaseMutex(hMutex);    iHandle:=FindWindow('TForm1',nil);
        if iHandle<>0 then
        begin
          SendMessage(iHandle,WM_SYSCOMMAND,SC_MAXIMIZE,0);
          SetActiveWindow(iHandle);
          SetForegroundWindow(iHandle);
        end
        else
          MessageBox(Application.Handle,'抱歉,本程序已经在运行!','系统提示' ,
                     MB_OK + MB_DEFBUTTON1 + MB_ICONEXCLAMATION);
       exit;
     end;  Screen.Cursor:=crHourGlass;
      Application.CreateForm(TForm1, Form1);
      Application.Run;
    end.
      

  3.   

    防止程序的多次运行    
      互斥对象(CreateMutex)应该是最好的方法 
    //项目文件...beginApplication.initialation;if CreateMutex then beginApplication.CreateForm(Form1, TForm1);Application.Run;end elseDestroyMutex;end;//主窗体文件...implementationvarMutex: hWnd;function CreateMutex: Boolean;varPrevInstHandle: THandle;AppTitle: PChar;beginAppTitle := StrAlloc(100);StrPCopy(AppTitle, Application.Title);Result := True;Mutex := Windows.CreateMutex(nil, False, AppTitle);if (GetLastError = ERROR_ALREADY_EXISTS) or (Mutex = 0) then beginResult := False;SetWindowText(Application.Handle, '');PrevInstHandle := FindWindow(nil, AppTitle);if PrevInstHandle <> 0 then beginif IsIconic(PrevInstHandle) thenShowWindow(PrevInstHandle, SW_RESTORE)elseBringWindowToTop(PrevInstHandle);SetForegroundWindow(PrevInstHandle);end;if Mutex <> 0 thenMutex := 0;end;StrDispose(AppTitle);end;procedure DestroyMutex;beginif Mutex <> 0 thenCloseHandle(Mutex);end; 
     
       
      

  4.   

    TO  Drate(小虫)
    不知道你注意看没有,我的程序也用的是互斥对象,只不过我希望第二次启动的时候自动把焦点切换到第一次的程序中,现在的问题是当第一次启动的程序最小化后,无法自动切换到第一次启动的程序
      

  5.   

    我试过了,用
    if IsIconic(PrevInstHandle) then
    ShowWindow(PrevInstHandle, SW_RESTORE)
    也不行