개요

프로그래밍 구조

똑같이 화면에 문자열을 출력하는 프로그램

while(1)
{
	if(_kbhit())
	{
		nKey = getch();
		printf("%c", nKey);
	}
}

return 0;
... WndProc( ... )
{
	PAINTSTRUCT ps;
	HDC hdc;
	static char string[100] = {0,};
	...
	switch(message)
	{
		...
	**case WM_CHAR :** // 키보드 입력시 입력한 키에 대한 메시지.
		nIndex = strlen(string);
		string[nIndex] = wParam;
		string[nIndex + 1] = NULL;
		InvalidateRect(hWnd, NULL); // hWnd로 들어온 윈도우의 화면을 갱신해달라고 요청. 두번째 매개변수 RECT를 NULL로 주면 전체 화면 갱신.
	**case WM_PAINT :** // 화면을 다시 그릴 때 발생하는 메시지.
		hdc = BeginPaint(hWnd, &ps);
		TextOut(hdc, 10, 10, string, strlen(string));
		EndPaint(hWnd, &ps);
		break;
		...
	}
}

윈도우 명칭