?? menubar.cpp
字號:
if (!(m_arrItem[nIndex]->GetStyle() & MISTYLE_TRACKABLE) ||
(m_arrItem[nIndex]->GetState() & MISTATE_HIDDEN)) {
return GetNextOrPrevButton(nIndex, bPrev);
}
return nIndex;
}
//******************************************************************
/////////////////////////////////////////////////////////////////////////////
// CMenuBar insists own bar line
void CMenuBar::EnableDockingEx(DWORD dwDockStyle)
{
// pasted from CFrameWnd implementation
static const DWORD dwDockBarMap[4][2] =
{
{ AFX_IDW_DOCKBAR_TOP, CBRS_TOP },
{ AFX_IDW_DOCKBAR_BOTTOM, CBRS_BOTTOM },
{ AFX_IDW_DOCKBAR_LEFT, CBRS_LEFT },
{ AFX_IDW_DOCKBAR_RIGHT, CBRS_RIGHT },
};
EnableDocking(dwDockStyle);
// must be CBRS_ALIGN_XXX or CBRS_FLOAT_MULTI only
ASSERT((dwDockStyle & ~(CBRS_ALIGN_ANY|CBRS_FLOAT_MULTI)) == 0);
CFrameWnd* pFrame = CControlBar::GetParentFrame(); ASSERT_VALID(pFrame);
//pFrame->m_pFloatingFrameClass = RUNTIME_CLASS(CMiniDockFrameWnd);
for (int i = 0; i < 4; i++)
{
if (dwDockBarMap[i][1] & dwDockStyle & CBRS_ALIGN_ANY)
{
CDockBar* pDock = (CDockBar*)pFrame->GetControlBar(dwDockBarMap[i][0]);
if (pDock == NULL)
{
pDock = new CMenuDockBar;// which wait for CMenuBar
if (!pDock->Create(pFrame,
WS_CLIPSIBLINGS|WS_CLIPCHILDREN|WS_CHILD|WS_VISIBLE |
dwDockBarMap[i][1], dwDockBarMap[i][0]))
{
AfxThrowResourceException();
}
}
}
}
}
//******************************************************************
/////////////////////////////////////////////////////////////////////////////
// CMenuBar OLE menu support
// MFC does'nt do command routing for other process server.
// ::TrackPopupMenuEx won't accept HWND of other process and
// we have to determine a message target(ole server window or not)
// as ::OleCreateMenuDescriptor do.
// This is a hard coding.
// First menu(ordinarily File menu) and WindowMenu regarded as container's own menu.
// Some components can't update toolbar button and statusbar pane.
HWND CMenuBar::OleMenuDescriptor(BOOL& bSend, UINT nMsg, WPARAM wParam, LPARAM lParam)
{
CWnd* pOleWnd = GetCmdSentOleWnd();
if (pOleWnd == NULL)
return NULL;
HWND hWndSentCmd = NULL;
HMENU hMenu = NULL;
if (nMsg == WM_INITMENUPOPUP || nMsg == WM_INITMENU)
hMenu = (HMENU)wParam;
else if (nMsg == WM_MENUSELECT)
hMenu = (HMENU)lParam;
switch (nMsg) {
case WM_INITMENUPOPUP:
case WM_INITMENU:
case WM_MENUSELECT:
bSend = TRUE;
if (m_nTrackingState == popup) {
LTRACE2(_T(" now popup\n"));
if (m_bMDIApp) {
LTRACE2(_T(" this is MDI\n"));
if (m_nCurIndex == 0 || m_nCurIndex == 1 || hMenu == m_hWindowMenu) {
LTRACE2(_T(" it's container menu, send to frame\n"));
return NULL;
}
}
else {
LTRACE2(_T(" it's container menu, send to frame\n"));
if (m_nCurIndex == 0) {
return NULL;
}
}
LTRACE2(_T(" it's server menu, send to server\n"));
return pOleWnd->GetSafeHwnd();
}
break;
case WM_COMMAND:
bSend = FALSE;
if (m_bMDIApp) {
LTRACE2(_T(" this is MDI\n"));
if (_nPrevIndexForCmd == 0 || _nPrevIndexForCmd == 1 || _bWindowMenuSendCmd) {
LTRACE2(_T(" it's container menu, send to frame\n"));
return NULL;
}
}
else {
if (_nPrevIndexForCmd == 0) {
LTRACE2(_T(" it's container menu, send to frame\n"));
return NULL;
}
}
LTRACE2(_T(" it's server menu, send to server\n"));
return pOleWnd->GetSafeHwnd();
}
return NULL;// send to frame
}
//******************************************************************
CWnd* CMenuBar::GetCmdSentOleWnd()
{
// *****fixed by VORGA, thanks!*****
CWnd* pWnd = AfxGetMainWnd();
if (pWnd == NULL || !pWnd->IsFrameWnd())
return NULL;
CFrameWnd* pFrame = NULL;
if (m_bMDIApp) {
CMDIFrameWnd *pMDIFrame = STATIC_DOWNCAST(CMDIFrameWnd, pWnd);
if (pMDIFrame == NULL)
return NULL;
pFrame = pMDIFrame->GetActiveFrame();
}
else {
pFrame = STATIC_DOWNCAST(CFrameWnd, pWnd);
}
if (pFrame == NULL)
return NULL;
CDocument* pDoc = pFrame->GetActiveDocument();
if (pDoc != NULL && pDoc->IsKindOf(RUNTIME_CLASS(COleDocument))) {
COleDocument* pOleDoc = STATIC_DOWNCAST(COleDocument, pDoc);
ASSERT_VALID(pOleDoc);
COleClientItem* pClientItem = pOleDoc->GetInPlaceActiveItem(pFrame);
CWnd* pWnd = (pClientItem == NULL) ? NULL : pClientItem->GetInPlaceWindow();
if (pWnd != NULL) {
return pWnd;
}
}
return NULL;
}
//******************************************************************
/////////////////////////////////////////////////////////////////////////////
// CMDIClientHook
CMDIClientHook::CMDIClientHook()
{
m_pMenuBar = NULL;
}
//******************************************************************
BOOL CMDIClientHook::Install(CMenuBar* pMenuBar, HWND hWndToHook)
{
ASSERT_VALID(pMenuBar);
ASSERT(m_pMenuBar == NULL);
m_pMenuBar = pMenuBar;
return HookWindow(hWndToHook);
}
//******************************************************************
CMDIClientHook::~CMDIClientHook()
{
}
//******************************************************************
LRESULT CMDIClientHook::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
ASSERT_VALID(m_pMenuBar);
switch (nMsg) {
case WM_MDISETMENU: // only sent to MDI client window
// Setting new frame/window menu: bypass MDI. wParam is new menu.
if (wParam) {
//LTRACE(_T("CMenuBar::WM_MDISETMENU 0x%04x\n"), wParam);
m_pMenuBar->OnSetMenu((HMENU)wParam, (HMENU)lParam);
}
return 0;
case WM_MDIREFRESHMENU: // only sent to MDI client window
// Normally, would call DrawMenuBar, but I have the menu, so eat it.
//LTRACE(_T("CMenuBar::WM_MDIREFRESHMENU\n"));
return 0;
}
return CSubclassWnd::WindowProc(nMsg, wParam, lParam);
}
//******************************************************************
/////////////////////////////////////////////////////////////////////////////
// CMainFrameHook
CMainFrameHook::CMainFrameHook()
{
m_pMenuBar = NULL;
}
//******************************************************************
BOOL CMainFrameHook::Install(CMenuBar* pMenuBar, HWND hWndToHook)
{
ASSERT_VALID(pMenuBar);
ASSERT(m_pMenuBar == NULL);
m_pMenuBar = pMenuBar;
return HookWindow(hWndToHook);
}
//******************************************************************
CMainFrameHook::~CMainFrameHook()
{
}
//******************************************************************
LRESULT CMainFrameHook::WindowProc(UINT nMsg, WPARAM wParam, LPARAM lParam)
{
ASSERT_VALID(m_pMenuBar);
// be care for other windows(MainFrame) hooking
// possible called when already this wnd destroyed (WM_NCACTIVATE is)
if (!::IsWindow(m_pMenuBar->m_hWnd)) {
return CSubclassWnd::WindowProc(nMsg, wParam, lParam);
}
BOOL bSend = FALSE;
if (HWND hWndServer = m_pMenuBar->OleMenuDescriptor(bSend, nMsg, wParam, lParam)) {
// OLE wnd will handle message
if (bSend)
return ::SendMessage(hWndServer, nMsg, wParam, lParam);
else
return ::PostMessage(hWndServer, nMsg, wParam, lParam);
}
switch (nMsg) {
case WM_MENUSELECT:
m_pMenuBar->OnMenuSelect((HMENU)lParam, (UINT)LOWORD(wParam));
break;
case WM_INITMENUPOPUP:
if (!HIWORD(lParam) && (HMENU)wParam == m_pMenuBar->m_hWindowMenu)
m_pMenuBar->OnInitMenuPopup(CMenu::FromHandle((HMENU)wParam),
LOWORD(lParam), (BOOL)HIWORD(lParam));
break;
case WM_NCACTIVATE:
m_pMenuBar->OnFrameNcActivate((BOOL)wParam);
break;
case WM_SYSCOLORCHANGE:
case WM_SETTINGCHANGE:
LTRACE(_T("CMenuBar::WM_SETTINGCHANGE\n"));
// It's enough to reinitialize common resources once.
m_pMenuBar->OnSettingChange(wParam, lParam);
break;
}
if (nMsg == CMenuBar::WM_GETMENU)
return (LRESULT)m_pMenuBar->m_hMenu;
return CSubclassWnd::WindowProc(nMsg, wParam, lParam);
}
//******************************************************************
//////////////////////////////////////////////////////////////////////
// CMenuItem interface
CMenuItem::CMenuItem()
{
m_fsStyle = 0;
m_fsState = 0;
m_rcItem.SetRectEmpty();
m_sizeHorz = CSize(0, 0);
m_cAccessKey = 0;
}
//******************************************************************
void CMenuItem::ModifyState(BYTE fsRemove, BYTE fsAdd)
{
m_fsState = (m_fsState & ~fsRemove) | fsAdd;
}
//******************************************************************
CSize CMenuItem::GetHorizontalSize() const
{
if (m_fsState & MISTATE_HIDDEN)
return CSize(0, 0);
else
return m_sizeHorz;
}
//-----------------------------------------------------------------
CGuiMenuButton::CGuiMenuButton()
{
m_bHorz=TRUE;
}
CGuiMenuButton::~CGuiMenuButton()
{
}
void CGuiMenuButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pdc= CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc=lpDrawItemStruct->rcItem;
UINT uState=lpDrawItemStruct->itemState;
CBrush cb;
if( uState & ODS_SELECTED) //the button is pressed
cb.CreateSolidBrush(GuiDrawLayer::GetRGBPressBXP());
else
if (m_bMouserOver)
cb.CreateSolidBrush(GuiDrawLayer::GetRGBFondoXP());
else
cb.CreateSolidBrush(m_clColor);
if (( uState == ODS_SELECTED) || m_bMouserOver )
{
pdc->Draw3dRect(rc,GuiDrawLayer::GetRGBCaptionXP(),GuiDrawLayer::GetRGBCaptionXP());
rc.DeflateRect(1,1);
}
pdc->FillRect(rc,&cb);
if (m_SizeText.cx > 2)
{
int nMode = pdc->SetBkMode(TRANSPARENT);
if (m_bHorz)
{
CRect rectletra=rc;
CPoint pt=CSize(rectletra.top+1,rectletra.left);
if (uState & ODS_DISABLED)
pdc->DrawState(pt, m_SizeText, m_szText, DSS_DISABLED, TRUE, 0, (CBrush*)NULL);
else
{
if(m_bMouserOver != 1)
pdc->SetTextColor(m_clrFont);
pdc->DrawText(m_szText,rectletra,DT_SINGLELINE|DT_CENTER|DT_VCENTER);
}
}
else
{
if (( uState == ODS_SELECTED) || m_bMouserOver )
rc.InflateRect(1,1);
COLORREF clr = ::GetSysColor(COLOR_MENUTEXT);
pdc->SetTextColor(clr);
CPoint ptOffset=CPoint(1,1);
CRect rcBtn = rc;
int nLength = m_szText.GetLength();
int nIndex = m_szText.Find('&');
CString strBtn = m_szText.Left(nIndex) + m_szText.Right(nLength - (nIndex+1));
// fixed for WinNT. *****fixed by Simon, thanks!*****
int iGraphicsMode = ::GetGraphicsMode(pdc->m_hDC);
::SetGraphicsMode(pdc->m_hDC, GM_ADVANCED);
pdc->SetBkMode(TRANSPARENT);
CFont* pOldFont = pdc->SelectObject(&_fontVertMenu);
// I know precise text size
//m_sizeHorz=((CMenuBar*)GetParent())->m_sizeHors;
CSize m_sizeHorz;
m_sizeHorz.cx = (_CalcTextWidth(m_szText) + CXTEXTMARGIN*2)+8;
m_sizeHorz.cy = (_cyHorzFont + _cyTextMargin*2)+1;
CRect rcString = CRect(
CPoint(rcBtn.right - _cyTextMargin, rcBtn.top + CXTEXTMARGIN), m_sizeHorz);
pdc->DrawText(strBtn, rcString + ptOffset,
DT_SINGLELINE | DT_NOCLIP | DT_NOPREFIX);// don't forget DT_NOCLIP
gbintHorz=-1;
rcMenu=rcBtn;
rcMenu.bottom-=3;
pdc->SelectObject(pOldFont);
// CDC::DrawText is poor, so we have to draw vertical line by ourselves
CPen pen(PS_SOLID, 0, clr);
CPen* pOldPen = pdc->SelectObject(&pen);
CPoint m_ptLineFrom;
CPoint m_ptLineTo;
if (nIndex == 0) {
m_ptLineFrom = CPoint(_cyTextMargin-1, CXTEXTMARGIN+1);
m_ptLineTo = CPoint(_cyTextMargin-1, CXTEXTMARGIN + _CalcTextWidth(strBtn.Left(nIndex+1)));
}
else {
m_ptLineFrom = CPoint(_cyTextMargin-1, CXTEXTMARGIN + _CalcTextWidth(strBtn.Left(nIndex+1)));
m_ptLineTo = CPoint(_cyTextMargin-1, CXTEXTMARGIN + _CalcTextWidth(strBtn.Left(nIndex+1)));
}
pdc->MoveTo(rcBtn.TopLeft() + m_ptLineFrom);
pdc->LineTo(rcBtn.TopLeft() + m_ptLineTo );
pdc->SelectObject(pOldPen);
::SetGraphicsMode( pdc->m_hDC, iGraphicsMode );
}
}
}
BEGIN_MESSAGE_MAP(CGuiMenuButton,CGuiToolButton)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CGuiMenuButton::OnLButtonDown(UINT nFlags, CPoint point)
{
ShowWindow(SW_HIDE);
ClientToScreen(&point);
GetParent()->SendMessage(WM_LBUTTONDOWN,100+GetDlgCtrlID(),MAKEWPARAM(point.x,point.y));
}
CGuiIconButton::CGuiIconButton()
{
}
CGuiIconButton::~CGuiIconButton()
{
}
void CGuiIconButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
CDC* pdc= CDC::FromHandle(lpDrawItemStruct->hDC);
CRect rc=lpDrawItemStruct->rcItem;
UINT uState=lpDrawItemStruct->itemState;
CBrush cb;
cb.CreateSolidBrush(GuiDrawLayer::GetRGBColorFace());
pdc->FillRect(rc,&cb);
CPoint m_point=CPoint(1,1);
if (m_SizeImage.cx > 2)
{
pdc->DrawState (m_point, m_SizeImage,m_Icon,
(uState==ODS_DISABLED?DSS_DISABLED:DSS_NORMAL),(CBrush*)NULL);
}
}
BEGIN_MESSAGE_MAP(CGuiIconButton,CGuiToolButton)
ON_WM_LBUTTONDOWN()
END_MESSAGE_MAP()
void CGuiIconButton::OnLButtonDown(UINT nFlags, CPoint point)
{
ClientToScreen(&point);
GetParent()->SendMessage(WM_LBUTTONDOWN,1000,MAKEWPARAM(point.x,point.y));
}
//-----------------------------------------------------------------
//******************************************************************
//////////////////////////////////////////////////////////////////////
// CMenuButton class
CMenuButton::CMenuButton(HMENU hMenu, int nIndex,CWnd* pWnd)
{
ASSERT(::IsMenu(hMenu));
ASSERT(nIndex >= 0);
m_cfont.CreateFont(-11,0,0,0,400,0,0,0,0,1,2,1,34,"MS Sans Serif");
m_fsStyle |= (MISTYLE_TRACKABLE | MISTYLE_WRAPPABLE);
m_bt.Create(_T(""), WS_VISIBLE | WS_CHILD | BS_PUSHBUTTON | BS_OWNERDRAW,
CRect(0,0,0,0), pWnd, nIndex);
m_bt.SetFont(&_fon
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -