📄 atlframe.h
字号:
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
};
/////////////////////////////////////////////////////////////////////////////
// CMDIChildWindowImpl
template <class T, class TBase = CMDIWindow, class TWinTraits = CMDIChildWinTraits>
class ATL_NO_VTABLE CMDIChildWindowImpl : public CFrameWindowImplBase<TBase, TWinTraits >
{
public:
HWND Create(HWND hWndParent, _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)
m_hMenu = ::LoadMenu(_Module.GetResourceInstance(), MAKEINTRESOURCE(nMenuID));
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;
HWND hWnd = CFrameWindowImplBase<TBase, TWinTraits >::Create(hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, (UINT)0U, atom, lpCreateParam);
if(hWnd != NULL && ::IsWindowVisible(m_hWnd) && !::IsChild(hWnd, ::GetFocus()))
::SetFocus(hWnd);
return hWnd;
}
HWND CreateEx(HWND hWndParent, _U_RECT rect = NULL, LPCTSTR lpcstrWindowName = NULL, DWORD dwStyle = 0, DWORD dwExStyle = 0, LPVOID lpCreateParam = NULL)
{
TCHAR szWindowName[256];
szWindowName[0] = 0;
if(lpcstrWindowName == NULL)
{
::LoadString(_Module.GetResourceInstance(), T::GetWndClassInfo().m_uCommonResourceID, szWindowName, 256);
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)
m_hAccel = ::LoadAccelerators(_Module.GetResourceInstance(), MAKEINTRESOURCE(T::GetWndClassInfo().m_uCommonResourceID));
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 CMDIChildWindowImpl< T, TBase, TWinTraits > thisClass;
typedef CFrameWindowImplBase<TBase, TWinTraits > baseClass;
BEGIN_MSG_MAP(thisClass)
MESSAGE_HANDLER(WM_SIZE, OnSize)
MESSAGE_HANDLER(WM_WINDOWPOSCHANGED, OnWindowPosChanged)
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))
{
CWindow wnd(m_hWndMDIClient);
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 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
};
/////////////////////////////////////////////////////////////////////////////
// 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((LPDELETEITEMSTRUCT)lParam);
bHandled = pT->IsMsgHandled();
return (LRESULT)TRUE;
}
// Overrideables
void DrawItem(LPDRAWITEMSTRUCT /*lpDrawItemStruct*/)
{
// must be implemented
ATLASSERT(FALSE);
}
void MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if(lpMeasureItemStruct->CtlType != ODT_MENU)
{
// return default height for a system font
T* pT = static_cast<T*>(this);
HWND hWnd = pT->GetDlgItem(lpMeasureItemStruct->CtlID);
CClientDC dc(hWnd);
TEXTMETRIC tm;
dc.GetTextMetrics(&tm);
lpMeasureItemStruct->itemHeight = tm.tmHeight;
}
else
lpMeasureItemStruct->itemHeight = ::GetSystemMetrics(SM_CYMENU);
}
int CompareItem(LPCOMPAREITEMSTRUCT /*lpCompareItemStruct*/)
{
// all items are equal
return 0;
}
void DeleteItem(LPDELETEITEMSTRUCT /*lpDeleteItemStruct*/)
{
// default - nothing
}
};
/////////////////////////////////////////////////////////////////////////////
// Update UI macros
// these build the Update UI map inside a class definition
#define BEGIN_UPDATE_UI_MAP(thisClass) \
static const _AtlUpdateUIMap* GetUpdateUIMap() \
{ \
static const _AtlUpdateUIMap theMap[] = \
{
#define UPDATE_ELEMENT(nID, wType) \
{ nID, wType },
#define END_UPDATE_UI_MAP() \
{ (WORD)-1, 0 } \
}; \
return theMap; \
}
///////////////////////////////////////////////////////////////////////////////
// CUpdateUI - manages UI elements updating
class CUpdateUIBase
{
public:
// constants
enum
{
// UI element type
UPDUI_MENUPOPUP = 0x0001,
UPDUI_MENUBAR = 0x0002,
UPDUI_CHILDWINDOW = 0x0004,
UPDUI_TOOLBAR = 0x0008,
UPDUI_STATUSBAR = 0x0010,
// state
UPDUI_ENABLED = 0x0000,
UPDUI_DISABLED = 0x0100,
UPDUI_CHECKED = 0x0200,
UPDUI_CHECKED2 = 0x0400,
UPDUI_RADIO = 0x0800,
UPDUI_DEFAULT = 0x1000,
UPDUI_TEXT = 0x2000,
};
// element data
struct _AtlUpdateUIElement
{
HWND m_hWnd;
WORD m_wType;
bool operator==(const _AtlUpdateUIElement& e) const
{ return (m_hWnd == e.m_hWnd && m_wType == e.m_wType); }
};
// map data
struct _AtlUpdateUIMap
{
WORD m_nID;
WORD m_wType;
};
// instance data
struct _AtlUpdateUIData
{
WORD m_wState;
void* m_lpData;
};
CSimpleArray<_AtlUpdateUIElement> m_UIElements; // elements data
const _AtlUpdateUIMap* m_pUIMap; // static UI data
_AtlUpdateUIData* m_pUIData; // instance UI data
WORD m_wDirtyType; // global dirty flag
bool m_bBlockAccelerators;
// Constructor, destructor
CUpdateUIBase() : m_pUIMap(NULL), m_pUIData(NULL), m_wDirtyType(0), m_bBlockAccelerators(false)
{ }
~CUpdateUIBase()
{
if(m_pUIMap != NULL && m_pUIData != NULL)
{
const _AtlUpdateUIMap* pUIMap = m_pUIMap;
_AtlUpdateUIData* pUIData = m_pUIData;
while(pUIMap->m_nID != (WORD)-1)
{
if(pUIData->m_wState & UPDUI_TEXT)
free(pUIData->m_lpData);
pUIMap++;
pUIData++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -