Introduction
In MFC, it is quite possible to map a BN_DOUBLECLICKED
message for your button, but it will never be called by the framework as the two clicks get interpreted as two single clicks on the button. To get around this in the past, I developed the following algorithm in the BN_CLICKED
handler to work out which type of clicking was really being done by the user.
void CTestView::OnButton1()
{
static bool double_wait = false;
static bool handled = false ;
MSG msg ;
if (double_wait)
{
TRACE("Double click\n") ;
handled = true ;
return ;
}
else
handled = false ;
double_wait = true ;
UINT time = GetDoubleClickTime() ;
UINT slice = time / 10 ;
for (int i = 0 ; i < 10 && !handled ; i++)
{
if (i == 9)
Sleep(slice + time % 10) ;
else
{
Sleep(slice) ;
}
while (::PeekMessage(&msg, NULL, 0, 0,
PM_NOYIELD | PM_REMOVE))
{
::TranslateMessage(&msg) ;
::DispatchMessage(&msg) ;
}
}
if (!handled)
{
TRACE("Single click\n") ;
}
double_wait = false ;
}
So with this code in your OnClick()
handler, you can then do the correct single/double click function code.
Enjoy!
Revision History
- 26th June, 2002 - Initial revision
A research and development programmer working for a pharmaceutical instrument company for the past 17 years.
I am one of those lucky people who enjoys his work and spends more time than he should either doing work or reseaching new stuff. I can also be found on playing DDO on the Cannith server (Send a tell to "Maetrim" who is my current main)
I am also a keep fit fanatic, doing cross country running and am seriously into [url]http://www.ryushinkan.co.uk/[/url] Karate at this time of my life, training from 4-6 times a week and recently achieved my 1st Dan after 6 years.