怎样判断一个窗口是否具有键盘输入焦点?

解决方案 »

  1.   

    HWND GetTopWindow( HWND hWnd);
    ParametershWnd
    [in] Handle to the parent window whose child windows are to be examined. If this parameter is NULL, the function returns a handle to the window at the top of the Z order. 
    Return ValueIf the function succeeds, the return value is a handle to the child window at the top of the Z order. If the specified window has no child windows, the return value is NULL. To get extended error information, use the GetLastError function. 如果傳入nil, 就能得到
    >>当前拥有焦点窗口
      

  2.   

    var
      wHandle: THandle;
    begin
      wHandle := GetForegroundWindow;
      ...
    end;
      

  3.   

    The GetForegroundWindow function returns the handle of the foreground window (the window with which the user is currently working). The system assigns a slightly higher priority to the thread that creates the foreground window than it does to other threads. HWND GetForegroundWindow(VOID)
     ParametersThis function has no parameters. Return ValuesThe return value is the handle of the foreground window