Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Add support for per-monitor DPI awareness #422

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
873e7da
WIP: Add support for per-monitor DPI awareness (1)
sdottaka Aug 30, 2020
246ea44
WIP: Add support for per-monitor DPI awareness (2)
sdottaka Aug 31, 2020
5fa531a
WIP: Add support for per-monitor DPI awareness (3)
sdottaka Sep 1, 2020
0af5dec
WIP: Add support for per-monitor DPI awareness (4)
sdottaka Sep 2, 2020
c8bd781
WIP: Add support for per-monitor DPI awareness (5)
sdottaka Sep 3, 2020
1dd085b
WIP: Add support for per-monitor DPI awareness (6)
sdottaka Sep 7, 2020
55bc261
WIP: Add support for per-monitor DPI awareness (7)
sdottaka Sep 10, 2020
59cf6d9
WIP: Add support for per-monitor DPI awareness (8)
sdottaka Sep 11, 2020
ae46e46
memcombo.cpp: The text width was calculated using the wrong font.WIP:…
sdottaka Sep 11, 2020
a36ba45
WIP: Add support for per-monitor DPI awareness (10)
sdottaka Sep 12, 2020
6e97245
WIP: Add support for per-monitor DPI awareness (11)
sdottaka Sep 16, 2020
f3dd809
WIP: Add support for per-monitor DPI awareness (12)
sdottaka Sep 16, 2020
11ec528
WIP: Add support for per-monitor DPI awareness (13)
sdottaka Sep 18, 2020
cfc8bfb
WIP: Add support for per-monitor DPI awareness (14)
sdottaka Sep 19, 2020
aefc0dd
WIP: Add support for per-monitor DPI awareness (15)
sdottaka Sep 22, 2020
3e3929c
WIP: Add support for per-monitor DPI awareness (16)
sdottaka Sep 24, 2020
79e87fd
WIP: Add support for per-monitor DPI awareness (17)
sdottaka Sep 25, 2020
0b14123
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Sep 28, 2020
fc33371
WIP: Add support for per-monitor DPI awareness (18)
sdottaka Oct 1, 2020
fa63e4f
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 2, 2020
241d706
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 3, 2020
53e0714
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 3, 2020
1560896
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 4, 2020
79633fc
WIP: Add support for per-monitor DPI awareness (19)
sdottaka Oct 4, 2020
7768cb0
WIP: Add support for per-monitor DPI awareness (20)
sdottaka Oct 12, 2020
12b26b0
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 12, 2020
01bbe73
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 18, 2020
3ee6ff9
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Oct 28, 2020
61632ed
Merge branch 'master' into per-monitor-dpi-aware
sdottaka Dec 2, 2022
4bd7698
Merge remote-tracking branch 'origin/master' into per-monitor-dpi-aware
sdottaka Dec 4, 2022
c1c172e
Merge branch 'master' into per-monitor-dpi-aware
sdottaka Jun 4, 2024
d04365b
WIP
sdottaka Jun 4, 2024
d118721
WIP
sdottaka Jun 4, 2024
8bacafa
WIP
sdottaka Jun 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 48 additions & 6 deletions Externals/crystaledit/Sample/ChildFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Sample.h"

#include "ChildFrm.h"
#include "MainFrm.h"

#ifdef _DEBUG
#define new DEBUG_NEW
Expand All @@ -15,10 +16,11 @@ static char THIS_FILE[] = __FILE__;
/////////////////////////////////////////////////////////////////////////////
// CChildFrame

IMPLEMENT_DYNCREATE(CChildFrame, CMDIChildWnd)
IMPLEMENT_DYNCREATE(CChildFrame, DpiAware::CDpiAwareWnd<CMDIChildWnd>)

