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;
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;
H:THandle;//the handle of a FormSetForegroundWindow(H);//设这个窗体为当前窗体;
H:=GetForegroundWindow;//取得当前窗体的句柄
函数功能:该函数返回前台窗口(用户当前工作的窗口)。系统分配给产生前台窗口的线程一个稍高一点的优先级。 函数原型:HWND GetForegroundwindow(VOID) 参数:无。 返回值:函数返回前台窗回的句柄