Results 1 to 5 of 5

Thread: MouseOver

  1. #1

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125

    MouseOver

    Let me just say this first. I am not very good with C++.

    Ok, here's what I want to do. I want a label on my form (I am using MFC) to change when the mouse moves over each button on my form. Kinda like a tooltip, but in a static place. I know how to change text in a label, but I don't know how to put code in a mouseover or mousemove event. Can anyone tell me how to do this?

    Thanks for any help.
    <removed by admin>

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Subclass the buttons and catch the WM_MOUSEMOVE message. Subclassing in MFC is quite confusing, you might want to use the traditional way.

    If you don't understand what I said you need to learn more about the basics of windows programming.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    PowerPoster MidgetsBro's Avatar
    Join Date
    Oct 2000
    Location
    Apparently, Internet.com
    Posts
    3,125
    I understand what you said, I just don't know how to do it. You have to subclass for something as simple as a mouse over? I think I'll just stick to VB and say f**k you to the people that don't have the VB runtimes. hehe.
    <removed by admin>

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Look, the button area belongs to the button, not to the parent window. Therefore only the button can catch the mousemove messages.
    The reason why VB can have a mouseover event might be either that it subclasses the button itself or (more likely) that even simple buttons in VB are evil slow ActiveX controls that notify the parent of such useless things.

    It's really not hard to subclass something.
    Here's untested code to subclass a button in MFC. Just put it somewhere into your class that represents the parent of the button
    Code:
    SubclassWindow(ctlButton.GetSafeHwnd());
    But if you already use CButton to create the button there is a better (more MFC-style) way: derive a class.
    Code:
    class CMyButt : public CButton
    {
      DECLARE_DYNAMIC(CMyButt);
      DECLARE_MESSAGE_MAP();
    
    public:
      afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    };
    
    IMPLEMENT_DYNAMIC(CMyButt, CButton);
    
    BEGIN_MESSAGE_MAP(CMyButt, CButton)
      ON_WM_MOUSEMOVE()
    END_MESSAGE_MAP()
    
    // code for OnMouseMove
    Then in your container do
    CMyButt m_ctlButt;
    instead of
    CButton m_ctlButt;
    and you're all settled.

    In case it's a dialog you can't do that of course. In this case you use the DDX mechanism:
    Code:
    class CMyDialog : public CDialog {
    // bla bla bla, lot's of wizard code
      CMyButt m_ctlButt;
    };
    
    // Add this line to the DoDataExchange function:
    DDX_Control(pDX, IDC_OFYOURBUTT, m_ctlButt);
    It's damn easy once you know how.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5
    Member
    Join Date
    Oct 2002
    Location
    Look out your window.
    Posts
    54
    Why not just use a CToolTipCtrl?

    Code:
    // Add a member variable for the tooltip control.
    class ParentWnd
    {
        ...
        CToolTipCtrl tooltip;
    }
    
    // Do this in OnCreate().
    tooltip.Create(pParentWnd, IDC_SOMEID, TTS_NOPREFIX);
    
    // Do this in OnInitDialog() or something close.
    tooltip.AddTool(GetDlgItem(IDC_A_BUTTON), TEXT("It's a button."));
    tooltip.AddTool(GetDlgItem(IDC_A_BUTTON2), TEXT("It's a button2."));
    
    // Do this in a OnMouseMove() for the parent not each individual button.
    LPMSG pMsg = ::GetCurrentMessage();
    tooltip.RelayEvent(pMsg);

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width