📄 cdrawmenu.cpp
字号:
pDC->ExtTextOut(rect.left ,rect.top, ETO_CLIPPED ,NULL, strText, NULL);
//s.Format(L"%d_1",i);
//AfxMessageBox(s);
}
else
{
// Draw the slightly lighter greyed text at an offset:
RECT offset = *rect;
offset.left+=1;
offset.right+=1;
offset.top+=1;
offset.bottom+=1;
pDC->SetTextColor(GetSysColor(COLOR_BTNHIGHLIGHT));//COLOR_BTNHILIGHT
//pDC->DrawText(strText,&offset, nFormat);
pDC->ExtTextOut(rect.left ,rect.top, ETO_CLIPPED ,NULL, strText, NULL);
//int i = pDC->DrawText (strText,rect,nFormat);
//s.Format(L"%d_2",i);
//AfxMessageBox(s);
// And the standard Grey text:
pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
//pDC->DrawText(strText,rect, nFormat);
pDC->ExtTextOut(rect.left ,rect.top, ETO_CLIPPED ,NULL, strText, NULL);
//i = pDC->DrawText (strText,rect,nFormat);
//s.Format(L"%d_3",i);
//AfxMessageBox(s);
};
pDC->SetBkMode( iOldMode );
pDC->SelectObject (pFont); //set it to the old font
}
dispFont.DeleteObject ();
}
void CDrawMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS )
{
// Obtain the width of the text:
CWnd *pWnd = AfxGetMainWnd(); // Get main window
CDC *pDC = pWnd->GetDC(); // Get device context
CFont* pFont = pDC->SelectObject (&m_fontMenu); // Select menu font in...
//LPCTSTR lpstrText = (((CDrawMenuData*)(lpMIS->itemData))->menuText); // Get pointer to text
CString sText = (((CDrawMenuData*)(lpMIS->itemData))->menuText);
SIZE t;
//GetTextExtentPoint32(pDC->GetSafeHdc(), lpstrText, strlen(lpstrText), &t); // Width of caption
GetTextExtentPoint32(pDC->GetSafeHdc(), sText, sText.GetLength(), &t);
pDC->SelectObject (pFont); // Select old font in
AfxGetApp()->m_pMainWnd->ReleaseDC (pDC); // Release the DC
// Set width and height:
lpMIS->itemWidth = m_iconX + t.cx + 10;
lpMIS->itemHeight = m_iconY;
}
void CDrawMenu::SetIconSize (int width, int height)
{
m_iconX = width;
m_iconY = height;
}
void CDrawMenu::SetTextColor (COLORREF clrText)
{
m_crText = clrText;
}
void CDrawMenu::SetBackColor (COLORREF clrBack)
{
m_clrBack = clrBack;
if ((HBRUSH)m_brBackground != NULL)
m_brBackground.DeleteObject ();
m_brBackground.CreateSolidBrush (clrBack);
}
void CDrawMenu::SetIconBgColor (COLORREF clrIconBack)
{
m_clrIconBack = clrIconBack;
if ((HBRUSH)m_brIconBack != NULL)
m_brIconBack.DeleteObject ();
m_brIconBack.CreateSolidBrush (clrIconBack);
}
void CDrawMenu::SetHighlightColor (COLORREF clrHilight)
{
m_clrHilight = clrHilight;
if ((HBRUSH)m_brSelect != NULL)
m_brSelect.DeleteObject ();
m_brSelect.CreateSolidBrush (clrHilight);
}
void CDrawMenu::SetHighlightTextColor (COLORREF clrHilightText)
{
m_clrHilightText = clrHilightText;
}
void CDrawMenu::SetHighlightStyle (HIGHLIGHTSTYLE hilightStyle)
{
m_hilightStyle = hilightStyle;
}
BOOL CDrawMenu::AppendODMenu(CString strText,//
UINT nFlags,
UINT nID,
UINT nIconNormal,
UINT nIconSelected,
UINT nIconDisabled)
{
// Add the MF_OWNERDRAW flag if not specified:
if(!(nFlags & MF_OWNERDRAW))
nFlags |= MF_OWNERDRAW;
CDrawMenuData *mdata = new CDrawMenuData;
m_MenuList.Add(mdata);
//lstrcpy(mdata->menuText, lpstrText);
mdata->menuText = strText;
mdata->menuIconNormal = nIconNormal;
mdata->menuIconSelected = nIconSelected;
mdata->menuIconDisabled = nIconDisabled;
return(CMenu::AppendMenu(nFlags, nID, (LPCTSTR)mdata));
};
BOOL CDrawMenu::ModifyODMenu(CString strText,
UINT nID,
UINT nIconNormal,
UINT nIconSelected,
UINT nIconDisabled)
{
// Delete the existing CDrawMenuData structure associated with this item (if any)
int numMenuItems = m_MenuList.GetUpperBound();
CDrawMenuData *mdata;
for(int m = 0; m <= numMenuItems; m++)
{
if((mdata = m_MenuList[m]) != NULL)
{
if(mdata->nID == nID)
{
delete(mdata);
m_MenuList.RemoveAt(m);
break;
};
};
};
// Create a new CDrawMenuData structure:
mdata = new CDrawMenuData;
m_MenuList.Add(mdata);
mdata->menuText = strText;
mdata->menuIconNormal = nIconNormal;
mdata->menuIconSelected = nIconSelected;
mdata->menuIconDisabled = nIconDisabled;
return(CMenu::ModifyMenu(nID, MF_BYCOMMAND | MF_OWNERDRAW, nID, (LPCTSTR)mdata));
};
/*
BOOL CDrawMenu::LoadMenu(LPCTSTR lpszResourceName)
{
return(CDrawMenu::LoadMenu(MAKEINTRESOURCE(lpszResourceName)));
};
BOOL CDrawMenu::LoadMenu(int nResource)
{
/// Find the Menu Resource:
DWORD dwSize;
WORD wrd = MAKEWORD(nResource, 0);
HRSRC hRsrc = FindResource(NULL, (LPCTSTR)wrd, RT_MENU); // Find the resource
if(hRsrc == NULL)
{
TRACE0("CDrawMenu::LoadMenu() - Failed to find Menu Resource\n");
ASSERT(FALSE);
};
// Get size of resource:
dwSize = SizeofResource(NULL, hRsrc);
// Load the Menu Resource:
HGLOBAL hGlobal = LoadResource(NULL, hRsrc);
if(hGlobal == NULL)
{
TRACE0("CDrawMenu::LoadMenu() - Failed to load Menu Resource\n");
ASSERT(FALSE);
};
// Attempt to create us as a menu...
if(!CMenu::CreateMenu())
{
TRACE0("CDrawMenu::LoadMenu() - Failed to create Menu\n");
ASSERT(FALSE);
};
// Get Item template Header, and calculate offset of MENUITEMTEMPLATES
/////////////////////////////////
//MENUITEMTEMPLATEHEADER* pTpHdr = (MENUITEMTEMPLATEHEADER*)LockResource(hGlobal);
BYTE* pTp;// = (BYTE*)pTpHdr +
// (sizeof(MENUITEMTEMPLATEHEADER) + pTpHdr->offset);
// Variables needed during processing of Menu Item Templates:
CDrawMenuData* pData = NULL; // New OD Menu Item Data
WORD dwFlags = 0; // Flags of the Menu Item
WORD dwID = 0; // ID of the Menu Item
BOOL bLastPopup = 0; // Last popup?
UINT uFlags; // Actual Flags.
char caption[80]; // Allows up to 80 chars for caption
int nLen = 0; // Length of caption
CTypedPtrArray<CPtrArray, CDrawMenu*> m_Stack; // Popup menu stack
m_Stack.Add(this); // Add it to this...
do
{
// Obtain Flags and (if necessary), the ID...
/////////////////////////////
memcpy(&dwFlags, pTp, sizeof(WORD));pTp+=sizeof(WORD); // Obtain Flags
if(!(dwFlags & MF_POPUP))
{
//////////////////////////////////
memcpy(&dwID, pTp, sizeof(WORD)); // Obtain ID
pTp+=sizeof(WORD);
}
else
dwID = 0;
uFlags = (UINT)dwFlags; // Remove MF_END from the flags that will
if(uFlags & MF_END) // be passed to the Append(OD)Menu functions.
uFlags -= MF_END;
// Obtain Caption (and length)
nLen = 0;
char *ch;// = (char*)pTp
while(*ch != 0)
{
caption[nLen] = ch[0];
nLen++; // Increment length
ch+=2; // Accounts for UNICODE '0's...
};
caption[nLen] = 0; // Zero-terminate the string...
pTp+=((nLen+1)*2); // Increase Pointer...
// Handle popup menus first....
if(dwFlags & MF_POPUP)
{
if(dwFlags & MF_END)
bLastPopup = TRUE;
CDrawMenu* pSubMenu = new CDrawMenu;
pSubMenu->CreatePopupMenu();
// Append it to the top of the stack:
///////////////////////////////////////////////
//m_Stack[m_Stack.GetUpperBound()]->AppendMenu(uFlags, (UINT)pSubMenu->m_hMenu, caption);
m_Stack.Add(pSubMenu); // Add to PopupStack
m_SubMenus.Add(pSubMenu); // For deletion...
}
else
{
m_Stack[m_Stack.GetUpperBound()]->AppendODMenu(caption, uFlags, dwID, -1, -1, -1);
if(dwFlags & MF_END)
m_Stack.RemoveAt(m_Stack.GetUpperBound()); // Remove top of stack
if(bLastPopup)
{
bLastPopup = FALSE;
m_Stack.RemoveAt(m_Stack.GetUpperBound()); // And again...
};
};
}while(m_Stack.GetUpperBound() != -1);
return(TRUE);
};
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -