• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 841
  • Last Modified:

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?
Thanks
0
mwcmp
Asked:
mwcmp
4 Solutions
 
OnegaZhangCommented:

add two message handlers WM_LBUTTONDOWN  and WM_LBUTTONUP
when left mouse button is down, OnLButtonDown is being called.
0
 
Amritpal SinghCommented:
have a look at the sample at the following link

http://www.funducode.com/freevc/mouse_vc/mouse_vc3.asp
0
 
RuskialtCommented:
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)

BEGIN_MESSAGE_MAP(CMapView, CView)
  ON_WM_LBUTTONDOWN()
  ON_WM_LBUTTONUP()
END_MESSAGE_MAP()

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
Ruskialt
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

-Surya
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now