५✍
1.16 본문
만들어야 하는 소스
"MoveChar-재시" 만들기
rand()%26; (26알파벳 갯수) 0-25
=97+k
strcmp 문자비교 사용 굳이 할 필요 없다
Timer[97p]
1. Timer Test
2. 임의문자
3. 출발지점정함
4. 타자받아들임
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107 |
#include <windows.h>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
HINSTANCE g_hInst;
HWND hWndMain;
LPCTSTR lpszClass = TEXT("Class");
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance
, LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
g_hInst = hInstance;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = WndProc;
WndClass.lpszClassName = lpszClass;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
RegisterClass(&WndClass);
hWnd = CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
while (GetMessage(&Message, NULL, 0, 0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT iMessage, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
SYSTEMTIME st;
static TCHAR random[10];
static TCHAR str[100];
static TCHAR current_char;
static RECT rt;
static int truecnt;
static int falsecnt;
static int x, y;
switch (iMessage) {
case WM_CREATE:
GetClientRect(hWnd, &rt);
SetTimer(hWnd, 1, 100, NULL); //0초부터 1초가지나면 timer를 호출
//
//SendMessage(hWnd, WM_TIMER, 1, 0); // 맨처음 시작할때 바로 timer호출
x = rand();
y = rand();
return 0;
case WM_TIMER:
y += 10; //y좌표 20씩 증가 //20씩 증가하면서 떨어지는 모습
if (y >= rt.bottom || x >= rt.right) //윈도우를 벗어날 경우
{
x = rand() % rt.right; //윈도우 범위안으로 바꿔주고
y = rand() % rt.bottom;
current_char = rand() % 26 + 97; //랜덤 문자를 바꿔줌
wsprintf(random, TEXT("%c"), current_char);
}
InvalidateRect(hWnd, NULL, TRUE);
return 0;
case WM_CHAR:
if (current_char == wParam)
{
truecnt++;
}
else
{
falsecnt++;
}
wsprintf(str, TEXT("Correct: %d, Miss: %d"), truecnt, falsecnt);
SendMessage(hWnd, WM_CREATE, 1, 0);
return 0;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
TextOut(hdc, x, y, random, lstrlen(random)); //랜덤한 화면에 랜덤한 알파벳을 뿌림
TextOut(hdc, 200, 500, str, lstrlen(str)); //스코어 출력
EndPaint(hWnd, &ps);
return 0;
/* OS 시스템, 즉 윈도우 운영체제 시스템의 기본 메시지를 처리해주는 함수
switch(iMessage) {
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
*/
case WM_DESTROY:
KillTimer(hWnd, 1);
PostQuitMessage(0);
return 0;
}
return(DefWindowProc(hWnd, iMessage, wParam, lParam));
}
|
cs |
'수업 > API' 카테고리의 다른 글
1.17 네모색넣기+ 컨트롤 시 (0) | 2019.01.17 |
---|---|
if안에 안들어감;;ㅜ (0) | 2019.01.17 |
1.16 끄적 (0) | 2019.01.16 |
1.15 (0) | 2019.01.15 |
1.14 (0) | 2019.01.14 |