Re: TimerProc and accessing dialog members

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Scott McPhillips [MVP] (org-dot-mvps-at-scottmcp)
Date: 11/26/04


Date: Fri, 26 Nov 2004 09:08:38 -0500

Daniel Lidström wrote:
> No, not quite. What I'm trying to do is this:
>
> void SurfPage::OnLoop()
> {
> if( m_looping )
> ::KillTimer(NULL, m_nTimer);
> else
> m_nTimer = ::SetTimer(NULL, 1, 100, (TIMERPROC)TimerProc);
>
> m_looping = !m_looping;
> }
>
> /* static */
> VOID CALLBACK SurfPage::TimerProc(
> HWND hwnd, // handle to window
> UINT uMsg, // WM_TIMER message
> UINT_PTR idEvent, // timer identifier
> DWORD dwTime // current system time
> )
> {
> // set m_val to something
> // then update CEdit control in SurfPage.
> // m_val is connected to the CEdit box through
> // DDX. How can I change the displayed value in the
> // CEdit box? This is a static function, that is the
> // whole problem.
> }
>
> Thanks!
>

The static function needs a static variable that is a pointer to the
dialog box. When you create the dialog set the pointer. The static
function can use it to call a dialog function, or to send/post a message
to the dialog. Then a dialog function should do the update.

But why not use a WM_TIMER message handler? If you do that then MFC
solves this problem for you, by calling your nonstatic handler function.

If you are trying to update the dialog from a separate thread then
neither approach will work, and you asked the wrong question.

-- 
Scott McPhillips [VC++ MVP]


Relevant Pages

  • Re: PostMessage parameter problem
    ... > WPARAM is a typedef for pointer to unsigned int. ... To pass the structure values to message handler, u have to do it by ... info* pInfo = new info; ...
    (microsoft.public.vc.mfc)
  • RE: PostMessage parameter problem
    ... WPARAM is a typedef for pointer to unsigned int. ... So it can't ur structure data. ... To pass the structure values to message handler, u have to do it by passing pointers, here the postmessage looks like, ...
    (microsoft.public.vc.mfc)
  • Re: Sample Grabber Performance
    ... new pointer via a message to the message handler. ... created the bitmap and then deleted the pointer. ... hurt my performace a little. ...
    (microsoft.public.win32.programmer.directx.video)