BEGIN_MESSAGE_MAP(CChildFrame, CMDIChildWnd)
BEGIN_MESSAGE_MAP(CChildFrame, DpiAware::CDpiAwareWnd<CMDIChildWnd>)
//{{AFX_MSG_MAP(CChildFrame)
ON_WM_SIZE()
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
//}}AFX_MSG_MAP
Expand All @@ -41,8 +43,25 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CMDIChildWnd::PreCreateWindow(cs);
CMainFrame* pMainFrame = static_cast<CMainFrame*>(AfxGetMainWnd());
MDITileLayout::LayoutManager& layoutManager = pMainFrame->GetLayoutManager();
if (!layoutManager.GetTileLayoutEnabled())
return __super::PreCreateWindow(cs);
__super::PreCreateWindow(cs);
cs.style &= ~WS_CAPTION;
CRect rcMain;
::GetWindowRect(pMainFrame->m_hWndMDIClient, rcMain);
CRect rc = layoutManager.GetDefaultOpenPaneRect();
rc.left -= rcMain.left;
rc.top -= rcMain.top;
rc.right -= rcMain.left;
rc.bottom -= rcMain.top;
AdjustWindowRectEx(rc, cs.style, false, cs.dwExStyle);
cs.x = rc.left;
cs.y = rc.top;
cs.cx = rc.Width();
cs.cy = rc.Height();
return true;
}

/////////////////////////////////////////////////////////////////////////////
Expand All @@ -51,12 +70,12 @@ BOOL CChildFrame::PreCreateWindow(CREATESTRUCT& cs)
#ifdef _DEBUG
void CChildFrame::AssertValid() const
{
CMDIChildWnd::AssertValid();
__super::AssertValid();
}

void CChildFrame::Dump(CDumpContext& dc) const
{
CMDIChildWnd::Dump(dc);
__super::Dump(dc);
}

#endif //_DEBUG
Expand All @@ -66,5 +85,28 @@ void CChildFrame::Dump(CDumpContext& dc) const

BOOL CChildFrame::OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext)
{
static_cast<CMainFrame*>(AfxGetMainWnd())->GetLayoutManager().NotifyChildOpened(this);
return m_wndSplitter.Create(this, 2, 2, CSize(30, 30), pContext);
}

BOOL CChildFrame::DestroyWindow()
{
static_cast<CMainFrame*>(AfxGetMainWnd())->GetLayoutManager().NotifyChildClosed(this);
return __super::DestroyWindow();
}

void CChildFrame::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
if (nType == SIZE_MAXIMIZED && IsDifferentDpiFromSystemDpi())
{
// This is a workaround of the problem that the maximized MDI child window is in the wrong position when the DPI changes
// I don't think MDI-related processing inside Windows fully supports per-monitor dpi awareness
CRect rc;
GetParent()->GetClientRect(rc);
AdjustWindowRectEx(&rc, GetStyle(), FALSE, GetExStyle());
SetWindowPos(nullptr, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_NOZORDER | SWP_NOACTIVATE);
}
static_cast<CMainFrame*>(AfxGetMainWnd())->GetLayoutManager().NotifyChildResized(this);
}

6 changes: 5 additions & 1 deletion Externals/crystaledit/Sample/ChildFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#pragma once

class CChildFrame : public CMDIChildWnd
#include "utils/DpiAware.h"

class CChildFrame : public DpiAware::CDpiAwareWnd<CMDIChildWnd>
{
DECLARE_DYNCREATE(CChildFrame)
public:
Expand All @@ -24,6 +26,7 @@ class CChildFrame : public CMDIChildWnd
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
protected:
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
virtual BOOL DestroyWindow();
//}}AFX_VIRTUAL

// Implementation
Expand All @@ -40,6 +43,7 @@ class CChildFrame : public CMDIChildWnd
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG
afx_msg void OnSize(UINT nType, int cx, int cy);
DECLARE_MESSAGE_MAP()
};

Expand Down
78 changes: 69 additions & 9 deletions Externals/crystaledit/Sample/MainFrm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,22 @@ static char THIS_FILE[] = __FILE__;
/////////////////////////////////////////////////////////////////////////////
// CMainFrame

