Skip to content

Commit b1b7608

Browse files
committed
开启全屏时隐藏主窗口功能时,仅当主窗口所在的显示器全屏时才隐藏主窗口 #1954
1 parent d8144e4 commit b1b7608

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

TrafficMonitor/Common.cpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -601,24 +601,31 @@ void CCommon::DrawWindowText(CDC* pDC, CRect rect, LPCTSTR lpszString, COLORREF
601601
//}
602602

603603

604-
bool CCommon::IsForegroundFullscreen()
604+
bool CCommon::IsForegroundFullscreen(HMONITOR hMonitor)
605605
{
606+
if (hMonitor == NULL)
607+
hMonitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
606608
bool bFullscreen{ false }; //用于指示前台窗口是否是全屏
607-
HWND hWnd;
608-
RECT rcApp;
609-
RECT rcDesk;
609+
HWND hWnd{};
610+
RECT rcApp{};
611+
612+
// 获取显示器信息
613+
MONITORINFOEX monitorInfo{};
614+
monitorInfo.cbSize = sizeof(monitorInfo);
615+
GetMonitorInfo(hMonitor, &monitorInfo);
616+
RECT monitorRect = monitorInfo.rcMonitor;
617+
610618
hWnd = GetForegroundWindow(); //获取当前正在与用户交互的前台窗口句柄
611619
TCHAR buff[256];
612620
GetClassName(hWnd, buff, 256); //获取前台窗口的类名
613621
CString class_name{ buff };
614622
if (hWnd != GetDesktopWindow() && class_name != _T("WorkerW") && hWnd != GetShellWindow())//如果前台窗口不是桌面窗口,也不是控制台窗口
615623
{
616624
GetWindowRect(hWnd, &rcApp); //获取前台窗口的坐标
617-
GetWindowRect(GetDesktopWindow(), &rcDesk); //根据桌面窗口句柄,获取整个屏幕的坐标
618-
if (rcApp.left <= rcDesk.left && //如果前台窗口的坐标完全覆盖住桌面窗口,就表示前台窗口是全屏的
619-
rcApp.top <= rcDesk.top &&
620-
rcApp.right >= rcDesk.right &&
621-
rcApp.bottom >= rcDesk.bottom)
625+
if (rcApp.left <= monitorRect.left && //如果前台窗口的坐标完全覆盖住桌面窗口,就表示前台窗口是全屏的
626+
rcApp.top <= monitorRect.top &&
627+
rcApp.right >= monitorRect.right &&
628+
rcApp.bottom >= monitorRect.bottom)
622629
{
623630
bFullscreen = true;
624631
}

TrafficMonitor/Common.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -202,16 +202,12 @@ class CCommon
202202
////设置绘图的剪辑区域
203203
//static void SetDrawArea(CDC* pDC, CRect rect);
204204

205-
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
206-
* 函数名称:IsForegroundFullscreen
207-
* 功能说明:判断当前正在与用户交互的前台窗口是否是全屏的。
208-
* 参数说明:无
209-
* 返回说明:true:是。
210-
false:否。
211-
* 线程安全:是
212-
* 调用样例:IsForegroundFullscreen (),表示判断当前正在与用户交互的前台窗口是否是全屏的。
213-
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
214-
static bool IsForegroundFullscreen();
205+
/**
206+
* 判断当前正在与用户交互的前台窗口是否是全屏的
207+
* @param[in] hMonitor 要判断的显示器(如果为空,则指定为主显示器)
208+
* @return
209+
*/
210+
static bool IsForegroundFullscreen(HMONITOR hMonitor = NULL);
215211

216212
//将一个字符串保存到剪贴板
217213
static bool CopyStringToClipboard(const wstring& str);

TrafficMonitor/TrafficMonitorDlg.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,10 @@ void CTrafficMonitorDlg::OnTimer(UINT_PTR nIDEvent)
15911591
if (theApp.m_main_wnd_data.m_always_on_top && !theApp.m_cfg_data.m_hide_main_window)
15921592
{
15931593
//每隔1秒钟就判断一下前台窗口是否全屏
1594-
m_is_foreground_fullscreen = CCommon::IsForegroundFullscreen();
1594+
CRect rect;
1595+
GetWindowRect(rect);
1596+
HMONITOR h_current_monitor = ::MonitorFromRect(&rect, MONITOR_DEFAULTTONEAREST);
1597+
m_is_foreground_fullscreen = CCommon::IsForegroundFullscreen(h_current_monitor);
15951598
if (theApp.m_main_wnd_data.hide_main_wnd_when_fullscreen) //当设置了全屏时隐藏悬浮窗时
15961599
{
15971600
if (m_is_foreground_fullscreen || theApp.m_cfg_data.m_hide_main_window)

0 commit comments

Comments
 (0)