Views 9209 Votes 0 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
121 Develop [ios] 앱에서 다른 앱 실행시키기 file hooni 2013.09.05 18528
120 Develop [ios] libxml/tree.h file not found file hooni 2013.08.08 18708
119 Develop [ios] Objective-C에서 형식이 있는 문자열(Format Strings)에 사용할 수 있는 토큰들(Tokens) file hooni 2013.04.23 18783
118 Develop URI 인코딩, URL 인코딩 file hooni 2013.04.23 18845
117 Develop 모터에 대한 pid 제어.. ㅎㅎ file hooni 2013.04.23 18878
116 Develop [js]모바일 웹에서 orientationchange hooni 2013.04.23 19357
115 Develop [php] XE 에서 php 구문 사용하기 (XE 템플릿에서) hooni 2013.10.31 19441
114 Develop [c] AES 알고리즘 (암호화/복호화) file hooni 2003.04.23 20046
113 Develop [c] UTF-8을 EUC-KR로 변환.. (iconv) file hooni 2013.04.23 20129
112 Develop [ios] UIView에서 상위 UIViewController 가져오기 hooni 2013.09.27 20153
111 Develop [php] substr() 한글 자를 때 깨짐 방지 hooni 2014.01.09 20363
110 Develop [android] [번역] 안드로이드 Android Cloud to Device Messaging(C2DM) hooni 2013.04.23 20421
109 Develop [opengl] 컴퓨터 그래픽스 강의 자료(수업자료) file hooni 2003.04.23 20432
108 Develop git 브런치 배우기 (링크) hooni 2013.07.09 20571
107 Develop [c++] 디렉토리 내의 파일 찾기 FindFirstFile() 함수 6 hooni 2013.04.23 20573
106 Develop [c] 이진트리/트리 순회법 코드(전위/중위/후위) 5 file hooni 2015.07.02 20919
Board Pagination Prev 1 ... 44 45 46 47 48 ... 53 Next
/ 53