Re: Button for continous 'increase' function
Sure, there's almost always "a way". Off-hand, here's what comes to mind. The BN_CLICKED
notification is sent when you release the left mouse button after having pushed it down over the
button control; this is too late for what you want. The mouse messages, WM_LBUTTONDOWN and
WM_LBUTTONUP, are sent to the window for which the mouse click is in the client area (assuming no
others have captured the mouse). That means when you click on a pushbutton control, that control
window is sent these messages.
If you derive a class from CButton, and use this derived class for the All Layers Increase button,
you can add handlers for WM_LBUTTONDOWN and WM_LBUTTONUP. In the button down handler, set a timer
(SetTimer) that is fired at some brief interval (this depends on how rapid you want the increase to
happen while the button is down). Whenever the handler for the WM_TIMER messages is invoked in your
derived button class, it can send the BN_CLICKED notification to the parent dialog box via a
WM_COMMAND message. This is basically simulating numerous button clicks at a normal interval
(dictated by the timer). In the handler for the WM_LBUTTONUP, just kill the timer (KillTimer).
BN_CLICKED Notification ():
http://msdn.microsoft.com/en-us/library/bb761825.aspx
WM_COMMAND Notification ():
http://msdn.microsoft.com/en-us/library/ms647591(VS.85).aspx
Warning, I haven't actually tried this -- it just seems very reasonable.
Scot
"blackbiscuit" <infozyzhang@gmail.com> wrote in message
news:33ccdc05-6993-4492-ab48-0c38ca86a9ea@k19g2000prh.googlegroups.com...
Hi,
I have a fairly *old* C++ application in Visual Studio 2002, which
uses MFC.
It has a number of dialog boxes, and these dialogs are used for
controlling motors on machinery.
The dialogs have buttons for increasing and decreasing the motor
speeds, but the buttons need to be pressed repeatedly to get the
increase function to call - I cannot simply hold down the button.
The button is using the following handler:
ON_BN_CLICKED(IDC_ALL_LAYERS_INCREASE, OnAllLayersIncrease)
Is there any way to have this button function so that holding the
button down with the mouse, will cause the OnAllLayersIncrease
function to continuously get called?
Thanks,
Tony