vc中获取焦点的一些常用方法

来源:互联网 发布:网络歌曲大全2016 编辑:程序博客网 时间:2024/06/11 14:26
 

      ::SetFocus(GetHwnd());
    const HWND hFore = ::GetForegroundWindow();
          const DWORD dwThreadIdFore = ::GetWindowThreadProcessId( hFore, NULL);
    BOOL bAttatched = FALSE;
    const dwCurThreadID = ::GetCurrentThreadId();
    if( dwThreadIdFore !=  dwCurThreadID ) 
    {//调SetForegroundWindow,SetActiveWindow,SetFocus,BringWindowToTop, SetWindowsPos

     ::AttachThreadInput( dwThreadIdFore, dwCurThreadID, TRUE );
     bAttatched = TRUE;
    }
    
    HWND hWnd = GetHwnd();
    
    SetForegroundWindow( hWnd );
    ::SetActiveWindow( hWnd );
    ::SetFocus( hWnd );
    BringWindowToTop( hWnd );
    
    if ( bAttatched )
     ::AttachThreadInput( dwThreadIdFore, dwCurThreadID, FALSE );
    BringWindowToTop( hWnd );

    //::SetForegroundWindow(GetHwnd());
    //::SetActiveWindow(GetHwnd());

原创粉丝点击