Board index » cppbuilder » MouseEnter/MouseLeave on ToolButtons

MouseEnter/MouseLeave on ToolButtons

I have subclassed TToolButton and want to customize the appearance of
the button. Thus I need to know in the Paint method, if the mouse cursor

is over the button or not. I read the articles about CM_MOUSEENTER and
CM_MOUSELEAVE but this seems rather complicated and I'm not sure if
this is possible at all in an non-windowed control like TToolButton.
I don't want to use the TToolBar->HotImageList because I want to change
all buttons in a similar way an I have lots of buttons.

Isn't there any property like ControlState or Down or Marked ... to
determine if the mouse cursor points on the button? I mean, apparently
the default Paint method does already know the current state.

Thanks,
Hartmut

 

Re:MouseEnter/MouseLeave on ToolButtons


Hi Hartmut,

Quote
> I have subclassed TToolButton and want to customize the appearance of
> the button. Thus I need to know in the Paint method, if the mouse cursor
> is over the button or not. I read the articles about CM_MOUSEENTER and
> CM_MOUSELEAVE but this seems rather complicated and I'm not sure if
> this is possible at all in an non-windowed control like TToolButton.

Those message do work for all TControl descendant classes.  However, you may be
better off using the TBN_HOTITEMCHANGE notification message.  This message is
sent to the ToolBar, in the form of a WM_NOTIFY message, which [if needed] you
must relay to the tool buttons.  If you plan on handling this notification
message in a derived TToolBar class, use the CN_NOTIFY version of the WM_NOTIFY
message.  For example...

class TMyToolBar :  public TToolBar
{
private:
    MESSAGE void __fastcall CNNotify(TMessage& AMsg)
    {
        LPNMHDR lpnmh = reinterpret_cast<LPNMHDR>(AMsg.LParam);
        if (lpnmh->code == TBN_HOTITEMCHANGE)
        {
            // hot button has changed -- notify button(s)...
        }
        TToolBar::Dispatch(&AMsg);
    }

public:
    __fastcall TMyToolBar(TComponent* AOwner) : TToolBar(AOwner) {};

BEGIN_MESSAGE_MAP
    MESSAGE_HANDLER(CN_NOTIFY, TMessage, CNNotify)
END_MESSAGE_MAP(TToolBar)

Quote
};

Good luck!

--
Damon Chandler (TeamB)
http://bcbcaq.freeservers.com

Re:MouseEnter/MouseLeave on ToolButtons


Thanks for the detailed information. In the meantime I found the event
TToolBar->OnCustomDrawButton which also passes the state cbsHot.

Hartmut

Other Threads