首页  编辑  

取得系统中当前焦点所在

Tags: /超级猛料/API.Windows应用程序接口/窗口和控件相关/   Date Created:
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;