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


?

List of Articles
No. Category Subject Author Date Views
717 Develop 논문 실험용 고려대 툴바 ㅎㅎ secret hooni 2013.04.23 8686
716 Develop [ios] 개발 기초 가이드 링크.. hooni 2013.04.23 31366
715 System/OS 맥북에서 MAC/윈도우 멀티부팅시 시간 설정 file hooni 2013.04.23 29759
714 Develop 웹페이지 성능 테스트 툴 설명 hooni 2013.04.23 27445
713 Develop [Xcode] 디버깅 옵션 file hooni 2013.04.23 57196
712 Algorithm 러시아 페인트공 알고리즘에 대해.. hooni 2013.04.23 22895
711 Develop [ios] Objective-C 문자열 잘라서 배열(NSArray)에 넣기 hooni 2013.04.23 29415
710 Develop [ios] Objective-C 특정 문자 찾아 제거하기 hooni 2013.04.23 28065
709 Develop [ios] Objective-C에서 형식이 있는 문자열(Format Strings)에 사용할 수 있는 토큰들(Tokens) file hooni 2013.04.23 18783
708 Develop [ios] Objective-C 문자열 조작 메서드 hooni 2013.04.23 26455
707 Develop [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) hooni 2013.04.23 20421
706 PPT [ppt] Equation Solving 발표 자료 (@PWE랩 톡데이 2011.07.26) file hooni 2013.04.23 24669
Board Pagination Prev 1 ... 34 35 36 37 38 39 40 41 42 43 ... 98 Next
/ 98