Re: Stopping timer created inside subclass of CListView
glchin@hotmail.com wrote:
I have a timer that is created in a subclass of CListView :
void CResultsView::OnInitialUpdate()
{
:
SetTimer( REFRESH_VIEW_TIMER_ID, iScreenRefreshRate, NULL);
}
From elsewhere in my MFC application, I wish to stop the above timer
using KillTimer() . How can this be done? I want a pointer to the
CResultsView object, but it is declared:
protected:
CResultsView(); // protected constructor used by dynamic
creation
DECLARE_DYNCREATE(CResultsView)
The protected constructor is not relevant, since what you want is a
pointer to the object that MFC previously created. MFC saves pointers
to all of the objects it creates dynamically.
In an SDI application getting the pointer is as simple as calling
GetActiveView.
In MDI can iterate through all docs, and the views for each doc,
starting with GetFirstDocTemplatePosition, GetNextDocTemplate, etc.
There is also a standard MFC way to notify views without needing a view
pointer. Calling UpdateAllViews will call OnUpdate in every view, and
you can pass a hint parameter that could mean "kill timer" in your
particular program.
--
Scott McPhillips [MVP VC++]