var
HWndCalculator : HWnd;
ClassName:string;
begin
// find the exist calculator window
HWndCalculator := FindWindow(nil, '扫雷');
// close the exist Calculator
SetLength(ClassName,25);
GetClassName(HWndCalculator,Pchar(ClassName),25);//文件夹的类名和程序的类名是不一样的.
showmessage(classname);
if HWndCalculator<>0 then
PostMessage(HWndCalculator, WM_CLOSE, 0, 0);
end;
function GetSysFocus: Integer;
var
hFgWin, FgThreadID, hFocusWin: Integer;
begin
hFgWin := GetForegroundWindow;
FgThreadID := GetWindowThreadProcessID(hFgWin, nil);
if AttachThreadInput(GetCurrentThreadID, FgThreadID, True) then
begin
hFocusWin := GetFocus;
Result := GetFocus;
AttachThreadInput(GetCurrentThreadID, FgThreadID, False);
end
else
Result := GetFocus;
end;