API인데.....계속 막히는 부분이 있습니다...도와주세요 ㅠㅠ
아래 처럼 요렇게 짰는데...출력하면 네모박스안에서
글을 입력할 수가 있는데....네모박스안에서 한줄을 입력하면 다음 줄로 넘어가야되는데 이상하게...한줄로만 나오네요 ㅠ
어느 부분을 수정해야되나요?
아무리 해도 ㅠㅠ
#include
LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam) ;
HINSTANCE g_hInst;
char lpszClass[100]="API Program Ex06";
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpszCmdLine,int nCmdShow)
{
HWND hWnd;
MSG Message;
WNDCLASS WndClass;
//ZeroMemory(&WndClass,sizeof(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);
RegisterClass(&WndClass);
hWnd=CreateWindow(lpszClass,lpszClass,WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 800, 600, NULL ,(HMENU)NULL, hInstance, NULL);
ShowWindow(hWnd,nCmdShow);
while(GetMessage(&Message,0,0,0)){
TranslateMessage(&Message);
DispatchMessage(&Message);
}
return (int)Message.wParam;
}
#define LEFT 100
#define TOP 100
#define RIGHT 300
#define BOTTOM 200
LRESULT CALLBACK WndProc (HWND hWnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
static char str[10][50];
static int count,line,yPos;
static SIZE size;
int i;
switch (iMsg)
{
case WM_CREATE:
count=0;
line=0;
yPos=0;
CreateCaret(hWnd,NULL,5,15);
ShowCaret(hWnd);
return 0;
case WM_PAINT:
hdc=BeginPaint(hWnd,&ps);
yPos=0;
Rectangle(hdc, LEFT,TOP, RIGHT,BOTTOM);
for(i=0; i
TextOut(hdc,LEFT+0, TOP+i*yPos, str[i],strlen(str[i]));
GetTextExtentPoint(hdc,str[line], strlen(str[i]),&size);
TextOut(hdc,LEFT+0, TOP+i*yPos, str[i],strlen(str[i]));
SetCaretPos(LEFT+size.cx,TOP+line*yPos);
yPos+=20;
EndPaint(hWnd,&ps);
break;
case WM_CHAR:
if(wParam == (VK_BACK))
count--;
else if(wParam == VK_RETURN)
{
count = 0;
line = line + 1;
}
else
str[line][count++]=wParam;
hdc = GetDC(hWnd);
GetTextExtentPoint(hdc, str[line], count, &size);
ReleaseDC(hWnd, hdc);
if(size.cx > RIGHT - LEFT)
{
str[line +1][0] = str[line][count-1];
str[line][count-1]='\0';
line++;
count = 1;
}
str[line][count] = '\0';
if((line+1)*yPos > BOTTOM - TOP)
{
MessageBox(hWnd, "글상자가 가득 찼습니다.","글상자",MB_OK);
break;
}
InvalidateRgn(hWnd, NULL, TRUE);
return 0;
case WM_DESTROY:
HideCaret(hWnd);
DestroyCaret();
PostQuitMessage (0) ;
break;
}
return DefWindowProc (hWnd, iMsg, wParam, lParam);
}
첨부 | 파일 크기 |
---|---|
![]() | 2.76 KB |
case WM_PAINT 아래에 yPos =
case WM_PAINT 아래에 yPos = 0해버리면 for룹안의 TextOut에서 TOP+i*yPos는 항상 TOP이 되어 항상 같은 높이에 찍히는듯 하고, 커서위치시키는 부분도 문제가 있어 보입니다.
^^
네...감사해요...도움이 되었네요 ^^;
댓글 달기