Auto-Repeat on a Button Control

USAGE:
WindowsNT 4.0 SVC Pack 3
VC++ 5.0
Dialog Based Application

I have a button control in a dialog based application that needs an auto-repeat feature on it. In other words it need to act like a scroll bar button where if you hold the left button down it pauses then continually moves the view in the desired direction.
Problem is I only have a OnButton message handler for the control which is called only when the user releases the button. How do I implement the desired feature under these circumstances?
Thanks in advance
shark351Asked:
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.

WynCommented:
Try this:

on_wm_lbuttondown
while(flag)
{
first step:
here do one time your chores
second step:
peekmessage() and check whether it's wm_lbuttonup,and set the flag correspondingly.
}

Regards
Wyn
0
WynCommented:
Here elaborate the second step:

while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
AfxGetApp ()->PumpMessage ();
}


and in the handler of on_wm_lbuttonup

on_wm_lbuttonup
{
flag=false;
}

on_wm_mousemove
{
//
that's all.
Btw:
you should also setcapture() and check the mouse point whether still on your button using ptinrect() in on_wm_mousemove and set flag to false and releasecapture if ptinrect() return false.
Regards
Wyn

0
WynCommented:
Here elaborate the second step:

while (::PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE)) {
AfxGetApp ()->PumpMessage ();
}


and in the handler of on_wm_lbuttonup

on_wm_lbuttonup
{
flag=false;
}

on_wm_mousemove
{
//
that's all.
Btw:
you should also setcapture() and check the mouse point whether still on your button using ptinrect() in on_wm_mousemove and set flag to false and releasecapture if ptinrect() return false.
Regards
Wyn

0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

shark351Author Commented:
That doesn't work since the 'dialog based app' doesn't respond to the WM_LBUTTONDOWN message when the button controls are clicked. Only the raw client area of the dialog box can handle the OnLButtonDown message handler.
0
WynCommented:
no,you can call SubclassWindow().
0
WynCommented:
Create your button class and subclass the dialog's button.

You should not reject me if there are somethings which not clear to you.
Just ask.

0

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
shark351Author Commented:
This is certainly going to be a lot more work than I imagined. The buttons were created in the resource editor. In order to call SubclassWindow() I need the handle to each button. How is this achieved?
Secondly since the base class now receives all the messages how do I know when one of the buttons have been clicked?
0
olgatCommented:
In your derived button class

1. SetTimer() in OnLButtonDown()
2. In OnTimer()
   call ButtonParentWnd->SendMessage(WM_COMMAND, BUTTONID,...)
3. KillTimer() in OnLButtonUp()

0
shark351Author Commented:
This is certainly going to be a lot more work than I imagined. The buttons were created in the resource editor. In order to call SubclassWindow() I need the handle to each button. How is this achieved?
Secondly since the base class now receives all the messages how do I know when one of the buttons have been clicked?
0
WynCommented:
shark351,
No matter how much work you'v got to do,if you dont subclass it,you can not get mouse message and then
How can you implement YOur auto-repeat button?
Btw:It's not too much work:)

Since your question is that,you'v got to do that,otherwise,you should avoid this kind of button.

Using a timer as olgat suggests works but compare with peekmessage,using a timer is less efficient and unreliable if you need do a long chores each time and keep the sensibility when user release the mousebutton.It's your choice.
If you just want your button act as the scroll button,you can use a timer but the background is the same.
derive your class and subclass then do thing in wm_lbuttonup and wm_lbuttondown.
 
>>In order to call SubclassWindow() I >>need the handle to each button. How >>is this achieved
Call GetDlgItem()

>>Secondly since the base class now >>receives all the messages how do I >>know when one of the buttons have >>been clicked?
In the GetDlgItem ,you will specify which one you want to subclass.And message to that button will go to your derived button class message-handler.
Regards
Wyn




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