我用FindWindow找到一个窗口(用MessageBox弹出的,可能不属于本应用程序),然后我希望把它设置为topmost状态即置于屏幕的最前面且是激活的,而且关闭该窗口后我原来的程序应仍是active的即有焦点,我试了ShowWindow,但实现不了,有什么办法实现吗?请高手帮忙,很急用,谢谢!!!!

解决方案 »

  1.   

    protected
       procedure CreateParams(var Param:TCreateParams);override;...
    procedure TForm2.CreatePrams(Var Param:TCreateParams);
    begin
      inherited CreateParams(Param);
      with Param do
      begin
        ExStyle:=ExStyle or WS_EX_TOPMOST or WS_EX_DLGFRAME or WS_EX_TOOLWINDOW;
        WndParent := GetDesktopWindow;
      end;
    end; 
      

  2.   

    SetWindowPos(Handle, HWND_TOPMOST, ...)
      

  3.   

    Form1.FormStyle := fsStayOnTop;
      

  4.   

    renzy205朋友:
       你好! 
       根据你的方法我把SetWindowPos(Handle, HWND_TOPMOST, ...)放定时器中如下:
    procedure Tfrm_Main.Timer3Timer(Sender: TObject);
    var
    H:HWnd;
    begin
      H:=0;
      H:=FindWindow(nil,PChar('HF_Main'));
      SetWindowPos(H, HWND_TOPMOST,0,0,300,300,SWP_SHOWWINDOW);
      SetActiveWindow(H);
    end;
    能把窗口置于topmost,第一次也能有输入焦点,但以后当我切换到一个程序后该定时器能定期将窗口置于topmost且有光标闪烁却丢了焦点即无法输入,此时焦点在别的程序中,该怎么解决呢?另外如何得到当前屏幕中激活的有焦点可接受输入的窗口
    呢?
       比较急用,请帮忙看看,万分感谢!!!