//대충 만든거라 엄청 불친절. 그냥 무슨무슨 기능을 썼는지만, 보는 용도.
HANDLE hTimerHandle = 0; //타이머 핸들
struct _Rain
{
wchar_t Rain;
int Text_X, Text_Y;
};//필요 구조체.
_Rain ones;//구조체 변수
list<_Rain> Raining;//리스트 변수 선언
list<_Rain>::iterator CreateRain;//리스트 반복자 선언
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE :
//더미 데이터 입력.
hTimerHandle = (HANDLE)SetTimer(hWnd, 1, 100, NULL);
hTimerHandle = (HANDLE)SetTimer(hWnd, 2, 1000, NULL);
ones.Rain = 'a';
ones.Text_X = 0, ones.Text_Y = 0;
Raining.push_back(ones);
srand((unsigned)time(0));
//데미 데이터 입력 끝.
break;
case WM_COMMAND:
wmId = LOWORD(wParam);
wmEvent = HIWORD(wParam);
// 메뉴 선택을 구문 분석합니다.
switch (wmId)
{
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_TIMER :
//1번 타이머 - 0.1초마다 문자들의 Y축값이 변경된다.
if (wParam == 1)
{
CreateRain = Raining.begin();
while (CreateRain != Raining.end())
{
CreateRain->Text_Y += 10;
CreateRain++;
}
}
//2번 타이머 - 1초마다 랜덤하게 문자를 생성한다.
else if (wParam == 2)
{
ones.Rain = ('a' + (rand() % 26));
ones.Text_X = rand() % 800;
ones.Text_Y = 0;
Raining.push_back(ones);
}
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
hdc = GetDC(hWnd);
CreateRain = Raining.begin();
while (CreateRain != Raining.end())
{
TextOut(hdc, CreateRain->Text_X, CreateRain->Text_Y, &CreateRain->Rain, 1);
CreateRain++;
}
// TODO: 여기에 그리기 코드를 추가합니다.
EndPaint(hWnd, &ps);
break;
case WM_KEYDOWN :
CreateRain = Raining.begin();
if (CreateRain->Rain == wParam + 32)
{
CreateRain = Raining.erase(CreateRain);
}
break;
case WM_DESTROY:
KillTimer(hWnd, 1);
KillTimer(hWnd, 2);
Raining.clear();
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}