您的位置:首页 > 其它

SetForeGroundWindow

2016-07-21 16:59 274 查看
BOOL CDlg::SetForeGroundWindowEx()

{
HWND hForeWnd = NULL; 
HWND hWnd= GetSafeHwnd(); 
DWORD dwForeID; 
DWORD dwCurID; 

hForeWnd = ::GetForegroundWindow(); 
dwCurID =  ::GetCurrentThreadId(); 
dwForeID = ::GetWindowThreadProcessId( hForeWnd, NULL );
if (hForeWnd==GetSafeHwnd())//如果当前窗口已经是前景窗口 直接返回
   return TRUE;
if(!AttachThreadInput( dwCurID, dwForeID, TRUE)) //切换键盘输入焦点AttachThreadInput 
{

return FALSE;
}
//if(!ShowWindow(SW_SHOWNORMAL )) //显示窗口ShowWindow
//{
//
// return FALSE;
//}
if(!::SetWindowPos(hWnd,HWND_TOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE )) //更改窗口的Zorder,SetWindowPos使之最上,为了不影响后续窗口的Zorder,改完之后,再还原
{
return FALSE;
}
if(!::SetWindowPos(hWnd,HWND_NOTOPMOST, 0,0,0,0, SWP_NOSIZE|SWP_NOMOVE ))
{
return FALSE;
}
if(!SetForegroundWindow())
{
return FALSE;
}
return TRUE;

//AttachThreadInput( dwCurID, dwForeID, FALSE);


}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: