改成GetForegroundWindow()就可以了。如下var hw : THandle; begin hw :=GetForegroundWindow(); if hw>0 then begin SetWindowText(hw,'新标题'); SpinEdit1.Value := SpinEdit1.Value + 1; end; end;
procedure TForm1.tmrChangeCapTimer(Sender: TObject); var TheWindowText: array[0..255] of char; TheForegroundWindow: HWND; begin {get a handle to the foreground window} TheForegroundWindow:=GetForegroundWindow; GetWindowText(TheForegroundWindow, TheWindowText, 255); {display the foreground window's caption} self.Label1.Caption:='Foreground Window Text: '+TheWindowText; windows.SetWindowText(TheForegroundWindow, 'helloworld') end;
hw : THandel;
begin
hw :=GetActiveWindow();
if hw>0 then
SetWindowText(hw,'新标题');
end;
self.caption:='未激活';
hw : THandle;
begin
hw :=GetForegroundWindow();
if hw>0 then
begin
SetWindowText(hw,'新标题');
SpinEdit1.Value := SpinEdit1.Value + 1;
end;
end;
var
TheWindowText: array[0..255] of char;
TheForegroundWindow: HWND;
begin
{get a handle to the foreground window}
TheForegroundWindow:=GetForegroundWindow; GetWindowText(TheForegroundWindow, TheWindowText, 255); {display the foreground window's caption}
self.Label1.Caption:='Foreground Window Text: '+TheWindowText;
windows.SetWindowText(TheForegroundWindow, 'helloworld')
end;