Contents

Views 9209 Comment 0
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
?

Shortcut

PrevPrev Article

NextNext Article

Larger Font Smaller Font Up Down Go comment Print
SetTimer
The SetTimer function creates a timer with the specified time-out value. 
UINT SetTimer(
    HWND hWnd,              // handle of window for timer messages
    UINT nIDEvent,          // timer identifier
    UINT uElapse,           // time-out value
    TIMERPROC lpTimerFunc   // address of timer procedure );

The SetTimer function creates a timer with the specified time-out value. 

첫번째 인수 : 타이머 받을 윈도우
두번째 인수 : 타이머의 번호 (하나 이용시 1을 쓰고, 그외에 타이머들은 번호를 고유한 부여시킨다 )
세번째 인수 : 타이머의 주기 단위는 1/1000초  ( 1000 == 1초 )
네번째 인수 : 타이머 발생시 호출하는 함수 지정.

예) SetTimer(hWnd, 1, 1000, NULL );

//타이머는 시스템 전역 자원으로 이용 후 파괴하는것이 좋다.
BOOL KillTimer(
    HWND hWnd,      // handle of window that installed timer
    UINT uIDEvent   // timer identifier
);

두번째 인수 : SetTimer의 두번째 인자값이며, 파괴할 타이머 번호 대상이 된다. 

////////////////////////////////////////////////////////////////////////////////////

두개의 타이머 이용. 두개의 타이머 모두 WM_TIMER를 호출 한다.
또한 강제로 SendMessage()로 WM_TIMER를 불러 프로그램 시작 직후 바로 적용시킨다.

//예제
case WM_CREATE:
    SetTimer(hWnd, 1, 1000, NULL);
    SetTimer(hWnd, 2, 5000, NULL);
    SendMessage(hWnd, WM_TIMER, 1, 0);
    return 0;
    
case WM_TIMER:
    switch(wParam)
    {
        case 1:
            GetLocalTime(&st);
            wsprintf(sTime,TEXT("현재 시간 %d:%d:%d"),
                st.wHour, st.wMinute, st.wSecond);
            InvalidateRect(hWnd, NULL, TRUE);
            break;
        case 2:
            MessageBeep(0);
            break;
    }
    return 0;

////////////////////////////////////////////////////////////////////////////////////

일회용 타이머를 이용.

//WM_TIMER에 KillTimer를 넣어 이벤트 발생시 3초동안 글자 표시하고 사라지게 만드는 예제
static TCHAR str[128];

switch(iMessage)
{
    case WM_TIMER:
        KillTimer(hWnd, 1);
        lstrcpy(str,"");
        InvalidateRect(hWnd, NULL, TRUE);
        return 0;
        
    case WM_LBUTTONDOWN:
        lstrcpy(str,"왼쪽 버튼을 눌렀습니다.");
        InvalidateRect(hWnd, NULL, TRUE);
        SetTimer(hWnd, 1, 3000, NULL);
        return 0;
        
    case WM_PAINT:
        hdc = BeginPaint(hWnd, &ps);
        TextOut(hdc, 10,10, str, lstrlen(str));
        EndPaint(hWnd, &ps);
        return 0;
}


?

  1. 프로그램 문서 관리 (Doxygen)

    Date2013.04.23 CategoryDevelop Byhooni Views16385
    Read More
  2. [php] php+db 연동(odbc, mssql, mysql, sybase)

    Date2013.04.23 CategoryDevelop Byhooni Views8539
    Read More
  3. [asp] 폼 메일 소스

    Date2013.04.23 CategoryDevelop Byhooni Views7352
    Read More
  4. [asp] 폼메일 예제와 메일 포워딩 프로그램

    Date2013.04.23 CategoryDevelop Byhooni Views7129
    Read More
  5. [c] 프로세스 검사하기

    Date2013.04.23 CategoryDevelop Byhooni Views8027
    Read More
  6. [linux] 리눅스,유닉스 /proc/stat 파일 보는 법

    Date2013.04.23 CategorySystem/OS Byhooni Views17916
    Read More
  7. [linux] 리눅스, 유닉스 CPU 이용률 확인..

    Date2013.04.23 CategorySystem/OS Byhooni Views23782
    Read More
  8. [linux] 리눅스 파일시스템과 디렉토리 설명

    Date2013.04.23 CategorySystem/OS Byhooni Views26877
    Read More
  9. [c] 네트워크 관련 프로그래밍 (포트스캔 탐지 샘플)

    Date2013.04.23 CategoryDevelop Byhooni Views7198
    Read More
  10. [c] SetTimer() & KillTimer() & 일회용 Timer

    Date2013.04.23 CategoryDevelop Byhooni Views9209
    Read More
  11. [c++] 인라인 함수에 대한 설명

    Date2013.04.23 CategoryDevelop Byhooni Views7110
    Read More
  12. [c++] 인라인 함수 설명과 예제..

    Date2013.04.23 CategoryDevelop Byhooni Views6633
    Read More
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 98 Next
/ 98