note that the Windows Explorer must be running for this example to work}
procedure TForm1.Button1Click(Sender: TObject);
var
   TheWindow: HWND;
begin
   {find a handle to the Windows Explorer window}
   TheWindow:=FindWindow('ExploreWClass',nil);   {bring it into the foreground}
   SetForegroundWindow(TheWindow);
end;The form for this project has its FormStyle property set to fsStayOnTop so it is visible when other applications have the focus. This code is fired from a timer set at 250 milliseconds.procedure TForm1.Timer1Timer(Sender: TObject);
var
   TheWindowText: array[0..255] of char;
   TheForegroundWindow: HWND;
begin
   {get a handle to the foreground window}
   TheForegroundWindow:=GetForegroundWindow;   {get it's caption text}   GetWindowText(TheForegroundWindow, TheWindowText, 255);   {display the foreground window's caption}
   Label2.Caption:='Foreground Window Text: '+TheWindowText;
end;

解决方案 »

  1.   

    var
      H:THandle;//the handle of a FormSetForegroundWindow(H);//设这个窗体为当前窗体;
    H:=GetForegroundWindow;//取得当前窗体的句柄
      

  2.   

    函数功能:该函数将创建指定窗口的线程设置到前台,并且激活该窗口。键盘输入转向该窗口,并为用户改各种可视的记号。系统给创建前台窗口的线程分配的权限稍高于其他线程。    函数原型:BOOL SetForegroundWindow(HWND hWnd)    参数:    hWnd:将被激活并被调入前台的窗口句柄。    返回值:如果窗口设入了前台,返回值为非零;如果窗口未被设入前台,返回值为零。    备注:前台窗口是z序顶部的窗口,是用户的工作窗口。在一个多任务优先抢占环境中,应让用户控制前台窗口。    Windows NT 5.0:当用户在另一个窗口中工作时,应用程序不能强行设置一个窗口到前台。相反,SetForeground函数将会激活窗口并且调用FlashWindowEx函数通知用户。
     函数功能:该函数返回前台窗口(用户当前工作的窗口)。系统分配给产生前台窗口的线程一个稍高一点的优先级。    函数原型:HWND GetForegroundwindow(VOID)    参数:无。    返回值:函数返回前台窗回的句柄