Skip to content

Commit 497541b

Browse files
committed
主窗口设置了总是置顶时,以主窗口为父窗口弹出的窗口不再置顶
1 parent 5f18357 commit 497541b

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

TrafficMonitor/BaseDialog.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "afxdialogex.h"
77
#include "IniHelper.h"
88
#include "TrafficMonitor.h"
9+
#include "TrafficMonitorDlg.h"
910

1011
// CBaseDialog 对话框
1112
std::map<CString, HWND> CBaseDialog::m_unique_hwnd;
@@ -38,6 +39,16 @@ const std::map<CString, HWND>& CBaseDialog::AllUniqueHandels()
3839
return m_unique_hwnd;
3940
}
4041

42+
bool CBaseDialog::IsAllDialogClosed()
43+
{
44+
for (const auto& hwnd : m_unique_hwnd)
45+
{
46+
if (hwnd.second != nullptr)
47+
return false;
48+
}
49+
return true;
50+
}
51+
4152
void CBaseDialog::LoadConfig()
4253
{
4354
if (!GetDialogName().IsEmpty())
@@ -117,6 +128,8 @@ BOOL CBaseDialog::OnInitDialog()
117128
SetWindowPos(nullptr, 0, 0, m_window_size.cx, m_window_size.cy, SWP_NOZORDER | SWP_NOMOVE);
118129
}
119130

131+
SetWindowPos(&wndNoTopMost, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE); //取消置顶
132+
120133
return TRUE; // return TRUE unless you set the focus to a control
121134
// 异常: OCX 属性页应返回 FALSE
122135
}
@@ -129,6 +142,11 @@ void CBaseDialog::OnDestroy()
129142
// TODO: 在此处添加消息处理程序代码
130143
m_unique_hwnd[GetDialogName()] = NULL;
131144
SaveConfig();
145+
146+
//当所有对话框关闭时重新设置主窗口置顶
147+
CTrafficMonitorDlg* pDlg = dynamic_cast<CTrafficMonitorDlg*>(theApp.m_pMainWnd);
148+
if (pDlg != nullptr && IsAllDialogClosed())
149+
pDlg->SetAlwaysOnTop();
132150
}
133151

134152

TrafficMonitor/BaseDialog.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class CBaseDialog : public CDialog
2121
void SetMinSize(int cx, int cy); //设置窗口的最小大小,如果未设置,则使用窗口的初始大小作为最小大小
2222
static HWND GetUniqueHandel(LPCTSTR dlg_name); //获指定窗口唯一的句柄
2323
static const std::map<CString, HWND>& AllUniqueHandels(); //获取所有窗口的句柄
24+
static bool IsAllDialogClosed();
2425

2526
private:
2627
void LoadConfig();

TrafficMonitor/TrafficMonitorDlg.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,9 @@ class CTrafficMonitorDlg : public CDialog
129129
CString GetMouseTipsInfo(); //获取鼠标提示信息
130130
void SetTransparency(); //根据m_transparency的值设置窗口透明度
131131
void SetTransparency(int transparency);
132+
public:
132133
void SetAlwaysOnTop(); //根据m_always_on_top的值设置窗口置顶
134+
protected:
133135
void SetMousePenetrate(); //根据m_mouse_penetrate的值设置是否鼠标穿透
134136
POINT CalculateWindowMoveOffset(CRect rect, bool screen_changed); //计算当窗口处于屏幕区域外时,移动到屏幕区域需要移动的位置
135137
void CheckWindowPos(bool screen_changed = false); //测试窗口的位置,如窗口的位置在屏幕外,则移动窗口使其全部都在屏幕内,并返回新位置

0 commit comments

Comments
 (0)