CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2005
    Location
    Singapore
    Posts
    8

    On LeftButton Down Event

    Hi,

    I am tried to implement LeftButtonDown and LeftButtonUp Event on my button.

    It is something like I want to increase a variable while the button is pressed and stop increasing when the button is released.

    I tried ON_WM_LBUTTONDOWN but I cannot trigger the event. Is there any advices.

    Thanks in advances.

  2. #2
    Join Date
    Jul 2005
    Location
    E: 120°.6, N: 31°.3′
    Posts
    795

    Re: On LeftButton Down Event

    Code:
    OnLButtonDown()
    {
        AfxMessageBox("Left Button is down mode .");
    }
     ......
    
    OnLButtonUp()
    {
        AfxMessageBox("Left Button is Up mode. ");
    }

  3. #3
    Join Date
    Feb 2005
    Location
    Pune (India)
    Posts
    644

    Thumbs up Re: On LeftButton Down Event

    Can you post more code............
    But why do you want this..Do you need to compute difference between Down Event and Up Event..if it so you can use system time to compute this....or you can use timer..using continous loop..seems to be improper...


    -Anant
    Last edited by anantwakode; May 8th, 2006 at 01:53 AM.
    "Devise the simplest possible solution that solves the problems"

  4. #4
    Join Date
    May 2005
    Location
    Oregon
    Posts
    3,725

    Re: On LeftButton Down Event

    Have a look in MSDN for message handler WM_LBUTTONDOWN and WM_LBUTTONUP you will get the things with your self.

    and if you want you also can go for WM_NOTIFY The WM_NOTIFY message is sent by a common control to its parent window when an event has occurred or the control requires some information.

    if Still Some problem Let us know
    thankyou

  5. #5
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: On LeftButton Down Event

    Hello,

    If you have subclassed CButton, you can handle WM_LBUTTONDOWN and WM_LBUTTONUP messages to take appropriate action when left mouse button is pressed / released on that button. But you have to take care of a few things.

    There is a possibility that you press your left mouse button elsewhere and release it on the button. There can be vice-versa event where mouse button is pressed on the button and released elsewhere. In both cases, it does not generate a BN_CLICKED event. You may have to check in your program whether the pressing and releasing of left mouse button is done on the button itself.

    While handling the messages WM_LBUTTONDOWN and WM_LBUTTONUP, framework inserts default calls of CButton::OnLButtonDown / CButton::OnLButtonUp in the respective message handler functions. If they are removed or bypassed, pressing the button will not generate a BN_CLICKED notification message.

    If I understood your need correctly, the best method I can suggest is to start a timer when WM_LBUTTONDOWN message is handled, do the incrementing part in the timer and kill the timer in the handler of WM_LBUTTONUP.

    Here is how I handled the mouse messages:

    Code:
    
    void CMyButton::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    	// TODO: Add your message handler code here and/or call default
    	GetParent()->SetTimer(WM_USER, 1000, NULL);
    	CButton::OnLButtonDown(nFlags, point);
    }
    
    void CMyButton::OnLButtonUp(UINT nFlags, CPoint point) 
    {
    	// TODO: Add your message handler code here and/or call default
    	GetParent()->KillTimer(WM_USER);
    	CButton::OnLButtonUp(nFlags, point);
    }
    
    Here is how I incremented the variable in WM_TIMER message handler of the dialog box:

    Code:
    
    void CButtonDlg::OnTimer(UINT nIDEvent) 
    {
    	// TODO: Add your message handler code here and/or call default
    	UpdateData(TRUE);
    	m_Edit++;
    	UpdateData(FALSE);
    	CDialog::OnTimer(nIDEvent);
    }
    
    I have assumed that the application is dialog based and added an edit box with variable m_Edit attached with it. The increment is displayed in the edit box.

    Regards.
    Pravin.
    Last edited by Pravin Kumar; May 8th, 2006 at 03:54 AM.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

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

Featured