No. Because of my understanding (which I described in the previous
posting) I decided that a PeekMessage loop was NOT needed, so I don't
call ::PeekMessage() nor CProgressWnd::PeekAndPump().
And provided I send FEWER than approx 5 progress messages per sec from
the filter graph to the handler in my main CMyDialog object then
CProgressWnd::OnCancel() gets called and it *seems* to works fine -
but it doesn't fill me with confidence!
To simplify, first start a 0.5 second timer. Then call
CProgressWnd::Create
to put up the dialog modelessly. Then start your background thread that
starts the filter graph. When your primary thread receives messages from
the thread, call the CProgressWnd to update the progress. When your
OnTimer() is called every 0.5 seconds, call CProgressWnd::Cancelled() to
see
if the Cancel button has been clicked.
Thanks for your suggestion. I just tried using only Create and I can
allow LOTS of progress messages per sec to be sent from filter graph
to the CMyDialog handler, and pressing the Cancel button results in
OnCancel being executed IMMEDIATELY every time!
That's great, except that I NEED the CProgressWnd to be modal - I
don't want anyone messing with the main window while the "progressed"
operation is taking place.
Any idea how I can get this to work properly as modal ?
All GoModal seems to do is call EnableWindow(FALSE) on the parent
window, then EnableWindow(TRUE) on itself. But this seems to screw up
the message handling in the way I've previously described.
There is a fragment of code in the CProgressWnd::PeekAndPump() which
says:
// Cancel button disabled if modal, so we fake it.
if (m_bModal && (msg.message == WM_LBUTTONUP))
{
CRect rect;
m_CancelButton.GetWindowRect(rect);
if (rect.PtInRect(msg.pt))
OnCancel();
}
This suggests that if you use GoModal() then the normal invocation of
the OnCancel() does not work, so he's written a workaround to see if
the left mouse button was clicked within the Cancel button's rect.
However, I HAVE been using GoModal (with NO call to PeekAndPump) and
the OnCancel handler IS being invoked when I click the Cancel button -
so the above fragment of code seems to be wrong. i.e. the cancel
button does NOT get disabled if you are using CProgressWnd::GoModal.
But it does seem to screw up the message handling.
Any idea how I can get to work properly as a MODAL window?
somehow. I would insert OutputDebugString messages to output when the click
event is processed to see why some of those are getting dropped. Sorry,
nothing else stands out as a possible culprit.