조건
- 10글자되면 자동 개행
- 5줄되면 끝내기
#include <windows.h>
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdLine, int nCmdShow)
{
HWND hwnd;
MSG msg;
WNDCLASS WndClass;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = WndProc;
WndClass.cbClsExtra = 0;
WndClass.cbWndExtra = 0;
WndClass.hInstance = hInstance;
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.lpszMenuName = NULL;
WndClass.lpszClassName = "Window Class Name";
RegisterClass(&WndClass);
hwnd = CreateWindow("Window Class Name",
"Window Title Name",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
ShowWindow(hwnd, nCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,
WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
static char str[5][11];
static int count, yPos, line;
int i,answer;
switch (iMsg)
{
case WM_CREATE:
count = 0;
line=0;
yPos = 0;
break;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
for(i=0; i<5; i++){
TextOut(hdc, 0, i*20, str[i], strlen(str[i]));
}
EndPaint(hwnd, &ps);
break;
case WM_CHAR:
if (wParam == VK_BACK)
count--;
else if (wParam == VK_RETURN)
{
count = 0;
line++;
if(line==5)
{
answer = MessageBox(hwnd, "끝", "끝", MB_OKCANCEL);
PostQuitMessage(0);
}
}
else
{
if(count==10)
{
line++;
if(line==5)
{
answer = MessageBox(hwnd, "끝", "끝", MB_OKCANCEL);
PostQuitMessage(0);
}
else
count=0;
}
str[line][count++] = (TCHAR)wParam;
str[line][count] = 0;
InvalidateRgn(hwnd, NULL, FALSE);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
}
return(DefWindowProc(hwnd, iMsg, wParam, lParam));
}
출력 결과
'3-1 > 윈도우즈프로그래밍' 카테고리의 다른 글
2장 연습문제 1번 (0) | 2011.03.23 |
---|