CMFCButtons - 有没有人真正使用这些? [英] CMFCButtons - does anyone really use these?

查看:145
本文介绍了CMFCButtons - 有没有人真正使用这些?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾尝试使用CMFCButton,因为当鼠标悬停在工具提示和热位图时,它们内置了对工具提示和热位图的支持,但它们似乎没有任何工具可以显示按下(即选定的)位图 - 也就是说,你需要将它们视为所有者绘制并添加:

 ON_WM_DRAWITEM()
...
void CMyClass :: OnDrawItem( int nIDCtl,LPDRAWITEMSTRUCT lpDrawItemStruct)
{
etc ...





除非上面启用OnDrawItem(),否则鼠标悬停时不再显示热位图,以下内容如下与CButton一起使用的OnDrawItem()中的代码不再适用于CMFCButton:



  //  永远不会设置ODS_SELECTED  
int s =(lpDrawItemStruct-> ; itemState& ODS_SELECTED);





总而言之,对于所有者抽奖,我无法以传统方式捕获左键(ODS_SELECTED是设置)为了绘制按下的位图,我也不能得到鼠标悬停的热位图。



任何人都有任何想法?截至目前,CMFCButton似乎是从CButton向后退一步。

解决方案

这些类比原始类更复杂,这是肯定的。



我通过阅读按钮的源代码并确保在我将它们子类化之后发生相同的调用来克服这些问题。



我这样做的方法是观察使用Spy ++的Microsoft版本的行为,并确保我的课程表现相同。



在许多情况下,我已经从库中取出代码并将其提升到我的类,修改了编译错误并自定义行为。



这是一种常见的方式修改MFC派生类中的行为。


我有类似的动机使用它们(图像和工具提示支持了),但也希望显示已检查或已按下州。似乎使用基类方法

 CButton :: SetCheck(BST_CHECKED); 

并不会像使用它时那样使其显示为按下一个常规的CButton。



虽然我很欣赏杰克的建议 - 当然20年的MFC编程我已经看到了修复真正的错误的必要性 - 从代码维护和有限的预算,在这个项目上是不可行的。



关于此的任何决议或想法?凸块!


I have tried to use CMFCButton's because they have built-in support for tooltips and hot bitmaps when you mouse over them, but they don't seem to have any facility to display the "pressed" (i.e. selected) bitmap - which is to say, you need to treat them as owner-draw and add:

ON_WM_DRAWITEM()
    ...
    void CMyClass::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
        etc...



Except that when you enable OnDrawItem() as above, the hot bitmap no longer displays on mouse over, and the following code in OnDrawItem(), which works with CButton, no longer works with CMFCButton:

    // ODS_SELECTED is never set
int s = (lpDrawItemStruct->itemState & ODS_SELECTED);



So in summary, with owner-draw, I cannot capture a left button down in the traditional way (ODS_SELECTED is set) in order to draw the "pressed" bitmap, nor can I get mouse-over hot bitmap.

Anyone got any ideas? As of right now, CMFCButton seems like a step backwards from CButton.

解决方案

These classes are more complex than the originals, that's for sure.

I've conquered issues like these by reading the source code for the button and making sure that same calls occur after I subclass them.

The way I did this is by watching the behavior for the Microsoft version using Spy++ and making sure that my class behaved the same way.

In many cases, I've taken code right out of the library and promoted it to my class, with changes made to fix compile errors and customize behavior.

This is a common way to modify behavior in MFC derived classes.


I have a similar motivation for using them (image and tooltip support out of the can), but also want to show a 'checked' or 'pressed' state. It seems that using the base class method

CButton::SetCheck(BST_CHECKED);

does not make it appear pressed like it would if using a regular CButton.

While I appreciate Jack's suggestion - certainly 20 years of MFC programming I've seen the need to do that to fix real bugs - from the perspective of code maintenance and limited budgets, it isn't feasible on this project.

Any resolution or ideas on this? Bump!


这篇关于CMFCButtons - 有没有人真正使用这些?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