Contents

Views 10795 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;
}


?

List of Articles
No. Category Subject Author Date Views
721 Develop [c] 패킷정보출력(경로, 패킷길이, 3hand, sync, ack..) file hooni 2003.04.23 8485
720 Develop [c] 내가 만든 암호화 프로그램.. 좋아^^ file hooni 2013.04.23 8491
719 Develop [c] 간단한 순위 루틴.. (질문에 대한 답변) hooni 2003.04.23 8493
718 Develop [c] 스택/힙 오버플로우 테스트(overflow) file hooni 2003.04.23 8493
717 Develop [c] 프로그래밍 과제..(colprint) file hooni 2003.04.23 8513
716 Develop [js] 네이버에서 그림 퍼올 때.. URL Encoding 관련ㅋㅋ hooni 2013.04.23 8521
715 Develop [php] 자바스크립트 개판 만들기.. file hooni 2013.04.23 8528
714 Develop [c] 구조체 배열 예제 (학생 성적 계산) file hooni 2013.04.23 8534
713 Develop [jsp][php] LDAP 프로그래밍.. file hooni 2003.04.23 8535
712 Develop [chm] 윈도우즈에서 디버깅 기법(Debugging Applications) file hooni 2013.04.23 8547
711 Develop [c] 단기과정[01/07] 제어문, 피보나치수열 hooni 2003.04.23 8553
710 Develop [c] 도메인(호스트)으로 IP정보 알아오기.. (nslookup과 비슷) file hooni 2013.04.23 8553
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 99 Next
/ 99