📄 csdn_文档中心_vc++的菜单控制和自绘菜单。.htm
字号:
CDC::FromHandle(lpDIS->hDC);<BR> CRect
rect;<BR> HICON
hIcon;<BR> COLORREF crText =
m_crText;<BR> // draw the colored rectangle
portion<BR> rect.CopyRect(&lpDIS->rcItem);<BR><BR> //
draw the up/down/focused/disabled
state<BR><BR> UINT action =
lpDIS->itemAction;<BR> UINT state =
lpDIS->itemState;<BR> CString
strText;<BR> LOGFONT
lf;<BR> lf =
m_lf;<BR><BR> CFont
dispFont;<BR> CFont
*pFont;<BR> //GetWindowText(strText);<BR> if
(lpDIS->itemData !=
NULL)<BR> {<BR> strText
= (((MENUDATA*)
(lpDIS->itemData))->menuText);<BR> if
((((MENUDATA *)(lpDIS->itemData))->menuIconNormal) ==
-1)<BR> hIcon
= NULL;<BR> else if
(state &
ODS_SELECTED)<BR> {<BR> if
((((MENUDATA *)(lpDIS->itemData))->menuIconSelected) !=
-1)<BR> hIcon
= AfxGetApp ()->LoadIcon (((MENUDATA
*)(lpDIS->itemData))->menuIconSelected);<BR> else<BR> hIcon
= AfxGetApp()->LoadIcon
(((MENUDATA*)(lpDIS->itemData))->menuIconNormal);<BR> }<BR> else<BR> hIcon
= AfxGetApp()->LoadIcon
(((MENUDATA*)(lpDIS->itemData))->menuIconNormal);<BR><BR> TRACE1
("Draw for %s\n",
strText);<BR> }<BR> else<BR> {<BR> strText.Empty();<BR> hIcon
=
NULL;<BR> }<BR><BR> if
( (state & ODS_SELECTED)
)<BR> {<BR> //
draw the down
edges<BR><BR> CPen
*pOldPen = pDC->SelectObject
(&m_penBack);<BR><BR> //You
need only Text highlight and thats what you
get<BR> if
(m_hilightStyle !=
Normal)<BR> {<BR> pDC->FillRect
(rect,&m_brBackground);<BR> }<BR> else<BR> {<BR> pDC->FillRect
(rect,&m_brSelect);<BR> }<BR><BR> pDC->SelectObject
(pOldPen);<BR> pDC->Draw3dRect
(rect,GetSysColor
(COLOR_3DHILIGHT),GetSysColor(COLOR_3DSHADOW));<BR> lf.lfWeight
= FW_BOLD;<BR> if
((HFONT)dispFont !=
NULL)<BR> dispFont.DeleteObject
();<BR> dispFont.CreateFontIndirect
(&lf);<BR> crText
=
m_clrHilightText;<BR><BR> //While
selected move the text a
bit<BR> TRACE0
("SELECT,SELECTED\n");<BR> }<BR> else<BR> {<BR> CPen
*pOldPen = pDC->SelectObject
(&m_penBack);<BR> pDC->FillRect
(rect,&m_brBackground);<BR> pDC->SelectObject
(pOldPen);<BR> //
draw the up
edges<BR> pDC->Draw3dRect
(rect,m_clrBack,m_clrBack);<BR> if
((HFONT)dispFont !=
NULL)<BR> dispFont.DeleteObject
();<BR> dispFont.CreateFontIndirect
(&lf);
//Normal<BR><BR> TRACE0
("SELECT,
NORMAL\n");<BR> }<BR><BR> //
draw the text if there is any<BR> //We have
to paint the text only if the image is
nonexistant<BR> if (hIcon !=
NULL)<BR> {<BR> if(DrawIconEx
(pDC->GetSafeHdc(),rect.left,rect.top,hIcon,<BR> (m_iconX)?m_iconX:32,(m_iconY)?m_iconY:32,0,NULL,DI_NORMAL))<BR> TRACE0("Wrote
the icon
successfully\n");<BR> else<BR> TRACE0
("SORRY.NOGO\n");<BR> }<BR> //This
is needed always so that we can have the space for check
marks<BR> rect.left = rect.left
+((m_iconX)?m_iconX:32);<BR><BR> if (
!strText.IsEmpty())<BR> {<BR> //
pFont->GetLogFont
(&lf);<BR><BR> int
iOldMode =
pDC->GetBkMode();<BR><BR> pDC->SetBkMode(
TRANSPARENT);<BR><BR> pDC->SetTextColor(
crText);<BR><BR> pFont
= pDC->SelectObject
(&dispFont);<BR> TRACE1(
"About To DrawText
%s\n",strText);<BR> pDC->DrawText
(strText,rect,DT_LEFT|DT_SINGLELINE|DT_VCENTER);<BR> TRACE0("Done\n");<BR> pDC->SetBkMode(
iOldMode
);<BR> pDC->SelectObject
(pFont); //set it to the old
font<BR> }<BR> dispFont.DeleteObject
();<BR>}<BR><BR>void CCustomMenu::MeasureItem( LPMEASUREITEMSTRUCT
lpMIS )<BR>{<BR> CDC *pDC =
AfxGetApp()->m_pMainWnd->GetDC();<BR> CFont*
pFont = pDC->SelectObject
(&m_fontMenu);<BR> int iconX = 0,iconY=
0;<BR> TEXTMETRIC
tm;<BR> pDC->GetTextMetrics
(&tm);<BR> pDC->SelectObject
(pFont);<BR> AfxGetApp()->m_pMainWnd->ReleaseDC
(pDC);<BR><BR> if
(m_iconX)<BR> iconX =
m_iconX;<BR> if
(m_iconY)<BR> iconY =
m_iconY;<BR><BR> lpMIS->itemWidth = iconX
+ tm.tmAveCharWidth *
lstrlen(((MENUDATA*)(lpMIS->itemData))->menuText)
+10;<BR> lpMIS->itemHeight = (iconY >
(m_iMenuHeight+1))?iconY:m_iMenuHeight + 1;<BR>}<BR><BR>void
CCustomMenu::SetIconSize (int width, int
height)<BR>{<BR> m_iconX =
width;<BR> m_iconY = height;<BR>}<BR><BR>void
CCustomMenu::SetTextColor (COLORREF
clrText)<BR>{<BR> m_crText =
clrText;<BR>}<BR><BR>void CCustomMenu::SetBackColor (COLORREF
clrBack)<BR>{<BR> m_clrBack =
clrBack;<BR> if ((HBRUSH)m_brBackground !=
NULL)<BR> m_brBackground.DeleteObject
();<BR> m_brBackground.CreateSolidBrush
(clrBack);<BR>}<BR><BR>void CCustomMenu::SetHighlightColor (COLORREF
clrHilight)<BR>{<BR> m_clrHilight =
clrHilight;<BR> if ((HBRUSH)m_brSelect !=
NULL)<BR> m_brSelect.DeleteObject
();<BR> m_brSelect.CreateSolidBrush
(clrHilight);<BR>}<BR><BR>void CCustomMenu::SetHighlightTextColor
(COLORREF
clrHilightText)<BR>{<BR> m_clrHilightText =
clrHilightText;<BR>}<BR><BR><BR>void CCustomMenu::SetHighlightStyle
(HIGHLIGHTSTYLE
hilightStyle)<BR>{<BR> m_hilightStyle =
hilightStyle;<BR>}<BR><BR></FONT><BR></TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE><BR>
<TABLE align=center bgColor=#006699 border=0 cellPadding=0 cellSpacing=0
width=770>
<TBODY>
<TR bgColor=#006699>
<TD align=middle bgColor=#006699 id=white><FONT
color=#ffffff>对该文的评论</FONT></TD>
<TD align=middle>
<SCRIPT src="CSDN_文档中心_VC++的菜单控制和自绘菜单。.files/readnum.htm"></SCRIPT>
</TD></TR></TBODY></TABLE><BR>
<DIV align=center>
<TABLE align=center bgColor=#cccccc border=0 cellPadding=2 cellSpacing=1
width=770>
<TBODY>
<TR>
<TH bgColor=#006699 id=white><FONT
color=#ffffff>我要评论</FONT></TH></TR></TBODY></TABLE></DIV>
<DIV align=center>
<TABLE border=0 width=770>
<TBODY>
<TR>
<TD>你没有登陆,无法发表评论。 请先<A
href="http://www.csdn.net/member/login.asp?from=/Develop/read_article.asp?id=2239">登陆</A>
<A
href="http://www.csdn.net/expert/zc.asp">我要注册</A><BR></TD></TR></TBODY></TABLE></DIV><BR>
<HR noShade SIZE=1 width=770>
<TABLE border=0 cellPadding=0 cellSpacing=0 width=500>
<TBODY>
<TR align=middle>
<TD height=10 vAlign=bottom><A
href="http://www.csdn.net/intro/intro.asp?id=2">网站简介</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=5">广告服务</A> - <A
href="http://www.csdn.net/map/map.shtm">网站地图</A> - <A
href="http://www.csdn.net/help/help.asp">帮助信息</A> - <A
href="http://www.csdn.net/intro/intro.asp?id=2">联系方式</A> - <A
href="http://www.csdn.net/english">English</A> </TD>
<TD align=middle rowSpan=3><A
href="http://www.hd315.gov.cn/beian/view.asp?bianhao=010202001032100010"><IMG
border=0 height=48 src="CSDN_文档中心_VC++的菜单控制和自绘菜单。.files/biaoshi.gif"
width=40></A></TD></TR>
<TR align=middle>
<TD vAlign=top>百联美达美公司 版权所有 京ICP证020026号</TD></TR>
<TR align=middle>
<TD vAlign=top><FONT face=Verdana>Copyright © CSDN.net, Inc. All rights
reserved</FONT></TD></TR>
<TR>
<TD height=15></TD>
<TD></TD></TR></TBODY></TABLE></DIV>
<DIV></DIV><!--内容结束//--><!--结束//--></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -