OnButtonup and onbuttondown

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?
Who is Participating?
I wear a lot of hats...

"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.


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

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.

Start your 7-day free trial
Amritpal SinghCommented:
have a look at the sample at the following link

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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

mwcmpAuthor Commented:
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...
Is the button placed in your own dialog, created in the resource editor maybe?
mwcmpAuthor Commented:
it's placed in my own dialog , created using the class wizard
Surya BobbadhiTechnical ConsultantCommented:
    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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.