📄 atlframe.h
字号:
return NULL;
}
// Move it to the top of z-order
::BringWindowToTop(m_hWndClient);
// set as MDI client window
m_hWndMDIClient = m_hWndClient;
// update to proper size
T* pT = static_cast<T*>(this);
pT->UpdateLayout();
return m_hWndClient;
}
typedef CFrameWindowImplBase<TBase, TWinTraits > _baseClass;
BEGIN_MSG_MAP(CMDIFrameWindowImpl)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_SETFOCUS, OnSetFocus)
MESSAGE_HANDLER(WM_MDISETMENU, OnMDISetMenu)
#ifndef _ATL_NO_REBAR_SUPPORT
#if (_WIN32_IE >= 0x0400)
NOTIFY_CODE_HANDLER(RBN_AUTOSIZE, OnReBarAutoSize)
#endif //(_WIN32_IE >= 0x0400)
#if (_WIN32_IE >= 0x0500)
NOTIFY_CODE_HANDLER(RBN_CHEVRONPUSHED, OnChevronPushed)
#endif //(_WIN32_IE >= 0x0500)
#endif //!_ATL_NO_REBAR_SUPPORT
CHAIN_MSG_MAP(_baseClass)
END_MSG_MAP()
LRESULT OnSize(UINT /*uMsg*/, WPARAM wParam, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
if(wParam != SIZE_MINIMIZED)
{
T* pT = static_cast<T*>(this);
pT->UpdateLayout();
}
// message must be handled, otherwise DefFrameProc would resize the client again
return 0;
}
LRESULT OnSetFocus(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
// don't allow CFrameWindowImplBase to handle this one
return DefWindowProc(uMsg, wParam, lParam);
}
LRESULT OnMDISetMenu(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
SetMDIFrameMenu();
return 0;
}
#ifndef _ATL_NO_REBAR_SUPPORT
#if (_WIN32_IE >= 0x0400)
LRESULT OnReBarAutoSize(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
pT->UpdateLayout(FALSE);
return 0;
}
#endif //(_WIN32_IE >= 0x0400)
#if (_WIN32_IE >= 0x0500)
LRESULT OnChevronPushed(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
_ChevronMenuInfo cmi = { NULL, (LPNMREBARCHEVRON)pnmh, false };
if(!pT->PrepareChevronMenu(cmi))
{
bHandled = FALSE;
return 1;
}
// display a popup menu with hidden items
pT->DisplayChevronMenu(cmi);
// cleanup
pT->CleanupChevronMenu(cmi);
return 0;
}
#endif //(_WIN32_IE >= 0x0500)
#endif //!_ATL_NO_REBAR_SUPPORT
};
#endif //!_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CMDIChildWindowImpl
#ifndef _WIN32_WCE
template <class T, class TBase = CMDIWindow, class TWinTraits = ATL::CMDIChildWinTraits>
class ATL_NO_VTABLE CMDIChildWindowImpl : public CFrameWindowImplBase<TBase, TWinTraits >
{
public:
HWND Create(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
UINT nMenuID = 0, LPVOID lpCreateParam = NULL)
{
ATOM atom = T::GetWndClassInfo().Register(&m_pfnSuperWindowProc);
if(nMenuID != 0)
#if (_ATL_VER >= 0x0700)
m_hMenu = ::LoadMenu(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(nMenuID));
#else //!(_ATL_VER >= 0x0700)
m_hMenu = ::LoadMenu(_Module.GetResourceInstance(), MAKEINTRESOURCE(nMenuID));
#endif //!(_ATL_VER >= 0x0700)
dwStyle = T::GetWndStyle(dwStyle);
dwExStyle = T::GetWndExStyle(dwExStyle);
dwExStyle |= WS_EX_MDICHILD; // force this one
m_pfnSuperWindowProc = ::DefMDIChildProc;
m_hWndMDIClient = hWndParent;
ATLASSERT(::IsWindow(m_hWndMDIClient));
if(rect.m_lpRect == NULL)
rect.m_lpRect = &TBase::rcDefault;
// If the currently active MDI child is maximized, we want to create this one maximized too
ATL::CWindow wndParent = hWndParent;
BOOL bMaximized = FALSE;
wndParent.SendMessage(WM_MDIGETACTIVE, 0, (LPARAM)&bMaximized);
if(bMaximized)
wndParent.SetRedraw(FALSE);
HWND hWnd = CFrameWindowImplBase<TBase, TWinTraits >::Create(hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, (UINT)0U, atom, lpCreateParam);
if(bMaximized)
{
// Maximize and redraw everything
if(hWnd != NULL)
MDIMaximize(hWnd);
wndParent.SetRedraw(TRUE);
wndParent.RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
::SetFocus(GetMDIFrame()); // focus will be set back to this window
}
else if(hWnd != NULL && ::IsWindowVisible(m_hWnd) && !::IsChild(hWnd, ::GetFocus()))
{
::SetFocus(hWnd);
}
return hWnd;
}
HWND CreateEx(HWND hWndParent, ATL::_U_RECT rect = NULL, LPCTSTR lpcstrWindowName = NULL, DWORD dwStyle = 0, DWORD dwExStyle = 0, LPVOID lpCreateParam = NULL)
{
const int cchName = 256;
TCHAR szWindowName[cchName];
szWindowName[0] = 0;
if(lpcstrWindowName == NULL)
{
#if (_ATL_VER >= 0x0700)
::LoadString(ATL::_AtlBaseModule.GetResourceInstance(), T::GetWndClassInfo().m_uCommonResourceID, szWindowName, cchName);
#else //!(_ATL_VER >= 0x0700)
::LoadString(_Module.GetResourceInstance(), T::GetWndClassInfo().m_uCommonResourceID, szWindowName, cchName);
#endif //!(_ATL_VER >= 0x0700)
lpcstrWindowName = szWindowName;
}
T* pT = static_cast<T*>(this);
HWND hWnd = pT->Create(hWndParent, rect, lpcstrWindowName, dwStyle, dwExStyle, T::GetWndClassInfo().m_uCommonResourceID, lpCreateParam);
if(hWnd != NULL)
#if (_ATL_VER >= 0x0700)
m_hAccel = ::LoadAccelerators(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(T::GetWndClassInfo().m_uCommonResourceID));
#else //!(_ATL_VER >= 0x0700)
m_hAccel = ::LoadAccelerators(_Module.GetResourceInstance(), MAKEINTRESOURCE(T::GetWndClassInfo().m_uCommonResourceID));
#endif //!(_ATL_VER >= 0x0700)
return hWnd;
}
BOOL CreateSimpleToolBar(UINT nResourceID = 0, DWORD dwStyle = ATL_SIMPLE_TOOLBAR_STYLE, UINT nID = ATL_IDW_TOOLBAR)
{
ATLASSERT(!::IsWindow(m_hWndToolBar));
if(nResourceID == 0)
nResourceID = T::GetWndClassInfo().m_uCommonResourceID;
m_hWndToolBar = T::CreateSimpleToolBarCtrl(m_hWnd, nResourceID, TRUE, dwStyle, nID);
return (m_hWndToolBar != NULL);
}
BOOL UpdateClientEdge(LPRECT lpRect = NULL)
{
// only adjust for active MDI child window
HWND hWndChild = MDIGetActive();
if(hWndChild != NULL && hWndChild != m_hWnd)
return FALSE;
// need to adjust the client edge style as max/restore happens
DWORD dwStyle = ::GetWindowLong(m_hWndMDIClient, GWL_EXSTYLE);
DWORD dwNewStyle = dwStyle;
if(hWndChild != NULL && ((GetExStyle() & WS_EX_CLIENTEDGE) == 0) && ((GetStyle() & WS_MAXIMIZE) != 0))
dwNewStyle &= ~(WS_EX_CLIENTEDGE);
else
dwNewStyle |= WS_EX_CLIENTEDGE;
if(dwStyle != dwNewStyle)
{
// SetWindowPos will not move invalid bits
::RedrawWindow(m_hWndMDIClient, NULL, NULL,
RDW_INVALIDATE | RDW_ALLCHILDREN);
// remove/add WS_EX_CLIENTEDGE to MDI client area
::SetWindowLong(m_hWndMDIClient, GWL_EXSTYLE, dwNewStyle);
::SetWindowPos(m_hWndMDIClient, NULL, 0, 0, 0, 0,
SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE |
SWP_NOZORDER | SWP_NOCOPYBITS);
// return new client area
if (lpRect != NULL)
::GetClientRect(m_hWndMDIClient, lpRect);
return TRUE;
}
return FALSE;
}
typedef CFrameWindowImplBase<TBase, TWinTraits > _baseClass;
BEGIN_MSG_MAP(CMDIChildWindowImpl)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_WINDOWPOSCHANGED, OnWindowPosChanged)
MESSAGE_HANDLER(WM_MOUSEACTIVATE, OnMouseActivate)
MESSAGE_HANDLER(WM_MENUSELECT, OnMenuSelect)
MESSAGE_HANDLER(WM_MDIACTIVATE, OnMDIActivate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
#ifndef _ATL_NO_REBAR_SUPPORT
#if (_WIN32_IE >= 0x0400)
NOTIFY_CODE_HANDLER(RBN_AUTOSIZE, OnReBarAutoSize)
#endif //(_WIN32_IE >= 0x0400)
#if (_WIN32_IE >= 0x0500)
NOTIFY_CODE_HANDLER(RBN_CHEVRONPUSHED, OnChevronPushed)
#endif //(_WIN32_IE >= 0x0500)
#endif //!_ATL_NO_REBAR_SUPPORT
CHAIN_MSG_MAP(_baseClass)
END_MSG_MAP()
LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
DefWindowProc(uMsg, wParam, lParam); // needed for MDI children
if(wParam != SIZE_MINIMIZED)
{
T* pT = static_cast<T*>(this);
pT->UpdateLayout();
}
return 0;
}
LRESULT OnWindowPosChanged(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
// update MDI client edge and adjust MDI child rect
LPWINDOWPOS lpWndPos = (LPWINDOWPOS)lParam;
if(!(lpWndPos->flags & SWP_NOSIZE))
{
RECT rectClient;
if(UpdateClientEdge(&rectClient) && ((GetStyle() & WS_MAXIMIZE) != 0))
{
::AdjustWindowRectEx(&rectClient, GetStyle(), FALSE, GetExStyle());
lpWndPos->x = rectClient.left;
lpWndPos->y = rectClient.top;
lpWndPos->cx = rectClient.right - rectClient.left;
lpWndPos->cy = rectClient.bottom - rectClient.top;
}
}
bHandled = FALSE;
return 1;
}
LRESULT OnMouseActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
LRESULT lRes = DefWindowProc(uMsg, wParam, lParam);
// Activate this MDI window if needed
if(lRes == MA_ACTIVATE || lRes == MA_ACTIVATEANDEAT)
{
if(MDIGetActive() != m_hWnd)
MDIActivate(m_hWnd);
}
return lRes;
}
LRESULT OnMenuSelect(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/)
{
return ::SendMessage(GetMDIFrame(), uMsg, wParam, lParam);
}
LRESULT OnMDIActivate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
if((HWND)lParam == m_hWnd && m_hMenu != NULL)
SetMDIFrameMenu();
else if((HWND)lParam == NULL)
::SendMessage(GetMDIFrame(), WM_MDISETMENU, 0, 0);
bHandled = FALSE;
return 1;
}
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
UpdateClientEdge();
bHandled = FALSE;
return 1;
}
#ifndef _ATL_NO_REBAR_SUPPORT
#if (_WIN32_IE >= 0x0400)
LRESULT OnReBarAutoSize(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)
{
T* pT = static_cast<T*>(this);
pT->UpdateLayout(FALSE);
return 0;
}
#endif //(_WIN32_IE >= 0x0400)
#if (_WIN32_IE >= 0x0500)
LRESULT OnChevronPushed(int /*idCtrl*/, LPNMHDR pnmh, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
_ChevronMenuInfo cmi = { NULL, (LPNMREBARCHEVRON)pnmh, false };
if(!pT->PrepareChevronMenu(cmi))
{
bHandled = FALSE;
return 1;
}
// display a popup menu with hidden items
pT->DisplayChevronMenu(cmi);
// cleanup
pT->CleanupChevronMenu(cmi);
return 0;
}
#endif //(_WIN32_IE >= 0x0500)
#endif //!_ATL_NO_REBAR_SUPPORT
};
#endif //!_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// COwnerDraw - MI class for owner-draw support
template <class T>
class COwnerDraw
{
public:
#if (_ATL_VER < 0x0700)
BOOL m_bHandledOD;
BOOL IsMsgHandled() const
{
return m_bHandledOD;
}
void SetMsgHandled(BOOL bHandled)
{
m_bHandledOD = bHandled;
}
#endif //(_ATL_VER < 0x0700)
// Message map and handlers
BEGIN_MSG_MAP(COwnerDraw< T >)
MESSAGE_HANDLER(WM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(WM_MEASUREITEM, OnMeasureItem)
MESSAGE_HANDLER(WM_COMPAREITEM, OnCompareItem)
MESSAGE_HANDLER(WM_DELETEITEM, OnDeleteItem)
ALT_MSG_MAP(1)
MESSAGE_HANDLER(OCM_DRAWITEM, OnDrawItem)
MESSAGE_HANDLER(OCM_MEASUREITEM, OnMeasureItem)
MESSAGE_HANDLER(OCM_COMPAREITEM, OnCompareItem)
MESSAGE_HANDLER(OCM_DELETEITEM, OnDeleteItem)
END_MSG_MAP()
LRESULT OnDrawItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
pT->SetMsgHandled(TRUE);
pT->DrawItem((LPDRAWITEMSTRUCT)lParam);
bHandled = pT->IsMsgHandled();
return (LRESULT)TRUE;
}
LRESULT OnMeasureItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
pT->SetMsgHandled(TRUE);
pT->MeasureItem((LPMEASUREITEMSTRUCT)lParam);
bHandled = pT->IsMsgHandled();
return (LRESULT)TRUE;
}
LRESULT OnCompareItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
pT->SetMsgHandled(TRUE);
bHandled = pT->IsMsgHandled();
return (LRESULT)pT->CompareItem((LPCOMPAREITEMSTRUCT)lParam);
}
LRESULT OnDeleteItem(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& bHandled)
{
T* pT = static_cast<T*>(this);
pT->SetMsgHandled(TRUE);
pT->DeleteItem((LPDELET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -