📄 atlframe.h
字号:
// Windows Template Library - WTL version 7.1
// Copyright (C) 1997-2003 Microsoft Corporation
// All rights reserved.
//
// This file is a part of the Windows Template Library.
// The code and information is provided "as-is" without
// warranty of any kind, either expressed or implied.
#ifndef __ATLFRAME_H__
#define __ATLFRAME_H__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error atlframe.h requires atlapp.h to be included first
#endif
#ifndef __ATLWIN_H__
#error atlframe.h requires atlwin.h to be included first
#endif
///////////////////////////////////////////////////////////////////////////////
// Classes in this file:
//
// CFrameWindowImpl<T, TBase, TWinTraits>
// CMDIWindow
// CMDIFrameWindowImpl<T, TBase, TWinTraits>
// CMDIChildWindowImpl<T, TBase, TWinTraits>
// COwnerDraw<T>
// CUpdateUIBase
// CUpdateUI<T>
// CDialogResize<T>
//
// Global functions:
// AtlCreateSimpleToolBar()
namespace WTL
{
///////////////////////////////////////////////////////////////////////////////
// CFrameWndClassInfo - Manages frame window Windows class information
class CFrameWndClassInfo
{
public:
#ifndef _WIN32_WCE
enum { cchAutoName = 5 + sizeof(void*) * 2 }; // sizeof(void*) * 2 is the number of digits %p outputs
WNDCLASSEX m_wc;
#else // CE specific
enum { cchAutoName = MAX_PATH }; // MAX_PATH because this can be set in the wizard generated CMainFrame::ActivatePreviousInstance to a user defined string.
WNDCLASS m_wc;
#endif //!_WIN32_WCE
LPCTSTR m_lpszOrigName;
WNDPROC pWndProc;
LPCTSTR m_lpszCursorID;
BOOL m_bSystemCursor;
ATOM m_atom;
TCHAR m_szAutoName[cchAutoName];
UINT m_uCommonResourceID;
#ifndef _WIN32_WCE
ATOM Register(WNDPROC* pProc)
{
if (m_atom == 0)
{
CWindowCreateCriticalSectionLock lock;
if(FAILED(lock.Lock()))
{
ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CFrameWndClassInfo::Register.\n"));
ATLASSERT(FALSE);
return 0;
}
if(m_atom == 0)
{
#if (_ATL_VER >= 0x0700)
HINSTANCE hInst = ATL::_AtlBaseModule.GetModuleInstance();
#else //!(_ATL_VER >= 0x0700)
HINSTANCE hInst = _Module.GetModuleInstance();
#endif //!(_ATL_VER >= 0x0700)
if (m_lpszOrigName != NULL)
{
ATLASSERT(pProc != NULL);
LPCTSTR lpsz = m_wc.lpszClassName;
WNDPROC proc = m_wc.lpfnWndProc;
WNDCLASSEX wc = { 0 };
wc.cbSize = sizeof(WNDCLASSEX);
// try process local class first
#if (_ATL_VER >= 0x0700)
if(!::GetClassInfoEx(ATL::_AtlBaseModule.GetModuleInstance(), m_lpszOrigName, &wc))
#else //!(_ATL_VER >= 0x0700)
if(!::GetClassInfoEx(_Module.GetModuleInstance(), m_lpszOrigName, &wc))
#endif //!(_ATL_VER >= 0x0700)
{
// try global class
if(!::GetClassInfoEx(NULL, m_lpszOrigName, &wc))
{
lock.Unlock();
return 0;
}
}
memcpy(&m_wc, &wc, sizeof(WNDCLASSEX));
pWndProc = m_wc.lpfnWndProc;
m_wc.lpszClassName = lpsz;
m_wc.lpfnWndProc = proc;
}
else
{
m_wc.hCursor = ::LoadCursor(m_bSystemCursor ? NULL : hInst, m_lpszCursorID);
}
m_wc.hInstance = hInst;
m_wc.style &= ~CS_GLOBALCLASS; // we don't register global classes
if (m_wc.lpszClassName == NULL)
{
#if (_WIN32_WINNT >= 0x0500) || defined(_WIN64)
wsprintf(m_szAutoName, _T("ATL:%p"), &m_wc);
#else
wsprintf(m_szAutoName, _T("ATL:%8.8X"), (DWORD_PTR)&m_wc);
#endif
m_wc.lpszClassName = m_szAutoName;
}
WNDCLASSEX wcTemp = { 0 };
memcpy(&wcTemp, &m_wc, sizeof(WNDCLASSEX));
m_atom = (ATOM)::GetClassInfoEx(m_wc.hInstance, m_wc.lpszClassName, &wcTemp);
if (m_atom == 0)
{
if(m_uCommonResourceID != 0) // use it if not zero
{
#if (_ATL_VER >= 0x0700)
m_wc.hIcon = (HICON)::LoadImage(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(m_uCommonResourceID), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
m_wc.hIconSm = (HICON)::LoadImage(ATL::_AtlBaseModule.GetResourceInstance(), MAKEINTRESOURCE(m_uCommonResourceID), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
#else //!(_ATL_VER >= 0x0700)
m_wc.hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(m_uCommonResourceID), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
m_wc.hIconSm = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(m_uCommonResourceID), IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
#endif //!(_ATL_VER >= 0x0700)
}
m_atom = ::RegisterClassEx(&m_wc);
}
}
lock.Unlock();
}
if (m_lpszOrigName != NULL)
{
ATLASSERT(pProc != NULL);
ATLASSERT(pWndProc != NULL);
*pProc = pWndProc;
}
return m_atom;
}
#else // CE specific
ATOM Register(WNDPROC* pProc)
{
if (m_atom == 0)
{
CWindowCreateCriticalSectionLock lock;
if(FAILED(lock.Lock()))
{
ATLTRACE2(atlTraceUI, 0, _T("ERROR : Unable to lock critical section in CFrameWndClassInfo::Register.\n"));
ATLASSERT(FALSE);
return 0;
}
if(m_atom == 0)
{
HINSTANCE hInst = _Module.GetModuleInstance();
if (m_lpszOrigName != NULL)
{
ATLASSERT(pProc != NULL);
LPCTSTR lpsz = m_wc.lpszClassName;
WNDPROC proc = m_wc.lpfnWndProc;
WNDCLASS wc = { 0 };
// try process local class first
if(!::GetClassInfo(_Module.GetModuleInstance(), m_lpszOrigName, &wc))
{
// try global class
if(!::GetClassInfo(NULL, m_lpszOrigName, &wc))
{
lock.Unlock();
return 0;
}
}
memcpy(&m_wc, &wc, sizeof(WNDCLASS));
pWndProc = m_wc.lpfnWndProc;
m_wc.lpszClassName = lpsz;
m_wc.lpfnWndProc = proc;
}
else
{
#if defined(GWES_CURSOR) || defined(GWES_MCURSOR)
m_wc.hCursor = ::LoadCursor(m_bSystemCursor ? NULL : hInst, m_lpszCursorID);
#else //!(defined(GWES_CURSOR) || defined(GWES_MCURSOR))
m_wc.hCursor = NULL;
#endif //!(defined(GWES_CURSOR) || defined(GWES_MCURSOR))
}
m_wc.hInstance = hInst;
m_wc.style &= ~CS_GLOBALCLASS; // we don't register global classes
if (m_wc.lpszClassName == NULL)
{
wsprintf(m_szAutoName, _T("ATL:%8.8X"), (DWORD_PTR)&m_wc);
m_wc.lpszClassName = m_szAutoName;
}
WNDCLASS wcTemp = { 0 };
memcpy(&wcTemp, &m_wc, sizeof(WNDCLASS));
m_atom = (ATOM)::GetClassInfo(m_wc.hInstance, m_wc.lpszClassName, &wcTemp);
if (m_atom == 0)
{
if(m_uCommonResourceID != 0) // use it if not zero
m_wc.hIcon = (HICON)::LoadImage(_Module.GetResourceInstance(), MAKEINTRESOURCE(m_uCommonResourceID), IMAGE_ICON, 32, 32, LR_DEFAULTCOLOR);
m_atom = ::RegisterClass(&m_wc);
}
}
lock.Unlock();
}
if (m_lpszOrigName != NULL)
{
ATLASSERT(pProc != NULL);
ATLASSERT(pWndProc != NULL);
*pProc = pWndProc;
}
return m_atom;
}
#endif //_WIN32_WCE
};
///////////////////////////////////////////////////////////////////////////////
// Macros for declaring frame window WNDCLASS
#ifndef _WIN32_WCE
#define DECLARE_FRAME_WND_CLASS(WndClassName, uCommonResourceID) \
static WTL::CFrameWndClassInfo& GetWndClassInfo() \
{ \
static WTL::CFrameWndClassInfo wc = \
{ \
{ sizeof(WNDCLASSEX), 0, StartWindowProc, \
0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, WndClassName, NULL }, \
NULL, NULL, IDC_ARROW, TRUE, 0, _T(""), uCommonResourceID \
}; \
return wc; \
}
#define DECLARE_FRAME_WND_CLASS_EX(WndClassName, uCommonResourceID, style, bkgnd) \
static WTL::CFrameWndClassInfo& GetWndClassInfo() \
{ \
static WTL::CFrameWndClassInfo wc = \
{ \
{ sizeof(WNDCLASSEX), style, StartWindowProc, \
0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName, NULL }, \
NULL, NULL, IDC_ARROW, TRUE, 0, _T(""), uCommonResourceID \
}; \
return wc; \
}
#define DECLARE_FRAME_WND_SUPERCLASS(WndClassName, OrigWndClassName, uCommonResourceID) \
static WTL::CFrameWndClassInfo& GetWndClassInfo() \
{ \
static WTL::CFrameWndClassInfo wc = \
{ \
{ sizeof(WNDCLASSEX), 0, StartWindowProc, \
0, 0, NULL, NULL, NULL, NULL, NULL, WndClassName, NULL }, \
OrigWndClassName, NULL, NULL, TRUE, 0, _T(""), uCommonResourceID \
}; \
return wc; \
}
#else // CE specific
#define DECLARE_FRAME_WND_CLASS(WndClassName, uCommonResourceID) \
static CFrameWndClassInfo& GetWndClassInfo() \
{ \
static CFrameWndClassInfo wc = \
{ \
{ 0, StartWindowProc, \
0, 0, NULL, NULL, NULL, (HBRUSH)(COLOR_WINDOW + 1), NULL, WndClassName }, \
NULL, NULL, IDC_ARROW, TRUE, 0, _T(""), uCommonResourceID \
}; \
return wc; \
}
#define DECLARE_FRAME_WND_CLASS_EX(WndClassName, uCommonResourceID, style, bkgnd) \
static CFrameWndClassInfo& GetWndClassInfo() \
{ \
static CFrameWndClassInfo wc = \
{ \
{ style, StartWindowProc, \
0, 0, NULL, NULL, NULL, (HBRUSH)(bkgnd + 1), NULL, WndClassName }, \
NULL, NULL, IDC_ARROW, TRUE, 0, _T(""), uCommonResourceID \
}; \
return wc; \
}
#define DECLARE_FRAME_WND_SUPERCLASS(WndClassName, OrigWndClassName, uCommonResourceID) \
static CFrameWndClassInfo& GetWndClassInfo() \
{ \
static CFrameWndClassInfo wc = \
{ \
{ NULL, StartWindowProc, \
0, 0, NULL, NULL, NULL, NULL, NULL, WndClassName }, \
OrigWndClassName, NULL, IDC_ARROW, TRUE, 0, _T(""), uCommonResourceID \
}; \
return wc; \
}
#endif //!_WIN32_WCE
///////////////////////////////////////////////////////////////////////////////
// CFrameWindowImpl
// Client window command chaining macro (only for frame windows)
#define CHAIN_CLIENT_COMMANDS() \
if(uMsg == WM_COMMAND && m_hWndClient != NULL) \
::SendMessage(m_hWndClient, uMsg, wParam, lParam);
// standard toolbar styles
#define ATL_SIMPLE_TOOLBAR_STYLE \
(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | TBSTYLE_TOOLTIPS)
// toolbar in a rebar pane
#define ATL_SIMPLE_TOOLBAR_PANE_STYLE \
(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CCS_NODIVIDER | CCS_NORESIZE | CCS_NOPARENTALIGN | TBSTYLE_TOOLTIPS | TBSTYLE_FLAT)
// standard rebar styles
#if (_WIN32_IE >= 0x0400)
#define ATL_SIMPLE_REBAR_STYLE \
(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS | RBS_AUTOSIZE)
#else
#define ATL_SIMPLE_REBAR_STYLE \
(WS_CHILD | WS_VISIBLE | WS_BORDER | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS)
#endif //!(_WIN32_IE >= 0x0400)
// rebar without borders
#if (_WIN32_IE >= 0x0400)
#define ATL_SIMPLE_REBAR_NOBORDER_STYLE \
(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS | RBS_AUTOSIZE | CCS_NODIVIDER)
#else
#define ATL_SIMPLE_REBAR_NOBORDER_STYLE \
(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | RBS_VARHEIGHT | RBS_BANDBORDERS | CCS_NODIVIDER)
#endif //!(_WIN32_IE >= 0x0400)
// command bar support
#if !defined(__ATLCTRLW_H__) && !defined(_WIN32_WCE)
#define CBRM_GETCMDBAR (WM_USER + 301) // return command bar HWND
#define CBRM_GETMENU (WM_USER + 302) // returns loaded or attached menu
#define CBRM_TRACKPOPUPMENU (WM_USER + 303) // displays a popup menu
struct _AtlFrameWnd_CmdBarPopupMenu
{
int cbSize;
HMENU hMenu;
UINT uFlags;
int x;
int y;
LPTPMPARAMS lptpm;
};
#define CBRPOPUPMENU _AtlFrameWnd_CmdBarPopupMenu
#endif //!defined(__ATLCTRLW_H__) && !defined(_WIN32_WCE)
template <class TBase = ATL::CWindow, class TWinTraits = ATL::CFrameWinTraits>
class ATL_NO_VTABLE CFrameWindowImplBase : public ATL::CWindowImplBaseT< TBase, TWinTraits >
{
public:
DECLARE_FRAME_WND_CLASS(NULL, 0)
// Data members
HWND m_hWndToolBar;
HWND m_hWndStatusBar;
HWND m_hWndClient;
HACCEL m_hAccel;
#ifdef _WIN32_WCE
HWND m_hWndCECommandBar;
#endif //_WIN32_WCE
struct _AtlToolBarData
{
WORD wVersion;
WORD wWidth;
WORD wHeight;
WORD wItemCount;
//WORD aItems[wItemCount]
WORD* items()
{ return (WORD*)(this+1); }
};
#if (_WIN32_IE >= 0x0500) && !defined(_WIN32_WCE)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -