Solved

How to have a "repeat button"?

Posted on 1997-06-06
2
245 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
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

15 Experts available now in Live!

Get 1:1 Help Now