IMPLEMENT_DYNAMIC(CMainFrame, CMDIFrameWnd)
IMPLEMENT_DYNAMIC(CMainFrame, DpiAware::CDpiAwareWnd<CMDIFrameWnd>)

BEGIN_MESSAGE_MAP(CMainFrame, CMDIFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, DpiAware::CDpiAwareWnd<CMDIFrameWnd>)
//{{AFX_MSG_MAP(CMainFrame)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code !
ON_WM_CREATE()
ON_WM_SIZE()
ON_COMMAND_EX(ID_WINDOW_ARRANGE, OnMDIWindowCmd)
ON_COMMAND_EX(ID_WINDOW_CASCADE, OnMDIWindowCmd)
ON_COMMAND_EX(ID_WINDOW_TILE_HORZ, OnMDIWindowCmd)
ON_COMMAND_EX(ID_WINDOW_TILE_VERT, OnMDIWindowCmd)
ON_COMMAND_EX(ID_WINDOW_SPLIT_VERTICALLY, OnWindowSplit)
ON_COMMAND_EX(ID_WINDOW_SPLIT_HORIZONTALLY, OnWindowSplit)
ON_COMMAND(ID_WINDOW_COMBINE, OnWindowCombine)
ON_MESSAGE(WM_DPICHANGED, OnDpiChanged)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()

Expand All @@ -44,7 +53,7 @@ static UINT indicators[] =
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction

CMainFrame::CMainFrame()
CMainFrame::CMainFrame() : m_layoutManager(this)
{
// TODO: add member initialization code here

Expand All @@ -56,7 +65,7 @@ CMainFrame::~CMainFrame()

int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CMDIFrameWnd::OnCreate(lpCreateStruct) == -1)
if (__super::OnCreate(lpCreateStruct) == -1)
return -1;

if (!m_wndToolBar.Create(this) ||
Expand Down Expand Up @@ -92,16 +101,16 @@ BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs

return CMDIFrameWnd::PreCreateWindow(cs);
return __super::PreCreateWindow(cs);
}

BOOL CMainFrame::LoadToolBar()
{
const int ICON_COUNT = 17;
m_wndToolBar.LoadToolBar(IDR_MAINFRAME);
CToolBarCtrl& toolbarCtrl = m_wndToolBar.GetToolBarCtrl();
const int cx = MulDiv(16, GetSystemMetrics(SM_CXSMICON), 16);
const int cy = MulDiv(15, GetSystemMetrics(SM_CYSMICON), 16);
const int cx = MulDiv(16, m_dpi, USER_DEFAULT_SCREEN_DPI);
const int cy = MulDiv(15, m_dpi, USER_DEFAULT_SCREEN_DPI);
m_imgListToolBar.Detach();
m_imgListToolBar.Create(cx, cy, ILC_COLOR32, ICON_COUNT, 0);
CBitmap bm;
Expand All @@ -119,15 +128,66 @@ BOOL CMainFrame::LoadToolBar()
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CMDIFrameWnd::AssertValid();
__super::AssertValid();
}

void CMainFrame::Dump(CDumpContext& dc) const
{
CMDIFrameWnd::Dump(dc);
__super::Dump(dc);
}

#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers

BOOL CMainFrame::OnMDIWindowCmd(UINT nID)
{
switch (nID)
{
case ID_WINDOW_TILE_HORZ:
case ID_WINDOW_TILE_VERT:
{
bool bHorizontal = (nID == ID_WINDOW_TILE_HORZ);
m_layoutManager.SetTileLayoutEnabled(true);
m_layoutManager.Tile(bHorizontal);
break;
}
case ID_WINDOW_CASCADE:
m_layoutManager.SetTileLayoutEnabled(false);
__super::OnMDIWindowCmd(nID);
break;
}
return 0;
}

