首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OwnerDraw CButton mfc焦点

OwnerDraw CButton mfc焦点
EN

Stack Overflow用户
提问于 2015-06-24 08:25:58
回答 1查看 2.5K关注 0票数 0

对于标准按钮,如果我有OK和Cancel,默认情况下在OK和我按右箭头取消焦点和按回车键盘上的取消按钮功能被调用。

这种情况不会发生在主绘制按钮上。如果我按右箭头,取消按钮是聚焦的,但按下键盘上的回车,就会调用OK按钮函数。

我怎么能有一个拥有标准行为的所有者绘图按钮?

这是我的课。

代码语言:javascript
复制
BEGIN_MESSAGE_MAP(CFlatButton, CButton)
    //{{AFX_MSG_MAP(CMyClass)
        // NOTE - the ClassWizard will add and remove mapping macros here.
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

void CFlatButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
    // TODO: Add your code to draw the specified item
    CDC dc;
    dc.Attach(lpDrawItemStruct->hDC);       //Get device context object
    CRect rt;
    rt = lpDrawItemStruct->rcItem;      //Get button rect

    UINT state = lpDrawItemStruct->itemState;   //Get state of the button
    if ( (state & ODS_SELECTED) )
        dc.FillSolidRect(rt, RGB(255, 0, 0));
    else
    {
        if ((state & ODS_DISABLED))
        {
            dc.FillSolidRect(rt, RGB(0, 255, 0));
        }
        else
        {
            if ((state & ODS_FOCUS))       // If the button is focused
            {
                // Draw a focus rect which indicates the user 
                // that the button is focused
                dc.FillSolidRect(rt, RGB(0, 0, 255));
            }
            else
            {
                dc.FillSolidRect(rt, RGB(255, 255, 0));
            }
        }
    }
    dc.SetTextColor(RGB(255,255,255));      // Set the color of the caption to be yellow
    CString strTemp;
    GetWindowText(strTemp);     // Get the caption which have been set
    dc.DrawText(strTemp,rt,DT_CENTER|DT_VCENTER|DT_SINGLELINE);     // Draw out the caption


    dc.Detach();
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-24 10:51:33

主要原因是,对话框通常使用BS_DEFPUSHBUTTON和BS_PUSHBUTTON来表示这一点,但所有者绘图标志与此是相互排斥的。

查看本文:它解释了完整的背景:http://www.codeproject.com/Articles/1318/COddButton

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31021442

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档