#include <windows.h>
HINSTANCE g_hInst;
LPCTSTR lpszClass = "window program";
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
int WINAPI 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)GetStockObject(WHITE_BRUSH);
WndClass.hCursor = LoadCursor(NULL, IDC_ARROW);
WndClass.hIcon = LoadIcon(NULL, IDI_APPLICATION);
WndClass.hInstance = hInstance;
WndClass.lpfnWndProc = (WNDPROC)WndProc;
WndClass.lpszClassName = lpszClass;
WndClass.lpszMenuName = NULL;
WndClass.style = CS_HREDRAW | CS_VREDRAW;
// 윈도우 클래스 등록
RegisterClass(&WndClass);
// 윈도우 생성
hWnd = CreateWindow(lpszClass, lpszClass, WS_OVERLAPPEDWINDOW, 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 iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc=GetDC(hWnd);
PAINTSTRUCT ps;
static SIZE size;
static int xPos = 0;
static int yPos = 0;
static char str[10][10];
static char temstr[10][10];
static int count = 0;
static int line = 0;
int i,j,temp;
switch (iMsg)
{
case WM_CREATE:
CreateCaret(hWnd, NULL, 5, 15);
ShowCaret(hWnd);
break;
case WM_PAINT:
hdc = BeginPaint(hWnd, &ps);
for (i = 0; i < line + 1; i++) {
GetTextExtentPoint(hdc, str[i], strlen(str[i]), &size);
TextOut(hdc, xPos, 20 * i, str[i], strlen(str[i]));
SetCaretPos(size.cx + xPos, 20 * i);
}
EndPaint(hWnd, &ps);
break;
case WM_CHAR:
if (wParam >= '0' && wParam <= '9') {
if (count != 0)
{
line += 1;
count = 0;
}
str[line][count++] = wParam;
//SetTextColor(hdc,RGB(255,0,0)); 문자 붉게? -모름 1
count = 0;
line += 1;
}
else if (wParam == 'R' || wParam == 'r')
{
(i = line-1; i >=0; i--)
str[i][count] = temstr[line][count]; -모름2
}
else if (wParam == 'Q' || wParam == 'q') {
exit(0);
}
else
{
if (count > 8)
{
line += 1;
count = 0;
}
str[line][count++] = wParam;
}
InvalidateRect(hWnd, NULL, TRUE);
break;
case WM_DESTROY:
HideCaret(hWnd);
DestroyCaret();
PostQuitMessage(0);
break;
}
return (DefWindowProc(hWnd, iMsg, wParam, lParam));
}
내가 모르는 부분이 붉게 칠한 두부분인데
첫번째 부분은 문자가 입력되면 글씨가 붉은색으로 바껴야되는데 안바뀌고
두번째는
1 dfe
2 asd
asd -> 1
dfe 2
이렇게 바껴야되는데 C언어도 4년전에 배운거라(그것도 F맞고 재수강때림)
로직도 잘 못짜겠고, 뭔가 새로운걸 배우니까 더 머리 안돌아가고
중요한건 물어볼 친구가 없어서.. 어떻게 짜야할지 방향좀 알려주셈
textout 하기 전에 글씨색을 설정해야지 븅딱아