Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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:
C#
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:

C#
    // 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.
Posted

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.
 
Share this answer
 
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
C++
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!
 
Share this answer
 
Comments
CHill60 19-Mar-15 5:34am    
Please don't post comments or further questions as solutions to old posts.
If you have a question of your own then it is better to use the "Ask a Question" link. More members will look at an unanswered question that one that is already resolved.
You can always include links back to this post in your question - in fact it would be a good idea as someone may just refer back here as a solution.
DavidCarr 20-Mar-15 16:35pm    
In terms of searching for issues and existing solutions, my first and foremost tool is to Google. That being said, to solicit input and ideas I can appreciate what you are saying, especially from the experts monitoring new posts directly within the forum. Thanks for the tips.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900