📄 atlframe.h
字号:
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;
#ifndef _WIN32_WCE
m_hWndToolBar = T::CreateSimpleToolBarCtrl(m_hWnd, nResourceID, TRUE, dwStyle, nID);
#else // CE specific
m_hWndToolBar = T::CreateSimpleToolBarCtrl(m_hWndCECommandBar, nResourceID, TRUE, dwStyle, nID);
#endif //_WIN32_WCE
return (m_hWndToolBar != NULL);
}
// message map and handlers
typedef CFrameWindowImplBase< TBase, TWinTraits > _baseClass;
BEGIN_MSG_MAP(CFrameWindowImpl)
MESSAGE_HANDLER(WM_SIZE, OnSize)
#ifndef _ATL_NO_REBAR_SUPPORT
#if (_WIN32_IE >= 0x0400)
NOTIFY_CODE_HANDLER(RBN_AUTOSIZE, OnReBarAutoSize)
#endif //(_WIN32_IE >= 0x0400)
#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
NOTIFY_CODE_HANDLER(RBN_CHEVRONPUSHED, OnChevronPushed)
#endif //(_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
#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();
}
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) && !defined(_WIN32_WCE)
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) && !defined(_WIN32_WCE)
#endif //!_ATL_NO_REBAR_SUPPORT
};
///////////////////////////////////////////////////////////////////////////////
// AtlCreateSimpleToolBar - helper for creating simple toolbars
#ifndef _WIN32_WCE
inline HWND AtlCreateSimpleToolBar(HWND hWndParent, UINT nResourceID, BOOL bInitialSeparator = FALSE,
DWORD dwStyle = ATL_SIMPLE_TOOLBAR_STYLE, UINT nID = ATL_IDW_TOOLBAR)
{
return CFrameWindowImplBase<>::CreateSimpleToolBarCtrl(hWndParent, nResourceID, bInitialSeparator, dwStyle, nID);
}
#endif //!_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CMDIWindow
#ifndef _WIN32_WCE
#ifndef _WTL_MDIWINDOWMENU_TEXT
#define _WTL_MDIWINDOWMENU_TEXT _T("&Window")
#endif
class CMDIWindow : public ATL::CWindow
{
public:
// Data members
HWND m_hWndMDIClient;
HMENU m_hMenu;
// Constructors
CMDIWindow(HWND hWnd = NULL) : ATL::CWindow(hWnd), m_hWndMDIClient(NULL), m_hMenu(NULL)
{ }
CMDIWindow& operator =(HWND hWnd)
{
m_hWnd = hWnd;
return *this;
}
// Operations
HWND MDIGetActive(BOOL* lpbMaximized = NULL)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
return (HWND)::SendMessage(m_hWndMDIClient, WM_MDIGETACTIVE, 0, (LPARAM)lpbMaximized);
}
void MDIActivate(HWND hWndChildToActivate)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
ATLASSERT(::IsWindow(hWndChildToActivate));
::SendMessage(m_hWndMDIClient, WM_MDIACTIVATE, (WPARAM)hWndChildToActivate, 0);
}
void MDINext(HWND hWndChild, BOOL bPrevious = FALSE)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
ATLASSERT(hWndChild == NULL || ::IsWindow(hWndChild));
::SendMessage(m_hWndMDIClient, WM_MDINEXT, (WPARAM)hWndChild, (LPARAM)bPrevious);
}
void MDIMaximize(HWND hWndChildToMaximize)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
ATLASSERT(::IsWindow(hWndChildToMaximize));
::SendMessage(m_hWndMDIClient, WM_MDIMAXIMIZE, (WPARAM)hWndChildToMaximize, 0);
}
void MDIRestore(HWND hWndChildToRestore)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
ATLASSERT(::IsWindow(hWndChildToRestore));
::SendMessage(m_hWndMDIClient, WM_MDIRESTORE, (WPARAM)hWndChildToRestore, 0);
}
void MDIDestroy(HWND hWndChildToDestroy)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
ATLASSERT(::IsWindow(hWndChildToDestroy));
::SendMessage(m_hWndMDIClient, WM_MDIDESTROY, (WPARAM)hWndChildToDestroy, 0);
}
BOOL MDICascade(UINT uFlags = 0)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
return (BOOL)::SendMessage(m_hWndMDIClient, WM_MDICASCADE, (WPARAM)uFlags, 0);
}
BOOL MDITile(UINT uFlags = MDITILE_HORIZONTAL)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
return (BOOL)::SendMessage(m_hWndMDIClient, WM_MDITILE, (WPARAM)uFlags, 0);
}
void MDIIconArrange()
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
::SendMessage(m_hWndMDIClient, WM_MDIICONARRANGE, 0, 0);
}
HMENU MDISetMenu(HMENU hMenuFrame, HMENU hMenuWindow)
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
return (HMENU)::SendMessage(m_hWndMDIClient, WM_MDISETMENU, (WPARAM)hMenuFrame, (LPARAM)hMenuWindow);
}
HMENU MDIRefreshMenu()
{
ATLASSERT(::IsWindow(m_hWndMDIClient));
return (HMENU)::SendMessage(m_hWndMDIClient, WM_MDIREFRESHMENU, 0, 0);
}
// Additional operations
static HMENU GetStandardWindowMenu(HMENU hMenu)
{
int nCount = ::GetMenuItemCount(hMenu);
if(nCount == -1)
return NULL;
int nLen = ::GetMenuString(hMenu, nCount - 2, NULL, 0, MF_BYPOSITION);
if(nLen == 0)
return NULL;
LPTSTR lpszText = (LPTSTR)_alloca((nLen + 1) * sizeof(TCHAR));
if(::GetMenuString(hMenu, nCount - 2, lpszText, nLen + 1, MF_BYPOSITION) != nLen)
return NULL;
if(lstrcmp(lpszText, _WTL_MDIWINDOWMENU_TEXT) != 0)
return NULL;
return ::GetSubMenu(hMenu, nCount - 2);
}
void SetMDIFrameMenu()
{
HMENU hWindowMenu = GetStandardWindowMenu(m_hMenu);
MDISetMenu(m_hMenu, hWindowMenu);
MDIRefreshMenu();
::DrawMenuBar(GetMDIFrame());
}
HWND GetMDIFrame() const
{
return ::GetParent(m_hWndMDIClient);
}
};
#endif //!_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CMDIFrameWindowImpl
#ifndef _WIN32_WCE
// MDI child command chaining macro (only for MDI frame windows)
#define CHAIN_MDI_CHILD_COMMANDS() \
if(uMsg == WM_COMMAND) \
{ \
HWND hWndChild = MDIGetActive(); \
if(hWndChild != NULL) \
::SendMessage(hWndChild, uMsg, wParam, lParam); \
}
template <class T, class TBase = CMDIWindow, class TWinTraits = ATL::CFrameWinTraits>
class ATL_NO_VTABLE CMDIFrameWindowImpl : public CFrameWindowImplBase<TBase, TWinTraits >
{
public:
HWND Create(HWND hWndParent = NULL, ATL::_U_RECT rect = NULL, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
HMENU hMenu = NULL, LPVOID lpCreateParam = NULL)
{
m_hMenu = hMenu;
ATOM atom = T::GetWndClassInfo().Register(&m_pfnSuperWindowProc);
dwStyle = T::GetWndStyle(dwStyle);
dwExStyle = T::GetWndExStyle(dwExStyle);
if(rect.m_lpRect == NULL)
rect.m_lpRect = &TBase::rcDefault;
return CFrameWindowImplBase<TBase, TWinTraits >::Create(hWndParent, rect.m_lpRect, szWindowName, dwStyle, dwExStyle, hMenu, atom, lpCreateParam);
}
HWND CreateEx(HWND hWndParent = NULL, ATL::_U_RECT rect = NULL, DWORD dwStyle = 0, DWORD dwExStyle = 0, LPVOID lpCreateParam = NULL)
{
const int cchName = 256;
TCHAR szWindowName[cchName];
szWindowName[0] = 0;
#if (_ATL_VER >= 0x0700)
::LoadString(ATL::_AtlBaseModule.GetResourceInstance(), T::GetWndClassInfo().m_uCommonResourceID, szWindowName, cchName);
HMENU hMenu = ::LoadMenu(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(T::GetWndClassInfo().m_uCommonResourceID));
#else //!(_ATL_VER >= 0x0700)
::LoadString(_Module.GetResourceInstance(), T::GetWndClassInfo().m_uCommonResourceID, szWindowName, cchName);
HMENU hMenu = ::LoadMenu(_Module.GetResourceInstance(), MAKEINTRESOURCE(T::GetWndClassInfo().m_uCommonResourceID));
#endif //!(_ATL_VER >= 0x0700)
T* pT = static_cast<T*>(this);
HWND hWnd = pT->Create(hWndParent, rect, szWindowName, dwStyle, dwExStyle, hMenu, 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);
}
virtual WNDPROC GetWindowProc()
{
return MDIFrameWindowProc;
}
static LRESULT CALLBACK MDIFrameWindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
CMDIFrameWindowImpl< T, TBase, TWinTraits >* pThis = (CMDIFrameWindowImpl< T, TBase, TWinTraits >*)hWnd;
// set a ptr to this message and save the old value
#if (_ATL_VER >= 0x0700)
ATL::_ATL_MSG msg(pThis->m_hWnd, uMsg, wParam, lParam);
const ATL::_ATL_MSG* pOldMsg = pThis->m_pCurrentMsg;
#else //!(_ATL_VER >= 0x0700)
MSG msg = { pThis->m_hWnd, uMsg, wParam, lParam, 0, { 0, 0 } };
const MSG* pOldMsg = pThis->m_pCurrentMsg;
#endif //!(_ATL_VER >= 0x0700)
pThis->m_pCurrentMsg = &msg;
// pass to the message map to process
LRESULT lRes = 0;
BOOL bRet = pThis->ProcessWindowMessage(pThis->m_hWnd, uMsg, wParam, lParam, lRes, 0);
// restore saved value for the current message
ATLASSERT(pThis->m_pCurrentMsg == &msg);
pThis->m_pCurrentMsg = pOldMsg;
// do the default processing if message was not handled
if(!bRet)
{
if(uMsg != WM_NCDESTROY)
lRes = pThis->DefWindowProc(uMsg, wParam, lParam);
else
{
// unsubclass, if needed
LONG_PTR pfnWndProc = ::GetWindowLongPtr(pThis->m_hWnd, GWLP_WNDPROC);
lRes = pThis->DefWindowProc(uMsg, wParam, lParam);
if(pThis->m_pfnSuperWindowProc != ::DefWindowProc && ::GetWindowLongPtr(pThis->m_hWnd, GWLP_WNDPROC) == pfnWndProc)
::SetWindowLongPtr(pThis->m_hWnd, GWLP_WNDPROC, (LONG_PTR)pThis->m_pfnSuperWindowProc);
#if (_ATL_VER >= 0x0700)
// mark window as destryed
pThis->m_dwState |= WINSTATE_DESTROYED;
#else //!(_ATL_VER >= 0x0700)
// clear out window handle
HWND hWnd = pThis->m_hWnd;
pThis->m_hWnd = NULL;
// clean up after window is destroyed
pThis->OnFinalMessage(hWnd);
#endif //!(_ATL_VER >= 0x0700)
}
}
#if (_ATL_VER >= 0x0700)
if(pThis->m_dwState & WINSTATE_DESTROYED && pThis->m_pCurrentMsg == NULL)
{
// clear out window handle
HWND hWnd = pThis->m_hWnd;
pThis->m_hWnd = NULL;
pThis->m_dwState &= ~WINSTATE_DESTROYED;
// clean up after window is destroyed
pThis->OnFinalMessage(hWnd);
}
#endif //(_ATL_VER >= 0x0700)
return lRes;
}
// Overriden to call DefWindowProc which uses DefFrameProc
LRESULT DefWindowProc()
{
const MSG* pMsg = m_pCurrentMsg;
LRESULT lRes = 0;
if (pMsg != NULL)
lRes = DefWindowProc(pMsg->message, pMsg->wParam, pMsg->lParam);
return lRes;
}
LRESULT DefWindowProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{
return ::DefFrameProc(m_hWnd, m_hWndMDIClient, uMsg, wParam, lParam);
}
BOOL PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImplBase<TBase, TWinTraits>::PreTranslateMessage(pMsg))
return TRUE;
return ::TranslateMDISysAccel(m_hWndMDIClient, pMsg);
}
HWND CreateMDIClient(HMENU hWindowMenu = NULL, UINT nID = ATL_IDW_CLIENT, UINT nFirstChildID = ATL_IDM_FIRST_MDICHILD)
{
DWORD dwStyle = WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | MDIS_ALLCHILDSTYLES;
DWORD dwExStyle = WS_EX_CLIENTEDGE;
CLIENTCREATESTRUCT ccs = { 0 };
ccs.hWindowMenu = hWindowMenu;
ccs.idFirstChild = nFirstChildID;
if((GetStyle() & (WS_HSCROLL | WS_VSCROLL)) != 0)
{
// parent MDI frame's scroll styles move to the MDICLIENT
dwStyle |= (GetStyle() & (WS_HSCROLL | WS_VSCROLL));
// fast way to turn off the scrollbar bits (without a resize)
ModifyStyle(WS_HSCROLL | WS_VSCROLL, 0, SWP_NOREDRAW | SWP_FRAMECHANGED);
}
// Create MDICLIENT window
#if (_ATL_VER >= 0x0700)
m_hWndClient = ::CreateWindowEx(dwExStyle, _T("MDIClient"), NULL,
dwStyle, 0, 0, 1, 1, m_hWnd, (HMENU)LongToHandle(nID),
ATL::_AtlBaseModule.GetModuleInstance(), (LPVOID)&ccs);
#else //!(_ATL_VER >= 0x0700)
m_hWndClient = ::CreateWindowEx(dwExStyle, _T("MDIClient"), NULL,
dwStyle, 0, 0, 1, 1, m_hWnd, (HMENU)LongToHandle(nID),
_Module.GetModuleInstance(), (LPVOID)&ccs);
#endif //!(_ATL_VER >= 0x0700)
if (m_hWndClient == NULL)
{
ATLTRACE2(atlTraceUI, 0, _T("MDI Frame failed to create MDICLIENT.\n"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -