|
-
February 17th, 2004, 05:42 PM
#1
Quick Button Clicks
Hi,
I have a button (MFC CButton object) which would very possibly want to be clicked repetively (quite fast) and produce its result on all clicks. By default clicking the button once will do its event, the second click does nothing, then the third click does, etc. I think that the double-click message might be causing problems, does anybody know of a fix?
Regards,
Lea Hayes
-
February 17th, 2004, 06:12 PM
#2
If you do not want Double clicks, remove CS_DBLCLKS style from your Window class.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 17th, 2004, 06:15 PM
#3
Hi,
Thanks for your help, would you be able to show me how to do this please?
Best Regards,
Lea Hayes
-
February 17th, 2004, 06:30 PM
#4
You'd have to derive your own class for that control (was it a button?), and override PreCreateWindow() function like that:
Code:
BOOL CYourWnd::PreCreateWindow(CREATESTRUCT& cs)
{
if (!CWnd::PreCreateWindow(cs))
return FALSE;
cs.dwExStyle |= WS_EX_CLIENTEDGE;
cs.style &= ~WS_BORDER;
cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW,
::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);
return TRUE;
}
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 17th, 2004, 06:34 PM
#5
Hi,
Thanks for your help!
Regards,
Lea Hayes
-
February 17th, 2004, 07:57 PM
#6
Hi VladimirF
Just had the same problem, thank you for the tip of CS_DBLCLKS style. I think that I found a solution without deriving my own class:
DWORD dwStyle = ::GetClassLong(m_hwndButton, GCL_STYLE);
dwStyle &= ~CS_DBLCLKS;
::SetClassLong(m_hwndButton, GCL_STYLE, dwStyle);
That's better for my case; maybe someone else needs it too.
Oliver
-
February 17th, 2004, 08:22 PM
#7
Hi Oliver,
your solution will work ONLY if you want to change double-click handling for all windows of that class. For example, if you want to disable it for one button, all buttons will be affected.
If this works for your particular situation - than your way is simpler.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 17th, 2004, 10:27 PM
#8
Hi VladimirF
Yes, you're right... it works well for my situation, but it is not generally desireable. Thanks for this note, I'll better keep it in mind!
Oliver.
-
February 17th, 2004, 10:46 PM
#9
Hi VladimirF. I also tried your code for my button on status bar but my button seems like a white edit box and I cannot change its text. the button has the main dialog as parent window(I could not attach it to statusbar window since I could not get CWnd of status bar). How can I make the button work. It is only to show a popup menu. Thanks
-
February 18th, 2004, 02:23 AM
#10
Hi,
I have found another solution for those interested; if you create a custom button (derived from CButton) and override the DefWindowProc virtual function, and place the following in its body; then that also fixes the problem:
Code:
if(message == WM_LBUTTONDBLCLK)
message = WM_LBUTTONDOWN;
return CButton::DefWindowProc(message, wParam, lParam);
Best Regards,
Lea Hayes
-
February 18th, 2004, 08:20 AM
#11
Hi lhayes00
Funny, I just found a quite similar solution and wanted to post it. My attempt was to handle WM_LBUTTONDBLCLK
Code:
void CMyButton::OnLButtonDblClk(UINT nFlags, CPoint point)
{
// send normal left-click message
SendMessage(WM_LBUTTONDOWN, nFlags, MAKELPARAM(point.x, point.y));
}
Oliver.
-
February 18th, 2004, 01:56 PM
#12
Hi Lea and Oliver,
although what you did might work in your particular case, you are playing dangerous game by replacing one window's message with another.
The double click could have been generated as a result of BOTH WM_LBUTTONDOWN and WM_LBUTTONUP processing, and you are only forwarding button down.
If a client is relying on getting button up for each button down, he is going to wait for a long time...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 18th, 2004, 04:41 PM
#13
Hi VladimirF
Right. So can we "fix" this by sending WM_LBUTTONDOWN and WM_LBUTTONUP?
Oliver.
-
February 18th, 2004, 06:34 PM
#14
Originally posted by Oliver Twesten
Right. So can we "fix" this by sending WM_LBUTTONDOWN and WM_LBUTTONUP?
Not really. It wasn't my point. I said "could have been".
Your first suggestion will work. If you read remarks from MSDN:
Only windows that have the CS_DBLCLKS style can receive WM_LBUTTONDBLCLK messages, which the system generates whenever the user presses, releases, and again presses the left mouse button within the system's double-click time limit. Double-clicking the left mouse button actually generates a sequence of four messages: WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK, and WM_LBUTTONUP.
All I am saying is that you should not substitute one message with another, especially if you are not sure.
My point was that double click messages are controlled by documented style, and if you do not want to receive them - do not set that style.
Of course, you could find a hack that will work...
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
February 19th, 2004, 08:38 AM
#15
Hi VladimirF
Sorry if this sounds as if I just do not want to try your solution. The point is, that I can not get it to work for my special case. Maybe you can help me and I'll surely use the better / cleaner approach!
I have already derived my own button class that does a lot of painting things with my buttons. I use this ownerdrawn button on almost all dialog templates in my project and need to disable the double-clicks for only 2 buttons.
And I thought - as long as I find a hack that can solve this situation for the 2 buttons - I do not want to implement many new stuff.
Would you mind telling me exactly what to do in my situation? OnCreate will not be called for the button class - I think I'm missing something here. Do I have to re-create the whole button functionality and derive from CWnd?
Thank you!
Oliver.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|