windows判断窗口是否置顶、设置取消置顶、设置前景
来源:互联网 发布:数据的重要性 编辑:程序博客网 时间:2024/05/02 02:49
判断窗口是否置顶
bool isWndTopMost(HWND hwnd) { return GetWindowLong(hwnd, GWL_EXSTYLE) & WS_EX_TOPMOST; }
设置和取消置顶
void showWndTopMost(HWND hwnd){ RECT rect; GetWindowRect(hwnd, &rect); SetWindowPos(hwnd, HWND_TOPMOST, rect.left, rect.top, abs(rect.right - rect.left), abs(rect.bottom - rect.top), SWP_SHOWWINDOW); } void cancelTopMost(HWND hwnd){ RECT rect; GetWindowRect(hwnd, &rect); SetWindowPos(hwnd, HWND_NOTOPMOST, rect.left, rect.top, abs(rect.right - rect.left), abs(rect.bottom - rect.top), SWP_SHOWWINDOW); }
设置窗口前景
void showWndTop(HWND hWnd){ if (!::IsWindow(hWnd)) return; if (!::SetForegroundWindow(hWnd)) { WinParameter winParameter; ::SetForegroundWindow(hWnd) } }
WinParameter是为了解决某些特殊情况下设置失败的问题
#ifndef WINPARAMETER_H#define WINPARAMETER_Hclass WinParameter {public: WinParameter(); ~WinParameter();private: unsigned long m_lockTimeOut;};#endif // WINPARAMETER_H///////////////////////////////////////////////////////#include "winparameter.h"#include <windows.h>WinParameter::WinParameter(){ m_lockTimeOut = 0; HWND hCurrWnd = ::GetForegroundWindow(); unsigned long dwThisTID = ::GetCurrentThreadId(); unsigned long dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd,0); //we need to bypass some limitations from Microsoft :) if(dwThisTID != dwCurrTID) { ::AttachThreadInput(dwThisTID, dwCurrTID, TRUE); ::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT,0,&m_lockTimeOut,0); ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,0,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE); ::AllowSetForegroundWindow(ASFW_ANY); }}WinParameter::~WinParameter(){ HWND hCurrWnd = ::GetForegroundWindow(); unsigned long dwThisTID = ::GetCurrentThreadId(); unsigned long dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd,0); if(dwThisTID != dwCurrTID) { ::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT,0,(PVOID)m_lockTimeOut,SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE); ::AttachThreadInput(dwThisTID, dwCurrTID, FALSE); }}
0 0
- windows判断窗口是否置顶、设置取消置顶、设置前景
- 设置windows窗口置顶
- 窗口置顶/取消置顶
- 设置窗口置顶
- 窗口置顶/取消置顶工具
- MFC 设置窗口置顶显示
- 取消窗口置顶属性
- 取消窗口置顶
- Qt 实现窗口置顶与取消置顶
- FastReport调用进程句柄,设置窗口置顶
- 窗口置顶
- 窗口置顶
- 窗口置顶
- 窗口置顶
- 窗口置顶
- [置顶] Android selector设置详解
- textView中的文字置顶设置
- 把windows窗口置顶--Windows on Top
- 关于对象/数组的深拷贝
- C语言及ARM中堆栈指针SP设置的理解与总结
- 模拟网页分页(注意,这里还是取出来数据库的全部内容,其实应该分页获取)
- Android 带你彻底理解 Window 和 WindowManager
- Linux 进程间通信之 消息队列
- windows判断窗口是否置顶、设置取消置顶、设置前景
- zabbix安装配置
- js中将字符串转换成json的三种方式
- QComboBox item文字重叠
- 设计模式学习之过滤器模式
- 【设计模式】解释器模式
- 哈希表-二级指针
- Struts+JQuery实现ajax并返回json数据
- 开公司(排列枚举、DFS)