Solved

How to have a "repeat button"?

Posted on 1997-06-06
2
249 Views
Last Modified: 2013-11-20
My application needs a "repeat button" : a button that sends a  messages every m milisecondes when the user maintains it pressed. Could tell what is the best way to implement this?
(Is it in a new class repeat  button, at he level of the toolbar that have the button or in the View that use the handle the command?
Thanks, Nicolas
0
Comment
Question by:Nicolas060297
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 2

Accepted Solution

by:
The Master earned 100 total points
ID: 1301998
As far as I know, the only time you get a button-click notification is when the button is acutally pressed, and then released.  You need to start your handling when the button is pressed, so you need to create your own class.

You could do this pretty easily by deriving a class from CButton, and handling the following messages:

OnLButtonDown()
OnLButtonUp()
OnTimer()

In OnLButtonDown, just call SetTimer() with the appropriate delay, and in OnLButtonUp, call KillTimer().  In your OnTimer() handler, send your message.

I'm pretty sure the timer resolution in Windows is around 55 ms, so if you want faster messages than that, you could alternatively start a peekmessage loop in your OnLButtonDown handler, and call timeGetTime() every loop to know when to send out the message.  You would obviously break out of the loop when you received a WM_MOUSEUP message.

Good Luck!
0
 

Author Comment

by:Nicolas060297
ID: 1301999
This answer suits me quite well. But I would have liked a little bit more details about how the button generates an application message.
(How does it knows the message it have to send)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

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. …
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.

735 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