OwnerDraw C按钮mfc焦点
OwnerDraw CButton mfc focus
使用标准按钮,如果我有"确定"answers"取消",默认情况下为"确定",然后我按下右箭头,"取消"将聚焦,并按键盘上的enter键,则调用"取消"按钮功能。
ownerdraw按钮不会发生这种情况。如果我按下向右箭头,取消按钮会聚焦,但按下键盘上的回车键,则会调用OK按钮功能。
我怎样才能拥有一个行为规范的ownerdraw按钮?
这是我的课。
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();
}
主要原因是对话框通常使用BS_DEFPUSHBUTTON和BS_PUSHBUTON来表示这一点,但ownerdraw标志与此互斥。
查看这篇文章:它解释了完整的背景:http://www.codeproject.com/Articles/1318/COddButton
相关文章:
- C++ MFC Libraries in Travis CI
- 从 bmp 文件数据创建 MFC CBitmap
- 如何在 MFC 中显示文件的所有行
- 目录删除 MFC 的问题
- 有没有办法区分Qt小部件是通过鼠标单击还是通过按表键获得焦点?
- MFC:如何设置CEdit框的焦点?
- MFC 中的抗锯齿
- 双击更改 mfc 中列表控件中的行的颜色
- C++MFC编辑框处理双击
- C++ MFC CObject 派生类摘要?
- 如何在 MFC 对话框中使用 OnDraw
- MFC) 使 TreeCtrl 失去其项目焦点
- MFC 结束对话框崩溃时模式对话框没有焦点
- 将焦点设置在MFC视图中托管的无模式对话框上
- 启动时C++ MFC 软件请求焦点(在任务栏中闪烁)
- MFC:如何在一个函数中捕获对话框的每个控件的设置焦点
- MFC 对话框在失去焦点时冻结
- MFC:当将焦点设置为子窗口时,如何防止应用程序成为前景窗口
- ListView在mfc中杀死焦点
- OwnerDraw C按钮mfc焦点