📄 toolmenu.cpp
字号:
if(state&ODS_SELECTED){ // draw the down edges
CPen *pOldPen = pDC->SelectObject (&m_penBack);
pDC->FillRect (rect,&m_brSelect);
pDC->Draw3dRect (rect,crSelect,crSelect);
pDC->SelectObject (pOldPen);
if((HFONT)dispFont != NULL)dispFont.DeleteObject ();
dispFont.CreateFontIndirect (&lf);
}
else {
rect2.SetRect(rect.left,rect.top,rect.left+m_iconX+4+GAP,rect.bottom);
CPen *pOldPen = pDC->SelectObject (&m_penBack);
pDC->FillRect (rect,&m_brBackground);
pDC->FillRect (rect2,&m_newbrBackground);
pDC->SelectObject (pOldPen);
// draw the up edges
pDC->Draw3dRect (rect,m_clrBack,m_clrBack);
pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
if ((HFONT)dispFont != NULL) dispFont.DeleteObject ();
dispFont.CreateFontIndirect (&lf); //Normal
}
// draw the text if there is any
//We have to paint the text only if the image is nonexistant
dy = (rect.Height()-4-m_iconY)/2;
dy = dy<0 ? 0 : dy;
if(checkflag||standardflag||selectedflag||disableflag){
rect2.SetRect(rect.left+1,rect.top+1+dy,rect.left+m_iconX+3,
rect.top+m_iconY+3+dy);
pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
if(checkflag && checkmaps){
pDC->FillRect (rect2,&m_newbrBackground);
rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
rect.top+m_iconY+4+dy);
pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
CPoint ptImage(rect.left+3,rect.top+2+dy);
if(state&ODS_SELECTED)checkmaps->Draw(pDC,1,ptImage,ILD_TRANSPARENT);
else checkmaps->Draw(pDC,0,ptImage,ILD_TRANSPARENT);
}
else if(disableflag){
if(!selectedflag){
CBitmap bitmapstandard;
GetBitmapFromImageList(pDC,bitmap,xoffset,bitmapstandard);
rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
rect.top+m_iconY+4+dy);
pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
COLORREF transparentcol=m_newclrBack;
if(state&ODS_SELECTED)transparentcol=crSelectFill;
if(disable_old_style)
DitherBlt(lpDIS->hDC,rect.left+2,rect.top+2+dy,m_iconX,m_iconY,
(HBITMAP)(bitmapstandard),0,0,transparentcol);
else
DitherBlt2(pDC,rect.left+2,rect.top+2+dy,m_iconX,m_iconY,
bitmapstandard,0,0,transparentcol);
if(state&ODS_SELECTED)pDC->Draw3dRect (rect,crSelect,crSelect);
bitmapstandard.DeleteObject();
}
}
else if(selectedflag){
pDC->FillRect (rect2,&m_brSelect);
if (IsNewShell() && state&ODS_CHECKED){
rect2.SetRect(rect.left,rect.top,rect.left+m_iconX+GAP+3,rect.bottom);
pDC->Draw3dRect(rect2,crSelect,crSelect);
}
CPoint ptImage(rect.left+3,rect.top+2+dy);
if(bitmap)bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
}
else{
if(state&ODS_CHECKED){
if(!XPflag)rect2.SetRect(rect.left+1,rect.top,rect.left+m_iconX+GAP+3,rect.bottom);
else rect2.SetRect(rect.left+1,rect.top,rect.left+m_iconX+GAP+3,rect.bottom-1);
CBrush brushin;
brushin.CreateSolidBrush(LightenColor(crSelect,0.85));
pDC->FillRect(rect2,&brushin);
brushin.DeleteObject();
pDC->Draw3dRect(rect2,crSelect,crSelect);
}
else{
pDC->FillRect (rect2,&m_newbrBackground);
rect2.SetRect(rect.left,rect.top+dy,rect.left+m_iconX+4,
rect.top+m_iconY+4+dy);
pDC->Draw3dRect (rect2,m_newclrBack,m_newclrBack);
}
CPoint ptImage(rect.left+3,rect.top+2+dy);
if(bitmap)bitmap->Draw(pDC,xoffset,ptImage,ILD_TRANSPARENT);
}
}
if(nIconNormal<0 && state&ODS_CHECKED && !checkflag){
CMenuItemInfo info;
info.fMask = MIIM_CHECKMARKS;
::GetMenuItemInfo((HMENU)lpDIS->hwndItem,lpDIS->itemID,
MF_BYCOMMAND, &info);
if(state&ODS_CHECKED || info.hbmpUnchecked) {
if(XPflag)rect2.SetRect(rect.left+2,rect.top+2+dy,rect.left+m_iconX+2,rect.top+m_iconY+3+dy);
else rect2.SetRect(rect.left+2,rect.top+2+dy,rect.left+m_iconX+2,rect.top+m_iconY+2+dy);
DrawXPCheckmark(pDC, rect2,state&ODS_CHECKED ? info.hbmpChecked :
info.hbmpUnchecked,crSelect);
}
}
//This is needed always so that we can have the space for check marks
x0=rect.left;y0=rect.top;
rect.left = rect.left + m_iconX + 8 + GAP;
if(!strText.IsEmpty()){
CRect rectt(rect.left,rect.top-1,rect.right,rect.bottom-1);
// Find tabs
CString leftStr,rightStr;
leftStr.Empty();rightStr.Empty();
int tablocr=strText.ReverseFind(_T('\t'));
if(tablocr!=-1){
rightStr=strText.Mid(tablocr+1);
leftStr=strText.Left(strText.Find(_T('\t')));
rectt.right-=m_iconX;
}
else leftStr=strText;
int iOldMode = pDC->GetBkMode();
pDC->SetBkMode( TRANSPARENT);
// Draw the text in the correct colour:
pFont = pDC->SelectObject (&dispFont);
UINT nFormat = DT_LEFT|DT_SINGLELINE|DT_VCENTER;
UINT nFormatr = DT_RIGHT|DT_SINGLELINE|DT_VCENTER;
if(!(lpDIS->itemState & ODS_GRAYED)){
pDC->SetTextColor(crText);
pDC->DrawText (leftStr,rectt,nFormat);
if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
}
else{
RECT offset = *rectt;
offset.left+=1;
offset.right+=1;
offset.top+=1;
offset.bottom+=1;
if(!XPflag){
COLORREF graycol=GetSysColor(COLOR_GRAYTEXT);
graycol = LightenColor(graycol,0.55);
pDC->SetTextColor(graycol);
}
else pDC->SetTextColor(GetSysColor(COLOR_GRAYTEXT));
pDC->DrawText(leftStr,rectt, nFormat);
if(tablocr!=-1) pDC->DrawText (rightStr,rectt,nFormatr);
}
pDC->SetBkMode( iOldMode );
pDC->SelectObject (pFont); //set it to the old font
}
m_penBack.DeleteObject();
m_fontMenu.DeleteObject();
m_brSelect.DeleteObject();
dispFont.DeleteObject ();
}
m_brBackground.DeleteObject();
m_newbrBackground.DeleteObject();
#ifdef BCMENU_USE_MEMDC
if(pMemDC)delete pMemDC;
#endif
}
void CToolMenu::DrawItem( LPDRAWITEMSTRUCT lpDIS )
{
if (!pmf->m_nMenuStyle)
DrawItem_Win9xNT2000(lpDIS);
else
DrawItem_WinXP(lpDIS);
}
#define GAP 1
void CToolMenu::MeasureItem( LPMEASUREITEMSTRUCT lpMIS )
{
if(lpMIS == NULL)
return;
try
{
// get image size
int cx=16, cy=16;//0;
CMenuData* pmd = (CMenuData*)(lpMIS->itemData);
if(pmd==NULL)
return;
if(pmd->m_pImgList != NULL)
::ImageList_GetIconSize(*(pmd->m_pImgList), &cx, &cy);
CFont m_fontMenu;
LOGFONT m_lf;
ZeroMemory ((PVOID) &m_lf,sizeof (LOGFONT));
NONCLIENTMETRICS nm;
nm.cbSize = sizeof (NONCLIENTMETRICS);
VERIFY(SystemParametersInfo(SPI_GETNONCLIENTMETRICS,
nm.cbSize,&nm,0));
m_lf = nm.lfMenuFont;
m_fontMenu.CreateFontIndirect (&m_lf);
// Obtain the width of the text:
CWnd *pWnd = AfxGetMainWnd(); // Get main window
CDC *pDC = pWnd->GetDC(); // Get device context
CFont* pFont=NULL; // Select menu font in...
pFont = pDC->SelectObject (&m_fontMenu);// Select menu font in...
//Get pointer to text SK
const char *lpstrText = pmd->m_szMenuText;//SK: we use const to prevent misuse
SIZE size={0,0};
if(lpstrText!=NULL)
::GetTextExtentPoint32(pDC->m_hDC,lpstrText,
strlen(lpstrText),&size);
CSize t = CSize(size);
pDC->SelectObject (pFont); // Select old font in
AfxGetMainWnd()->ReleaseDC(pDC); // Release the DC
// Set width and height:
lpMIS->itemWidth = cx + t.cx + cx + GAP;
int temp = t.cy+4;
if (lpMIS->itemID)//if(pmd->m_pImgList)
lpMIS->itemHeight = temp>cy+4 ? temp : cy+4;
else
lpMIS->itemHeight = 5;
m_fontMenu.DeleteObject();
}catch(...){}
}
BOOL DestroyMenuItemData(HMENU hMenu,int nPos, BOOL bPos)
{
if(hMenu==NULL)
return FALSE;
if(!IsMenu(hMenu))
return FALSE;
try{
MENUITEMINFO mii;
mii.fMask = MIIM_DATA|MIIM_TYPE; // get the state of the menu item
mii.dwTypeData = NULL;
mii.cch = 0;
mii.dwItemData = NULL;
mii.cbSize = sizeof(mii);
::GetMenuItemInfo(hMenu, nPos, bPos, &mii);
CMenuData* pmd = (CMenuData*)(mii.dwItemData);
if(mii.fType & MFT_OWNERDRAW && pmd!=NULL)
{
if(pmd->m_szMenuText != NULL)
{
delete[] pmd->m_szMenuText;
pmd->m_szMenuText = NULL;
}
if(pmd->m_szURL != NULL)
{
delete[] pmd->m_szURL;
pmd->m_szURL = NULL;
}
delete pmd;
mii.dwItemData = NULL;
mii.fMask = MIIM_DATA;
mii.cbSize = sizeof(mii);
::SetMenuItemInfo(hMenu, nPos, bPos, &mii);
}
}catch(...){}
return true;
}
BOOL DestroyMenuData(HMENU hMenu,int nStart)
{
if(hMenu==NULL)
return FALSE;
if(!IsMenu(hMenu))
return FALSE;
try{
int iCount;
MENUITEMINFO mii;
CMenuData* pmd;
for(iCount=0; iCount<::GetMenuItemCount(hMenu);iCount++)
{
mii.fMask = MIIM_DATA|MIIM_TYPE; // get the state of the menu item
mii.dwTypeData = NULL;
mii.cch = 0;
mii.dwItemData = NULL;
mii.cbSize = sizeof(mii);
::GetMenuItemInfo(hMenu, iCount, TRUE, &mii);
pmd = (CMenuData*)(mii.dwItemData);
if(mii.fType & MFT_OWNERDRAW && pmd!=NULL && iCount>=nStart)
{
if(pmd->m_szMenuText != NULL)
{
delete[] pmd->m_szMenuText;
pmd->m_szMenuText = NULL;
}
if(pmd->m_szURL != NULL)
{
delete[] pmd->m_szURL;
pmd->m_szURL = NULL;
}
delete pmd;
mii.dwItemData = NULL;
mii.fMask = MIIM_DATA;
mii.cbSize = sizeof(mii);
::SetMenuItemInfo(hMenu, iCount, TRUE, &mii);
//
HMENU hSubMenu = ::GetSubMenu(hMenu, iCount);
if(IsMenu(hSubMenu))
{
DestroyMenuData(hSubMenu,0);
}
}
}
}catch(...){}
return true;
}
BOOL DestroySubMenu(HMENU hMenu,HMENU hSubMenu)
{
if(hMenu==NULL)
return FALSE;
if(!IsMenu(hMenu))
return FALSE;
try{
int iCount,nItemCount;
MENUITEMINFO mii;
CMenuData* pmd;
nItemCount = ::GetMenuItemCount(hMenu);
for(iCount=0; iCount<nItemCount;iCount++)
{
mii.fMask = MIIM_DATA|MIIM_TYPE|MIIM_SUBMENU; // get the state of the menu item
mii.dwTypeData = NULL;
mii.cch = 0;
mii.dwItemData = NULL;
mii.cbSize = sizeof(mii);
::GetMenuItemInfo(hMenu, iCount, TRUE, &mii);
pmd = (CMenuData*)(mii.dwItemData);
if(mii.fType&MFT_OWNERDRAW && pmd && mii.hSubMenu)
{
if (mii.hSubMenu==hSubMenu)
{
//delete sub menu
DestroyMenuData(hSubMenu,0);
while(::DeleteMenu(hSubMenu,0, MF_BYPOSITION));
//
if(pmd->m_szMenuText != NULL)
{
delete[] pmd->m_szMenuText;
pmd->m_szMenuText = NULL;
}
if(pmd->m_szURL != NULL)
{
delete[] pmd->m_szURL;
pmd->m_szURL = NULL;
}
delete pmd;
mii.dwItemData = NULL;
mii.fMask = MIIM_DATA;
mii.cbSize = sizeof(mii);
::SetMenuItemInfo(hMenu, iCount, TRUE, &mii);
//!! delete menu item
DeleteMenu(hMenu, iCount, MF_BYPOSITION);
}
else
{
DestroySubMenu(mii.hSubMenu,hSubMenu);
}
}
}
}catch(...){}
return true;
}
BOOL CToolMenu::DestroyMenu()
{
DestroyMenuData(m_hMenu,0);
return CMenu::DestroyMenu();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -