Skip to content

Commit

Permalink
Change the close button behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
inte2000 committed Oct 30, 2021
1 parent bee3773 commit 994a229
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
35 changes: 12 additions & 23 deletions ui_mon/MainDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,12 @@ BOOL CMainDlg::OnInitDialog( HWND hWnd, LPARAM lParam )

UpdateValueToControl();

STabCtrl* pTabCtrl = FindChildByName2<STabCtrl>(L"tab_main");
if (pTabCtrl != nullptr)
pTabCtrl->SetCurSel(0);
#ifdef _DEBUG
CSimpleWnd::SetTimer(TIMER_THEME_CHECK, 10 * 1000, NULL);//10 秒钟检查一次
#else
CSimpleWnd::SetTimer(TIMER_THEME_CHECK, 5 * 60 * 1000, NULL);//5 分钟检查一次
#endif

AdjustPositionBySystemDpi();

m_bLayoutInited = TRUE;
return 0;
}
Expand All @@ -99,24 +94,6 @@ void CMainDlg::OnClose()
DestroyWindow();
}

void CMainDlg::AdjustPositionBySystemDpi()
{
int nCurScale = ScaleFromSystemDpi(GetSystemDeviceDpi());

int nOriginalScale = 100; //our skin default design as 96dpi
CRect rcWnd = GetWindowRect();
int OriWid = rcWnd.Width() * 100 / nOriginalScale;
int OriHei = rcWnd.Height() * 100 / nOriginalScale;

int nNewWid = OriWid * nCurScale / 100;
int nNewHei = OriHei * nCurScale / 100;

//SDispatchMessage(UM_SETSCALE, nCurScale, 0);

if (!CSimpleWnd::IsZoomed()) {
SetWindowPos(NULL, 0, 0, nNewWid, nNewHei, SWP_NOZORDER);
}
}

void CMainDlg::OnDpiChanged(WORD dpi, const RECT* desRect)
{
Expand Down Expand Up @@ -208,6 +185,18 @@ void CMainDlg::OnTimer(UINT_PTR idEvent)
}
}

void CMainDlg::OnSysBtnClose()
{
if (IsWindowVisible())
ShowWindow(SW_HIDE);
else
{
ShowWindow(SW_SHOW);
SetForegroundWindow(m_hWnd);
}
}


void CMainDlg::InitDarkModePage()
{
CAppConfig& cfg = GetAppConfig();
Expand Down
3 changes: 2 additions & 1 deletion ui_mon/MainDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class CMainDlg : public CFrmWndImpl, public TAutoEventMapReg<CMainDlg>//通知
void OnCommand(UINT uNotifyCode, int nID, HWND wndCtl);
void OnInitMenuPopup(SMenuEx* menuPopup, UINT nIndex);
void OnTimer(UINT_PTR idEvent);
void OnSysBtnClose();

//Dark mode page
void InitDarkModePage();
Expand Down Expand Up @@ -77,6 +78,7 @@ class CMainDlg : public CFrmWndImpl, public TAutoEventMapReg<CMainDlg>//通知
protected:

EVENT_MAP_BEGIN()
EVENT_NAME_COMMAND(L"btn_close", OnSysBtnClose)
EVENT_NAME_COMMAND(L"radio_light", OnRadLightClicked)
EVENT_NAME_COMMAND(L"radio_dark", OnRadDarkClicked)
EVENT_NAME_COMMAND(L"radio_auto", OnRadAutoClicked)
Expand Down Expand Up @@ -122,7 +124,6 @@ class CMainDlg : public CFrmWndImpl, public TAutoEventMapReg<CMainDlg>//通知
REFLECT_NOTIFICATIONS_EX()
END_MSG_MAP()

void AdjustPositionBySystemDpi();
BOOL UpdateControlToValue();
BOOL UpdateValueToControl();
void UpdateThemeModeRadio(int nThemeMode);
Expand Down

0 comments on commit 994a229

Please sign in to comment.