BUTTON按钮怎么不见了?

zoulie 2005-12-25 12:08:10
我在属性的Styles中的Owner_draw选中,然后运行按钮怎么就不见了?怎么回事?
...全文
375 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
chinanb 2005-12-26
  • 打赏
  • 举报
回复
改以下STYL属性,就可以加按钮颜色
r_s 2005-12-26
  • 打赏
  • 举报
回复
mark
ningxuelengyue 2005-12-25
  • 打赏
  • 举报
回复
能不能说详细点,把代码贴上来看看
菜牛 2005-12-25
  • 打赏
  • 举报
回复
if(m_flag==1)
{
}
else
{
}
就是说在你鼠标按下之前也要绘制一个按钮的东西。
zoulie 2005-12-25
  • 打赏
  • 举报
回复
搞了半夜,总算搞定了,谢楼上几位..
zoulie 2005-12-25
  • 打赏
  • 举报
回复
一定要重载DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)才能运行时也显示出来,我加的代码如下.Mackz(在相互)所说的,我分给完了,不好意思啊,下次再给 :-)

void CColorBtn::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item
if(m_flag==1) //显示红色的文本
{
UINT uStyle=DFCS_BUTTONPUSH;
ASSERT(lpDrawItemStruct->CtlType==ODT_BUTTON);
if(lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |=DFCS_PUSHED;
::DrawFrameControl(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,
DFC_BUTTON,uStyle);
CString strText;
GetWindowText(strText);
COLORREF crOldColor= ::SetTextColor(lpDrawItemStruct->hDC,RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC,strText,strText.GetLength(),
&lpDrawItemStruct->rcItem,DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC,crOldColor);
}

else //默认显示色
{
UINT uStyle=DFCS_BUTTONPUSH ;
ASSERT(lpDrawItemStruct->CtlType==ODT_BUTTON);
if(lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |=DFCS_PUSHED;
::DrawFrameControl(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,
DFC_BUTTON,uStyle);
CString strText;
GetWindowText(strText);
COLORREF crOldColor= ::SetTextColor(lpDrawItemStruct->hDC,RGB(0,0,0));
::DrawText(lpDrawItemStruct->hDC,strText,strText.GetLength(),
&lpDrawItemStruct->rcItem,DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC,crOldColor);
}

}
femalelover 2005-12-25
  • 打赏
  • 举报
回复
说说看怎么解决的.
femalelover 2005-12-25
  • 打赏
  • 举报
回复
先别结呀,我也遇到这个问题,在Debug下运行出错,但Release下可以运行,却不显示出来.也是OwnerDraw属性的问题.
hj008 2005-12-25
  • 打赏
  • 举报
回复
你把MSDN的代码,关于BUTTON的DrowItem里的范例COPY过来,跟你的对对就知道了.
zoulie 2005-12-25
  • 打赏
  • 举报
回复
代码如下:

void CCOLORBTN::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
// TODO: Add your code to draw the specified item

if(m_flag==1)
{
UINT uStyle=DFCS_PUSHED;
ASSERT(lpDrawItemStruct->CtlType==ODT_BUTTON);
if(lpDrawItemStruct->itemState & ODS_SELECTED)
uStyle |=DFCS_PUSHED;
::DrawFrameControl(lpDrawItemStruct->hDC,&lpDrawItemStruct->rcItem,
DFC_BUTTON,uStyle);
CString strText;
GetWindowText(strText);
COLORREF crOldColor= ::SetTextColor(lpDrawItemStruct->hDC,RGB(255,0,0));
::DrawText(lpDrawItemStruct->hDC,strText,strText.GetLength(),
&lpDrawItemStruct->rcItem,DT_SINGLELINE|DT_VCENTER|DT_CENTER);
::SetTextColor(lpDrawItemStruct->hDC,crOldColor);
}

}

void CCOLORBTN::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_flag=1;
CButton::OnLButtonDown(nFlags, point);
}
zoulie 2005-12-25
  • 打赏
  • 举报
回复
我的意思是让按钮被点击后改变字体的颜色,但是加了Owner_draw属性后不点击它又看不见,
zoulie 2005-12-25
  • 打赏
  • 举报
回复
结帖
wshcdr 2005-12-25
  • 打赏
  • 举报
回复
选择了Owner_draw属性,必须自己去画这个按纽
去看MSDN中 WM_DRAWITEM
LordSimon 2005-12-25
  • 打赏
  • 举报
回复
owner-drawn button
A button with the style BS_OWNERDRAW. Unlike all other button types, an owner-drawn button has no predefined appearance or behavior. Also, the application, not the system, is responsible for painting it.
很简单,不用在下翻译了吧,呵呵
LordSimon 2005-12-25
  • 打赏
  • 举报
回复
owner-drawn control
A predefined control that sends messages to its parent window when it must be drawn.

16,471

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Web++
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