Skip to content

Commit 8b901bd

Browse files
qdtroyasfdghf
authored andcommitted
支持Win11的SnapLayout贴边布局特性
1 parent 45e6c72 commit 8b901bd

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

DuiLib/Core/UIManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,6 +1966,11 @@ namespace DuiLib {
19661966
::InvalidateRect(m_hWndPaint, &rcItem, FALSE);
19671967
}
19681968

1969+
bool CPaintManagerUI::IsValid()
1970+
{
1971+
return m_hWndPaint != NULL && m_pRoot != NULL;
1972+
}
1973+
19691974
bool CPaintManagerUI::AttachDialog(CControlUI* pControl)
19701975
{
19711976
ASSERT(::IsWindow(m_hWndPaint));

DuiLib/Core/UIManager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ namespace DuiLib {
373373
void SetDragDrop(IDragDropUI* pDragDrop);
374374
virtual bool OnDrop(FORMATETC* pFmtEtc, STGMEDIUM& medium,DWORD *pdwEffect);
375375

376+
bool IsValid();
376377
bool AttachDialog(CControlUI* pControl);
377378
bool InitControls(CControlUI* pControl, CControlUI* pParent = NULL);
378379
void ReapObjects(CControlUI* pControl);

DuiLib/Utils/WinImplBase.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ namespace DuiLib
143143

144144
RECT rcClient;
145145
::GetClientRect(*this, &rcClient);
146+
147+
CControlUI* pMaxBtn = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
148+
CControlUI* pRestoreBtn = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
149+
if (pMaxBtn && pMaxBtn->IsVisible()) {
150+
RECT rcBtn = pMaxBtn->GetPos();
151+
if (::PtInRect(&rcBtn, pt)) {
152+
return HTMAXBUTTON;
153+
}
154+
}
155+
else if (pRestoreBtn && pRestoreBtn->IsVisible()) {
156+
RECT rcBtn = pRestoreBtn->GetPos();
157+
if (::PtInRect(&rcBtn, pt)) {
158+
return HTMAXBUTTON;
159+
}
160+
}
146161

147162
if (!::IsZoomed(*this))
148163
{
@@ -232,6 +247,13 @@ namespace DuiLib
232247
HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
233248
::SetWindowRgn(*this, hRgn, TRUE);
234249
::DeleteObject(hRgn);
250+
251+
if (m_pm.IsValid() && wParam == SIZE_RESTORED) {
252+
CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
253+
if (pControl) pControl->SetVisible(true);
254+
pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
255+
if (pControl) pControl->SetVisible(false);
256+
}
235257
}
236258
#endif
237259
bHandled = FALSE;
@@ -364,6 +386,45 @@ namespace DuiLib
364386
case WM_NCCALCSIZE: lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled); break;
365387
case WM_NCPAINT: lRes = OnNcPaint(uMsg, wParam, lParam, bHandled); break;
366388
case WM_NCHITTEST: lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled); break;
389+
case WM_NCLBUTTONDOWN:
390+
case WM_NCLBUTTONUP:
391+
case WM_NCLBUTTONDBLCLK: {
392+
if (wParam == HTMAXBUTTON) {
393+
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
394+
::ScreenToClient(m_hWnd, &pt);
395+
LPARAM param = MAKELPARAM(pt.x, pt.y);
396+
if (uMsg == WM_NCLBUTTONDOWN) {
397+
::SendMessage(m_hWnd, WM_LBUTTONDOWN, wParam, param);
398+
}
399+
else if (uMsg == WM_NCLBUTTONUP) {
400+
::SendMessage(m_hWnd, WM_LBUTTONUP, wParam, param);
401+
}
402+
return 0;
403+
}
404+
bHandled = FALSE;
405+
break;
406+
}
407+
case WM_NCMOUSEHOVER:
408+
case WM_NCMOUSELEAVE:
409+
case WM_NCMOUSEMOVE: {
410+
if (wParam == HTMAXBUTTON) {
411+
POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
412+
::ScreenToClient(m_hWnd, &pt);
413+
LPARAM param = MAKELPARAM(pt.x, pt.y);
414+
if (uMsg == WM_NCMOUSEHOVER) {
415+
//::SendMessage(m_hWnd, WM_MOUSEHOVER, wParam, param);
416+
}
417+
else if (uMsg == WM_NCMOUSELEAVE) {
418+
//::SendMessage(m_hWnd, WM_MOUSELEAVE, wParam, param);
419+
}
420+
else {
421+
::SendMessage(m_hWnd, WM_MOUSEMOVE, wParam, param);
422+
}
423+
return 0;
424+
}
425+
bHandled = FALSE;
426+
break;
427+
}
367428
case WM_GETMINMAXINFO: lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled); break;
368429
case WM_MOUSEWHEEL: lRes = OnMouseWheel(uMsg, wParam, lParam, bHandled); break;
369430
#endif

0 commit comments

Comments
 (0)