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;
}
{
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);
}
相关文章推荐
- Options for mounting NFS filesystem
- 联合索引详解
- (Android)截图批处理
- 【渗透测试学习平台】 web for pentester -6.命令执行
- PAT (Basic Level) Practise-1011
- 左偏树
- POM(Project Object Model)项目对象模型详解
- PHP使用APC的主要用处(个人观点)
- 组合数性质
- [sql]分页查询
- js 时间戳转yyyy-MM-dd
- tarjan算法应用之割边和割点
- POJ3122
- STM32F1学习-独立看门狗
- 重建控制文件时resetlogs与noresetlogs的使用情况
- android中getCompoundDrawables()方法,设置文本框中图片的位置
- Windows下从零开始学习nodejs4.X+express4.X开发--(1)nodejs安装
- Windows下从零开始学习nodejs4.X+express4.X开发--(2)nodejs交互环境
- 【渗透测试学习平台】 web for pentester -5.代码执行
- hdfs HA + MR HA