Using SetTimer (+getting hWnd) with a CDocument derived class

AlanSmith5
AlanSmith5 used Ask the Experts™
on
Hi

I have an SDI application. In my CDocument derived class I have a timer setup with

UINT_PTR SetTimer(
  HWND hWnd,              // handle to window
  UINT_PTR nIDEvent,      // timer identifier
  UINT uElapse,           // time-out value
  TIMERPROC lpTimerFunc   // timer procedure
);

What is the equivalent of hWnd for a CDocument class, ie one not derived from CWnd? Or do I somehow set up / associate the timer with my CView class?

Regards
Alan
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
>Or do I somehow set up / associate the timer with my CView class?

That's correct. You need to associate the timer with your view class or, better yet, with your CFrameWnd dervided class. There's no CDocument equivalent for HWND because a document is not a window and obviously, only window procedures can receive a timer message.

Commented:
use the class wizard and add WM_TIMER for the CView class

Author

Commented:
> That's correct. You need to associate the timer with your view class or, better yet, with your CFrameWnd dervided class.

OK. My CDoc class actually does all the work. So I put the timer in the CView derived class, and when it fires I call the necessary method in the CDoc class (accessing it via GetDocument())?
Is that it?

Alan
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Commented:
>So I put the timer in the CView derived class, and when it fires I call the necessary method in the CDoc class (accessing it via GetDocument())?

That's right. The class wizard should have generated a GetDocument() in your CView derived class which returns the CYourDocument() pointer. Use that pointer to access the document.

Alternatively, you'll be doing something like this:

CYourDocument* pDoc = (CYourDocument*) CView::GetDocument();

//now use pDoc to call whatever function you wish to call:
pDoc->MyFun();

Author

Commented:
Thanks bahsi

Commented:
You're welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial