#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[100][100];
static int count, yPos, ycnt, xPos;
static SIZE size;
int idx;
switch (iMsg)
{
case WM_CREATE:
count = 0;
yPos = 0;
xPos = 0;
CreateCaret(hwnd, NULL, 5, 15);
ShowCaret(hwnd);
break;
case WM_KEYDOWN:
switch(wParam)
{
case VK_DOWN:
yPos += 20;
break;
case VK_UP:
yPos -= 20;
break;
case VK_LEFT:
break;
case VK_RIGHT:
break;
}
case WM_PAINT:
idx = 0;
hdc = BeginPaint(hwnd, &ps);
while ( idx <= ycnt){
GetTextExtentPoint(hdc, str [idx], strlen(str [idx]), &size);
TextOut(hdc, 0, idx * 20, str [idx], strlen(str [idx]));
idx++;
SetCaretPos(size.cx, yPos);
}
EndPaint(hwnd, &ps);
break;
case WM_CHAR:
if (wParam == VK_BACK) count--;
else if (wParam == VK_RETURN)
{
count = 0;
ycnt++;
yPos = yPos + 20;
}
else
str[ycnt][count++] = wParam;
str[ycnt][count] = '\0';
InvalidateRgn(hwnd, NULL, TRUE);
break;
case WM_DESTROY:
HideCaret(hwnd);
DestroyCaret();
PostQuitMessage(0);
break;
}
return(DefWindowProc(hwnd, iMsg, wParam, lParam));
}
이렇게 짰는데요.. Caret을 적히는 문자에 맞춰 이동시키다보니 size.cx를 x좌표로 하는데.. y좌표는 yPos.
문제는 방향키로 Caret을 원하는위치로 이동시켜야 하는데 y좌표가 지정되어있는 yPos는 손쉽게 +-20으로 UP, DOWN을 작동시켰습니다만..
LEFT, RIGHT가 안됩니다 ㅠㅠ
따로 xPos로 줘서 이동시킬려니 Caret이 문자에 따라 맞춰서 이동이 안됩니다 ㅠㅠ
어떻게 해야하나요?