message queues and buffered mouse clicks
Hi,
I have a button in an MFC app that executes a lengthy query and I want
to disable the button while the query executes. The problem is that
mouse clicks over the disabled button are buffered, and are then
processed when the button is enabled. Here's my OnBnClickedQueryButton
handler.
Attempt 1:
m_queryButton.EnableWindow(FALSE);
ExecuteLengthyQuery();
m_queryButton.EnableWindow();
So I tried to grab the focus away from the button, but this attempt
didnt work either.
Attempt 2:
SetFocus();
SetCapture();
m_queryButton.EnableWindow(FALSE);
ExecuteLengthyQuery();
m_queryButton.EnableWindow();
ReleaseCapture();
Finally, I rationalized that mouse click messages were being queued up
in the message queue, so I had to allow them to process without
invoking ExecuteLengthyQuery. I modified my OnBnClickedQueryButton
handler again.
Attempt 3:
if (m_buttonLockout)
{
return;
}
m_buttonLockout = true;
ExecuteLengthyQuery();
HWND myHWND = GetSafeHwnd();
::PostMessage(myHWND, WM_FINISHED_QUERY, 0, 0);
I reset buttonLockout to false in the WM_FINISHED_QUERY message
handler, with the idea that my WM_FINISHED_QUERY message was posted to
the message queue after the WM_LBUTTONDOWN messages. But guess what?
Didnt work. Then I combined Attempts 2 and 3, and it still didnt
work!
Can someone please shed some light on this behavior?
Thank you,
Jim
--
mfc130603
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------