천객만래 [千客萬來] (It has an interminable succession of visitors)

'WM_TIMER'에 해당되는 글 2건

  1. 2012.05.02 [개발/MFC] WM_TIMER 예제
  2. 2011.03.23 [개발/MFC] WM_TIMER 예제

[MFC] WM_TIMER 예제


// Message Map
BEGIN_MESSAGE_MAP(CDlgDlg, CDialog)
    ...
    ON_WM_TIMER()
END_MESSAGE_MAP()

...

// Timer ID constants.
const UINT ID_TIMER_ONE  = 0x1001;
const UINT ID_TIMER_TWO = 0x1000;

// Start the timers.
void CDlgDlg::StartTimer()
{
    // Set timer for Minutes.
    SetTimer( ID_TIMER_ONE, 60 * 1000, 0 );

    // Set timer for Seconds.
    SetTimer( ID_TIMER_TWO, 1000, 0 );
}

// Stop the timers.
void CDlgDlg::StopTimer()
{
    // Stop both timers.
    KillTimer( ID_TIMER_ONE  );
    KillTimer( ID_TIMER_TWO );
}

// Timer Handler.
void CDlgDlg::OnTimer( UINT nIDEvent )
{
    // Per minute timer ticked.
    if( nIDEvent == ID_TIMER_ONE )
    {
        // Do your minute based tasks here.
    }

    // Per minute timer ticked.
    if( nIDEvent == ID_TIMER_TWO )
    {
        // Do your seconds based tasks here.
    }
}

 

위의 방법외에도 다른 방법이 있다.

UINT SetTimer(
   UINT nIDEvent,
   UINT 
nElapse,
   void ( CALLBACK* 
lpfnTimer )(HWND, UINT, UINT, DWORD) = NULL 
) throw();

void CALLBACK TimerProc(HWND hWnd, UINT nIDEvent, UINT nElapse, DWORD dwTime)
{
    CWnd *pWnd = AfxGetMainWnd();

    CTestProgDlg *dlg = (CTestProgDlg *)pWnd;

    dlg->ShowWindow(SW_SHOW);
}

Posted by SB패밀리



[MFC] WM_TIMER 예제


// Message Map
BEGIN_MESSAGE_MAP(CDlgDlg, CDialog)
    ...
    ON_WM_TIMER()
END_MESSAGE_MAP()

...

// Timer ID constants.
const UINT ID_TIMER_ONE  = 0x1001;
const UINT ID_TIMER_TWO = 0x1000;

// Start the timers.
void CDlgDlg::StartTimer()
{
    // Set timer for Minutes.
    SetTimer( ID_TIMER_ONE, 60 * 1000, 0 );

    // Set timer for Seconds.
    SetTimer( ID_TIMER_TWO, 1000, 0 );
}

// Stop the timers.
void CDlgDlg::StopTimer()
{
    // Stop both timers.
    KillTimer( ID_TIMER_ONE  );
    KillTimer( ID_TIMER_TWO );
}

// Timer Handler.
void CDlgDlg::OnTimer( UINT nIDEvent )
{
    // Per minute timer ticked.
    if( nIDEvent == ID_TIMER_ONE )
    {
        // Do your minute based tasks here.
    }

    // Per minute timer ticked.
    if( nIDEvent == ID_TIMER_TWO )
    {
        // Do your seconds based tasks here.
    }
}

위의 방법외에도 다른 방법이 있다.

UINT SetTimer(
   UINT nIDEvent,
   UINT
nElapse,
   void ( CALLBACK*
lpfnTimer )(HWND, UINT, UINT, DWORD) = NULL
) throw();

void CALLBACK TimerProc(HWND hWnd, UINT nIDEvent, UINT nElapse, DWORD dwTime)
{
    CWnd *pWnd = AfxGetMainWnd();

    CTestProgDlg *dlg = (CTestProgDlg *)pWnd;

    dlg->ShowWindow(SW_SHOW);
}

Posted by SB패밀리