OnButtonup and onbuttondown

Posted on 2004-10-24
Last Modified: 2013-11-20
Hi, could anyone provide me some sample codes on how to do a seperate control for onbuttoup and for onbuttondown please?
I know OnLButtonDown and OnLButtonUp is needed , but i do not know how to use it. Could anyone teach me how to do it please?
Question by:mwcmp
    LVL 12

    Accepted Solution


    add two message handlers WM_LBUTTONDOWN  and WM_LBUTTONUP
    when left mouse button is down, OnLButtonDown is being called.
    LVL 6

    Assisted Solution

    by:Amritpal Singh
    have a look at the sample at the following link
    LVL 2

    Assisted Solution

    As OnegaZhang points out you need WM_LBUTTONDOWN and WM_LBUTTONUP messages.

    You can use the class wizard to add messages to the message map, or you can add them manually. Right click the class in the project tree to use wizard. The messagemap entries for button up/down look like this in my CMapView class (a CView descendant)


    Your class member function looks like this

    afx_msg void OnLButtonDown( UINT nFlags, CPoint point );
    afx_msg void OnLButtonUp( UINT nFlags, CPoint point );

    The "nFlags" are typically used to identify if control of shift is down. The "point" is the mouse position when clicked. Press F1 in the source window with the cursor on the "ON_WM_LBUTTONDOWN()", and you will find the info you need.

    Good luck

    Author Comment

    ah...i'm sorry...i forgot to add that i need the onbuttonup and onbuttondown to be implemented on a Cbutton. WM_LBUTTONDOWN  only works for the whole MFC but not on the button...
    LVL 2

    Expert Comment

    Is the button placed in your own dialog, created in the resource editor maybe?

    Author Comment

    it's placed in my own dialog , created using the class wizard
    LVL 1

    Assisted Solution

        If you wnat to implement onbuttonup and onbuttondown to be implemented on a Cbutton.
    Derive a class from CButton and handle these messages (onbuttonup and onbuttondown )there and create the Button object with the derive class. If you don't want to derive it then override WindowProc and when WM_LBUTTONDOWN()  WM_LBUTTONUP() are encountered then check the window handle with the button handle, if they equal then user has clicken on the button.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Prepare to Pass the CompTIA A+ 900 Series Exam

    CompTIA aims to adapt its A+ Certification to reflect the most current knowledge and skills needed by today's IT professionals--and this year's 2016 exam is harder than ever. This certification is one of the most highly-respected and sought after in IT.

    Suggested Solutions

    Title # Comments Views Activity
    Problem with rc form 45 118
    Problem to DLL 9 67
    mixString challenge 36 86
    Macro to save highlighted rows as a separate file 5 30
    Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
    If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now