Contents

Views 9235 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. 해커스랩 깨기.. 후후.. ㅋㅋ

    Date2013.04.23 CategorySystem/OS Byhooni Views18523
    Read More
  2. 플라스터(Plaster) 수업 내용

    Date2016.05.24 CategoryEtc Byhooni Views0
    Read More
  3. 프로그램 문서 관리 (Doxygen)

    Date2013.04.23 CategoryDevelop Byhooni Views16436
    Read More
  4. 프로그래밍에서 foo, bar 함수의 유래

    Date2013.06.25 CategoryDevelop Byhooni Views21469
    Read More
  5. 프로그래밍 소스 관련 사이트..

    Date2013.04.23 CategoryDevelop Byhooni Views16524
    Read More
  6. 페이팔에서 돈 찾기 (Paypal withdraw)

    Date2014.02.20 CategoryDevelop Byhooni Views11475
    Read More
  7. 티스토리 테이블 html,css 구문

    Date2013.11.03 CategoryEtc Byhooni Views16051
    Read More
  8. 콘솔에서 패스워드 걸린 zip 압축하는 명령

    Date2018.03.02 CategorySystem/OS Byhooni Views1126
    Read More
  9. 컴파일러 수업 자료(교재 : 컴파일러 입문)

    Date2003.04.23 CategorySystem/OS Byhooni Views22072
    Read More
  10. 캘리포니아 운전면허 족보

    Date2017.06.12 CategoryDevelop Byhooni Views884
    Read More
  11. 캘리포니아 운전면허 문제

    Date2017.07.22 CategoryEtc Byhooni Views1169
    Read More
  12. 최근 논문 자료 (2011/01/03, 만현형한테 보낸거..)

    Date2013.04.23 CategoryDevelop Byhooni Views10366
    Read More
Board Pagination Prev 1 2 3 4 5 6 7 8 9 10 ... 98 Next
/ 98