BOOL CMainFrame::OnWindowSplit(UINT nID)
{
m_layoutManager.SplitActivePane(nID == ID_WINDOW_SPLIT_HORIZONTALLY, 0.5);
return 0;
}

void CMainFrame::OnWindowCombine()
{
m_layoutManager.CombineActivePane();
}

void CMainFrame::OnSize(UINT nType, int cx, int cy)
{
__super::OnSize(nType, cx, cy);
m_layoutManager.NotifyMainResized();
}

LRESULT CMainFrame::OnDpiChanged(WPARAM wParam, LPARAM lParam)
{
__super::OnDpiChanged(wParam, lParam);
DpiAware::UpdateAfxDataSysMetrics(GetDpi());
LoadToolBar();
const RECT* pRect = reinterpret_cast<RECT *>(lParam);
SetWindowPos(nullptr, pRect->left, pRect->top,
pRect->right - pRect->left,
pRect->bottom - pRect->top, SWP_NOZORDER | SWP_NOACTIVATE);
Default();
return 0;
}

13 changes: 12 additions & 1 deletion Externals/crystaledit/Sample/MainFrm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

#pragma once

class CMainFrame : public CMDIFrameWnd
#include "utils/DpiAware.h"
#include "utils/MDITileLayout.h"

class CMainFrame : public DpiAware::CDpiAwareWnd<CMDIFrameWnd>
{
DECLARE_DYNAMIC(CMainFrame)
public:
Expand All @@ -30,19 +33,27 @@ class CMainFrame : public CMDIFrameWnd
virtual void Dump(CDumpContext& dc) const;
#endif
BOOL LoadToolBar();
MDITileLayout::LayoutManager& GetLayoutManager() { return m_layoutManager; };

protected: // control bar embedded members
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CImageList m_imgListToolBar;
CSplitterWnd m_wndSplitter;
MDITileLayout::LayoutManager m_layoutManager;

// Generated message map functions
protected:
//{{AFX_MSG(CMainFrame)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
// NOTE - the ClassWizard will add and remove member functions here.
// DO NOT EDIT what you see in these blocks of generated code!
afx_msg BOOL OnMDIWindowCmd(UINT nID);
afx_msg BOOL OnWindowSplit(UINT nID);
afx_msg void OnWindowCombine();
afx_msg void OnSize(UINT nType, int cx, int cy);
//}}AFX_MSG
afx_msg LRESULT OnDpiChanged(WPARAM wParam, LPARAM lParam);
DECLARE_MESSAGE_MAP()
};

Expand Down
6 changes: 5 additions & 1 deletion Externals/crystaledit/Sample/Sample.rc
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,12 @@ BEGIN
BEGIN
MENUITEM "&New Window", ID_WINDOW_NEW
MENUITEM "&Cascade", ID_WINDOW_CASCADE
MENUITEM "&Tile", ID_WINDOW_TILE_HORZ
MENUITEM "Tile &Vertically", ID_WINDOW_TILE_VERT
MENUITEM "Tile &Horizontally", ID_WINDOW_TILE_HORZ
MENUITEM "&Arrange Icons", ID_WINDOW_ARRANGE
MENUITEM "Split V&ertically", ID_WINDOW_SPLIT_VERTICALLY
MENUITEM "Split H&orizontally", ID_WINDOW_SPLIT_HORIZONTALLY
MENUITEM "Com&bine", ID_WINDOW_COMBINE
END
POPUP "&Help"
BEGIN
Expand Down
10 changes: 10 additions & 0 deletions Externals/crystaledit/Sample/SampleStatic.manifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0" xmlns:asmv3="urn:schemas-microsoft-com:asm.v3">
<asmv3:application>
<asmv3:windowsSettings>
<dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">True</dpiAware>
<dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2</dpiAwareness>
</asmv3:windowsSettings>
</asmv3:application>
</assembly>

Loading
Loading