#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
HINSTANCE g_hInst;
LPCTSTR lpszClass = TEXT("Window class Name");
LPCTSTR lpszWindowName = TEXT("windows program 2-1");
LRESULT CALLBACK WndProc(HWND hWND, UINT Umsg, WPARAM wParam, LPARAM IParam);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevlnstance, LPSTR lpszCmdParam, int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASSEX WndClass;
g_hInst = hInstance;
WndClass.cbSize = sizeof(WndClass);
WndClass.style = CS_HREDRAW | CS_VREDRAW;
WndClass.lpfnWndProc = (WNDPROC)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 = lpszClass;
WndClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&WndClass);
hWnd = CreateWindow(lpszClass, lpszWindowName, WS_OVERLAPPED | WS_SYSMENU, 0, 0, 800, 600, NULL, (HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
while (GetMessage(&Message, 0, 0, 0)) {
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return Message.wParam;
}
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {
PAINTSTRUCT ps;
HDC hDC;
static SIZE size;
static char str[10][81];
static char temp[10][81];
static int count = 0;
static int yPos, xPos;
static int line;
static int temp_line, temp_count;
static int i = 0;
static int n = 0;
static int j = 0;
static int cxFont, cyFont;
switch (uMsg) {
case WM_CREATE:
yPos = 0;
xPos = 0;
line = 0;
count = 0;
temp_line = 0;
temp_count = 0;
CreateCaret(hWnd, NULL, 3, 15);
ShowCaret(hWnd);
break;
case WM_CHAR:
if (wParam == VK_BACK) {
if (count > 0)
count--;
else if (line > 0 && count == 0) {
line--;
count = strlen(str[line]);
yPos -= 20;
temp_line--;
}
}
else if (wParam == VK_RETURN) {
if (line < 9) {
yPos += 20;
count = 0;
line++;
temp_line++;
}
}
else str[line][count++] = wParam;
str[line][count] = '\0';
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_KEYDOWN:
switch (wParam)
{
case VK_LEFT:
xPos -= 5;
break;
case VK_RIGHT:
xPos += 5;
break;
case VK_UP:
yPos -= 20;
break;
case VK_DOWN:
yPos += 20;
break;
case VK_DELETE:
for (j = 0; j < 2; j++) {
for (i = 0; i < count; ++i) {
str[line - j][strlen(str[line - j]) + i] = str[line][i];
}
}
--line;
str[line][strlen(str[line])] = '\0';
count = strlen(str[line]);
yPos -= 20;
xPos -= count * 8;
break;
}
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_PAINT:
hDC = BeginPaint(hWnd, &ps);
GetTextExtentPoint(hDC, str[line], strlen(str[line]), &size);
for (i = 0; i < line + 1; ++i)
TextOut(hDC, 0, i * 20, str[i], strlen(str[i]));
SetCaretPos(xPos + size.cx, yPos);
EndPaint(hWnd, &ps);
break;
case WM_DESTROY:
HideCaret(hWnd);
DestroyCaret();
PostQuitMessage(0);
break;
}
return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
여기서 방향키로 캐럿을 움직이면 캐럿 위치에 입력하는 글자가 나오게 하고싶은데 어떻게 해야되나요ㅠㅠ VK_UP,DOWN,LEFT,RIGHT에서 캐럿 움직이는건 했는데..입력하면 글자가 끝에서 부터 나오네요..