?? atlctrlw.h
字號:
// Windows Template Library - WTL version 7.0
// Copyright (C) 1997-2002 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 __ATLCTRLW_H__
#define __ATLCTRLW_H__
#pragma once
#ifndef __cplusplus
#error ATL requires C++ compilation (use a .cpp suffix)
#endif
#ifndef __ATLAPP_H__
#error atlctrlw.h requires atlapp.h to be included first
#endif
#ifndef __ATLCTRLS_H__
#error atlctrlw.h requires atlctrls.h to be included first
#endif
#if (_WIN32_IE < 0x0400)
#error atlctrlw.h requires _WIN32_IE >= 0x0400
#endif
/////////////////////////////////////////////////////////////////////////////
// Classes in this file
//
// CCommandBarCtrlImpl<T, TBase, TWinTraits>
// CCommandBarCtrl
// CMDICommandBarCtrlImpl<T, TBase, TWinTraits>
// CMDICommandBarCtrl
namespace WTL
{
/////////////////////////////////////////////////////////////////////////////
// Command Bars
// Window Styles:
#define CBRWS_TOP CCS_TOP
#define CBRWS_BOTTOM CCS_BOTTOM
#define CBRWS_NORESIZE CCS_NORESIZE
#define CBRWS_NOPARENTALIGN CCS_NOPARENTALIGN
#define CBRWS_NODIVIDER CCS_NODIVIDER
// Extended styles
#define CBR_EX_TRANSPARENT 0x00000001L
#define CBR_EX_SHAREMENU 0x00000002L
#define CBR_EX_ALTFOCUSMODE 0x00000004L
#define CBR_EX_TRACKALWAYS 0x00000008L
// standard command bar styles
#define ATL_SIMPLE_CMDBAR_PANE_STYLE \
(WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | CBRWS_NODIVIDER | CBRWS_NORESIZE | CBRWS_NOPARENTALIGN)
// Messages - support chevrons for frame windows
#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
typedef struct tagCBRPOPUPMENU
{
int cbSize;
HMENU hMenu; // popup menu do display
UINT uFlags; // TPM_* flags for ::TrackPopupMenuEx
int x;
int y;
LPTPMPARAMS lptpm; // ptr to TPMPARAMS for ::TrackPopupMenuEx
} CBRPOPUPMENU, *LPCBRPOPUPMENU;
// helper class
template <class T>
class CSimpleStack : public CSimpleArray< T >
{
public:
BOOL Push(T t)
{
#ifdef _CMDBAR_EXTRA_TRACE
ATLTRACE2(atlTraceUI, 0, "CmdBar - STACK-PUSH (%8.8X) size = %i\n", t, GetSize());
#endif
return Add(t);
}
T Pop()
{
int nLast = GetSize() - 1;
if(nLast < 0)
return NULL; // must be able to convert to NULL
T t = m_aT[nLast];
#ifdef _CMDBAR_EXTRA_TRACE
ATLTRACE2(atlTraceUI, 0, "CmdBar - STACK-POP (%8.8X) size = %i\n", t, GetSize());
#endif
if(!RemoveAt(nLast))
return NULL;
return t;
}
T GetCurrent()
{
int nLast = GetSize() - 1;
if(nLast < 0)
return NULL; // must be able to convert to NULL
return m_aT[nLast];
}
};
/////////////////////////////////////////////////////////////////////////////
// CCommandBarCtrlBase - base class for the Command Bar implementation
class CCommandBarCtrlBase : public CToolBarCtrl
{
public:
struct _MsgHookData
{
HHOOK hMsgHook;
DWORD dwUsage;
_MsgHookData() : hMsgHook(NULL), dwUsage(0) { }
};
typedef CSimpleMap<DWORD, _MsgHookData*> CMsgHookMap;
static CMsgHookMap* s_pmapMsgHook;
static HHOOK s_hCreateHook;
static bool s_bW2K; // For animation flag
static CCommandBarCtrlBase* s_pCurrentBar;
static bool s_bStaticInit;
CSimpleStack<HWND> m_stackMenuWnd;
CSimpleStack<HMENU> m_stackMenuHandle;
HWND m_hWndHook;
DWORD m_dwMagic;
CCommandBarCtrlBase() : m_hWndHook(NULL), m_dwMagic(1314)
{
// init static variables
if(!s_bStaticInit)
{
::EnterCriticalSection(&_Module.m_csStaticDataInit);
if(!s_bStaticInit)
{
// Just in case...
INITCOMMONCONTROLSEX iccx;
iccx.dwSize = sizeof(iccx);
iccx.dwICC = ICC_COOL_CLASSES | ICC_BAR_CLASSES;
::InitCommonControlsEx(&iccx);
// Animation on Win2000 only
s_bW2K = !AtlIsOldWindows();
// done
s_bStaticInit = true;
}
::LeaveCriticalSection(&_Module.m_csStaticDataInit);
}
}
bool IsCommandBarBase() const { return m_dwMagic == 1314; }
};
__declspec(selectany) CCommandBarCtrlBase::CMsgHookMap* CCommandBarCtrlBase::s_pmapMsgHook = NULL;
__declspec(selectany) HHOOK CCommandBarCtrlBase::s_hCreateHook = NULL;
__declspec(selectany) CCommandBarCtrlBase* CCommandBarCtrlBase::s_pCurrentBar = NULL;
__declspec(selectany) bool CCommandBarCtrlBase::s_bW2K = false;
__declspec(selectany) bool CCommandBarCtrlBase::s_bStaticInit = false;
/////////////////////////////////////////////////////////////////////////////
// CCommandBarCtrl - ATL implementation of Command Bars
template <class T, class TBase = CCommandBarCtrlBase, class TWinTraits = CControlWinTraits>
class ATL_NO_VTABLE CCommandBarCtrlImpl : public CWindowImpl< T, TBase, TWinTraits >
{
public:
DECLARE_WND_SUPERCLASS(NULL, TBase::GetWndClassName())
// Declarations
struct _MenuItemData // menu item data
{
DWORD dwMagic;
LPTSTR lpstrText;
UINT fType;
UINT fState;
int iButton;
_MenuItemData() { dwMagic = 0x1313; }
bool IsCmdBarMenuItem() { return (dwMagic == 0x1313); }
};
struct _ToolBarData // toolbar resource data
{
WORD wVersion;
WORD wWidth;
WORD wHeight;
WORD wItemCount;
//WORD aItems[wItemCount]
WORD* items()
{ return (WORD*)(this+1); }
};
// Constants
enum _CmdBarDrawConstants
{
s_kcxGap = 1,
s_kcxTextMargin = 2,
s_kcxButtonMargin = 3,
s_kcyButtonMargin = 3
};
enum
{
_nMaxMenuItemTextLength = 100,
_chChevronShortcut = _T('/')
};
#ifndef DT_HIDEPREFIX
enum { DT_HIDEPREFIX = 0x00100000 };
#endif //!DT_HIDEPREFIX
// Data members
HMENU m_hMenu;
HIMAGELIST m_hImageList;
CSimpleValArray<WORD> m_arrCommand;
DWORD m_dwExtendedStyle; // Command Bar specific extended styles
CContainedWindow m_wndParent;
bool m_bMenuActive:1;
bool m_bAttachedMenu:1;
bool m_bImagesVisible:1;
bool m_bPopupItem:1;
bool m_bContextMenu:1;
bool m_bEscapePressed:1;
bool m_bSkipMsg:1;
bool m_bParentActive:1;
bool m_bFlatMenus:1;
bool m_bUseKeyboardCues:1;
bool m_bShowKeyboardCues:1;
bool m_bAllowKeyboardCues:1;
bool m_bKeyboardInput:1;
bool m_bAlphaImages:1;
int m_nPopBtn;
int m_nNextPopBtn;
SIZE m_szBitmap;
SIZE m_szButton;
COLORREF m_clrMask;
CFont m_fontMenu; // used internally, only to measure text
UINT m_uSysKey;
HWND m_hWndFocus; // Alternate focus mode
int m_cxExtraSpacing;
// Constructor/destructor
CCommandBarCtrlImpl() :
m_hMenu(NULL),
m_hImageList(NULL),
m_wndParent(this, 1),
m_bMenuActive(false),
m_bAttachedMenu(false),
m_nPopBtn(-1),
m_nNextPopBtn(-1),
m_bPopupItem(false),
m_bImagesVisible(true),
m_bSkipMsg(false),
m_uSysKey(0),
m_hWndFocus(NULL),
m_bContextMenu(false),
m_bEscapePressed(false),
m_clrMask(RGB(192, 192, 192)),
m_dwExtendedStyle(CBR_EX_TRANSPARENT | CBR_EX_SHAREMENU | CBR_EX_TRACKALWAYS),
m_bParentActive(true),
m_bFlatMenus(false),
m_bUseKeyboardCues(false),
m_bShowKeyboardCues(false),
m_bAllowKeyboardCues(true),
m_bKeyboardInput(false),
m_cxExtraSpacing(0),
m_bAlphaImages(false)
{
SetImageSize(16, 15); // default
}
~CCommandBarCtrlImpl()
{
if(m_wndParent.IsWindow())
/*scary!*/ m_wndParent.UnsubclassWindow();
if(m_hMenu != NULL && (m_dwExtendedStyle & CBR_EX_SHAREMENU) == 0)
::DestroyMenu(m_hMenu);
if(m_hImageList != NULL)
::ImageList_Destroy(m_hImageList);
}
// Attributes
DWORD GetCommandBarExtendedStyle() const
{
return m_dwExtendedStyle;
}
DWORD SetCommandBarExtendedStyle(DWORD dwExtendedStyle, DWORD dwMask = 0)
{
DWORD dwPrevStyle = m_dwExtendedStyle;
if(dwMask == 0)
m_dwExtendedStyle = dwExtendedStyle;
else
m_dwExtendedStyle = (m_dwExtendedStyle & ~dwMask) | (dwExtendedStyle & dwMask);
return dwPrevStyle;
}
CMenuHandle GetMenu() const
{
ATLASSERT(::IsWindow(m_hWnd));
return m_hMenu;
}
COLORREF GetImageMaskColor() const
{
return m_clrMask;
}
COLORREF SetImageMaskColor(COLORREF clrMask)
{
COLORREF clrOld = m_clrMask;
m_clrMask = clrMask;
return clrOld;
}
bool GetImagesVisible() const
{
return m_bImagesVisible;
}
bool SetImagesVisible(bool bVisible)
{
bool bOld = m_bImagesVisible;
m_bImagesVisible = bVisible;
return bOld;
}
void GetImageSize(SIZE& size) const
{
size = m_szBitmap;
}
bool SetImageSize(SIZE& size)
{
return SetImageSize(size.cx, size.cy);
}
bool SetImageSize(int cx, int cy)
{
if(m_hImageList != NULL)
{
if(::ImageList_GetImageCount(m_hImageList) == 0) // empty
{
::ImageList_Destroy(m_hImageList);
m_hImageList = NULL;
}
else
{
return false; // can't set, image list exists
}
}
if(cx == 0 || cy == 0)
return false;
m_szBitmap.cx = cx;
m_szBitmap.cy = cy;
m_szButton.cx = m_szBitmap.cx + 2 * s_kcxButtonMargin;
m_szButton.cy = m_szBitmap.cy + 2 * s_kcyButtonMargin;
return true;
}
bool GetAlphaImages() const
{
return m_bAlphaImages;
}
bool SetAlphaImages(bool bAlphaImages)
{
if(m_hImageList != NULL)
{
if(::ImageList_GetImageCount(m_hImageList) == 0) // empty
{
::ImageList_Destroy(m_hImageList);
m_hImageList = NULL;
}
else
{
return false; // can't set, image list exists
}
}
m_bAlphaImages = bAlphaImages;
return true;
}
HWND GetCmdBar() const
{
ATLASSERT(::IsWindow(m_hWnd));
return (HWND)::SendMessage(m_hWnd, CBRM_GETCMDBAR, 0, 0L);
}
// Methods
HWND Create(HWND hWndParent, RECT& rcPos, LPCTSTR szWindowName = NULL,
DWORD dwStyle = 0, DWORD dwExStyle = 0,
UINT nID = 0, LPVOID lpCreateParam = NULL)
{
// These styles are required for command bars
dwStyle |= TBSTYLE_LIST | TBSTYLE_FLAT;
return CWindowImpl< T, TBase, TWinTraits >::Create(hWndParent, rcPos, szWindowName, dwStyle, dwExStyle, nID, lpCreateParam);
}
BOOL AttachToWindow(HWND hWnd)
{
ATLASSERT(m_hWnd == NULL);
ATLASSERT(::IsWindow(hWnd));
BOOL bRet = SubclassWindow(hWnd);
if(bRet)
{
m_bAttachedMenu = true;
T* pT = static_cast<T*>(this);
pT->GetSystemSettings();
}
return bRet;
}
BOOL LoadMenu(_U_STRINGorID menu)
{
ATLASSERT(::IsWindow(m_hWnd));
if(m_bAttachedMenu) // doesn't work in this mode
return FALSE;
if(menu.m_lpstr == NULL)
return FALSE;
HMENU hMenu = ::LoadMenu(_Module.GetResourceInstance(), menu.m_lpstr);
if(hMenu == NULL)
return FALSE;
return AttachMenu(hMenu);
}
BOOL AttachMenu(HMENU hMenu)
{
ATLASSERT(::IsWindow(m_hWnd));
ATLASSERT(::IsMenu(hMenu));
if(hMenu != NULL && !::IsMenu(hMenu))
return FALSE;
// destroy old menu, if needed, and set new one
if(m_hMenu != NULL && (m_dwExtendedStyle & CBR_EX_SHAREMENU) == 0)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -