Owner Draw CButton Not Relinquishing Press State

I've created an owner-drawn CButton class to do custom painting including a hover state. I've added tooltip functionality as well. Everything works correctly, except if I select the button with the left mouse, then before releasing the left mouse, I move the cursor off the button. I would expect the button to unselect, similar to standard windows buttons. When I release the left mouse, the button selects no matter where the cursor is located on the screen (it can even be over a different application).

In my code, I'm checking the LPDRAWITEMSTRUCT object for disabled, selected, and focus states to paint the correct button state. Additionally, I maintain a m_bHovering bool to tell me when I'm hovering over a button. All states work correctly, and the button paints exactly how I want it to.

My problem is what I mentioned above, I can't get the button to "disengage" once it has been selected with the mouse. Once it has received the left mouse down message, that button is going to get selected eventually (once the left button is released), even if I don't want it to.

It doesn't seem like a painting issue to me. Functionally, I add the BS_OWNERDRAW style in PreCreateWindow(). In OnCreate() I create the tooltip control and create some fonts. I do handle OnKeyDown(), and it sends a message to it's parent. Otherwise, the remainder of the code does tooltip stuff, and painting stuff.

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I suggest using Spy++ to examine the sequence of messages that normally occur (on a standard button) when you click-and-hold then drag off of the button and release. Then I'd do the same thing for these special buttons, and compare the message logs to see what's different.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.