Button down increment
-
I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.
-
I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.
-
I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.
One way would be to respond to the WM_LBUTTONDOWN message for the button control and go into a modal loop until the button is released:
On WM_LBUTTONDOWN...
::SetCapture(hwnd);
MSG Msg;
memset(&Msg,0,sizeof(MSG));
while (Msg.message != WM_LBUTTONUP &&
(Msg.message != WM_MOUSEMOVE ||
(Msg.wParam & MK_LBUTTON)))
{
if (::PeekMessage(&Msg,0,0,0,PM_REMOVE))
{
::TranslateMessage(&Msg);
::DispatchMessage(&Msg);
}// Increment displayed field
// Call ::InvalidateRect(hWnd, NULL, bErase) on displayed field control
// Call ::UpdateWindow(hWnd) on displayed field control
}::ReleaseCapture();
A better method would be to do it like the up-down control (spin button) does:
// (pseudocode)
On WM_LBUTTONDOWN
Capture the mouse (::SetCapture())
Create a timer for the desired interval of increments (::SetTimer())
On WM_TIMER
Increment displayed field
Call ::InvalidateRect(hWnd, NULL, bErase) on displayed field control
Call ::UpdateWindow(hWnd) on displayed field control
On WM_LBUTTONUP
Kill the timer (::KillTimer())
Release the mouse (::ReleaseCapture())-- modified at 21:40 Monday 25th June, 2007
"Go that way, really fast. If something gets in your way, turn."
-
I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.
Check out
CBitmapButton
in WTL, that class has this feature (it's called "autofire"), so you could take the code from there.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
-
Check out
CBitmapButton
in WTL, that class has this feature (it's called "autofire"), so you could take the code from there.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
Cool! I have a dumb question....is WTL for XP+ or are lower OSs supported? Thanks! Mark
"Go that way, really fast. If something gets in your way, turn."
-
Check out
CBitmapButton
in WTL, that class has this feature (it's called "autofire"), so you could take the code from there.--Mike-- Visual C++ MVP :cool: LINKS~! Ericahist | PimpFish | CP SearchBar v3.0 | C++ Forum FAQ Dunder-Mifflin, this is Pam.
I can read :rolleyes: Supported Operating Systems: Windows 2000; Windows Server 2003; Windows Vista; Windows XP
"Go that way, really fast. If something gets in your way, turn."
-
I want to create a button that will force an acton to continue as long as the button is "down." For example, I want to increment a displayed field by 1 as long as the button is down. I can increment each time the button is clicked, but can't hold it down and get multiple increments. What's the general approach to this? Thanks.
It has been a while, but essentially you just need to start a timer that calls a timer message handler of you choice. The timer handler keeps doing the increment until you release the button. When you release the button, then you need to release the timer. This is very similar as to how one selects lines in a text editor (or web page), that is a timer is used to make the window scroll when you mover the mouse cursor near the edge of the window when selecting text.
INTP "Program testing can be used to show the presence of bugs, but never to show their absence."Edsger Dijkstra