#include <Windows.h>

#include "resource.h"

#include<stdio.h>


LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg,

WPARAM wParam, LPARAM lParam);

#define _CRT_SECURE_NO_WARNINGS


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR IpszCmdLine, 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_QUESTION); //아이콘

WndClass.hCursor = LoadCursor(NULL, IDC_IBEAM); //커서

WndClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH); //뒷 배경

WndClass.lpszMenuName = MAKEINTRESOURCE(IDR_MENU4); //메뉴 이름

WndClass.lpszClassName = "Window Class Name"; //클래스 이름

RegisterClass(&WndClass);

hwnd = CreateWindow("Window Class Name", "4장 2번", WS_OVERLAPPEDWINDOW, 300, 300, 600, 500, NULL, NULL, hInstance, NULL);

ShowWindow(hwnd, 1);          // x좌표 y좌표 폭 높이

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;

OPENFILENAME OFN;

OPENFILENAME SFN;

static bool answer;

static char str+[100];// 한줄당 100글자씩 10줄

static int count, yPos;// 

static SIZE size;

char str2[100] = { "0" }, lpstrFile[100] = "";

char filter[] = "Every File(*,*) \0*.*\0Text File\0*.txt;*.doc\0";


switch (iMsg)

{

case WM_CREATE:

CreateCaret(hwnd, NULL, 5, 15);

ShowCaret(hwnd);

count = yPos = 0;

answer = false;

break;

case WM_PAINT:

hdc = BeginPaint(hwnd, &ps);

for (int i = 0; i < yPos + 1; i++)//지속적인 출력위해 포문돌림

{

GetTextExtentPoint(hdc, str[i], strlen(str[i]), &size);

TextOut(hdc, 0, i * 20, str[i], strlen(str[i]));

SetCaretPos(size.cx, i * 20);

}

EndPaint(hwnd, &ps);

break;

case WM_CHAR:

if (wParam == VK_BACK || count == 100)//백스페이스를 누르면 좌표가 0인경우가아니면 발동, 글자가 100칸채워지면 자동발동

{

if (count > 0)//글자수가 1개일떄부터 지울수있음

count--;

}

else if (wParam == VK_RETURN)//엔터키를 받으면 글자수시작지점(Count)를 0으로 초기화하고, 줄이 10줄이하라면 줄을한칸 추가해 개행한다.

{

count = 0;

if (yPos <= 10)

yPos = yPos + 1;

}

else//그외의 키값은 배열안에 집어넣고 들어올때마다 글자수(count값)을 늘림

str[yPos][count++] = wParam;

str[yPos][count] = '\0';

InvalidateRgn(hwnd, NULL, TRUE);

break;

case WM_COMMAND:

switch (LOWORD(wParam))

{

case ID_FILESAVE:

hdc = GetDC(hwnd);

memset(&SFN, 0, sizeof(OPENFILENAME));

SFN.lStructSize = sizeof(OPENFILENAME);

SFN.hwndOwner = hwnd;

SFN.lpstrFilter = filter;

SFN.lpstrFile = lpstrFile;

SFN.nMaxFile = 1000;

SFN.lpstrInitialDir = ".";

if (GetSaveFileName(&SFN) != 0)

{

wsprintf(str2, "%s 파일로 저장하겠습니까?", SFN.lpstrFile);

answer = MessageBox(hwnd, str2, "저장하기 선택", MB_OK);

if (answer==IDOK)

{

FILE * file = fopen(SFN.lpstrFile, "wt");

for (int i = 0; i < 10; i++)

{

fputs(str[i], file);

fputs("\r\n", file);

if (feof(file) != 0)

break;

}

fclose(file);

ReleaseDC(hwnd, hdc);

}

}

break;

case ID_FILEOPEN:

hdc = GetDC(hwnd);

memset(&OFN, 0, sizeof(OPENFILENAME));

OFN.lStructSize = sizeof(OPENFILENAME);

OFN.hwndOwner = hwnd;

OFN.lpstrFilter = filter;

OFN.lpstrFile = lpstrFile;

OFN.nMaxFile = 100;

OFN.lpstrInitialDir = ",";

if (GetOpenFileName(&OFN) != 0)

{

wsprintf(str2, "%s 파일을 열겠습니까?", OFN.lpstrFile);

answer = MessageBox(hwnd, str2, "열기선택", MB_OK);

if (answer == IDOK)

{

FILE * file = fopen(OFN.lpstrFile, "rt");

if (file == NULL)

{

answer = MessageBox(hwnd, "파일오픈에러", "에러", MB_OK);

break;

}

for (int i = 0; i < 10; i++)

{

fgets(str[i], sizeof(str[i]), file);

if (feof(file) != 0)

break;

}

fclose(file);

ReleaseDC(hwnd, hdc);

}

InvalidateRgn(hwnd, NULL, TRUE);

}

break;

case ID_EXIT:

PostQuitMessage(1);

break;

}

break;

case WM_DESTROY:

HideCaret(hwnd);

DestroyCaret();

PostQuitMessage(0);

break;

}

return DefWindowProc(hwnd, iMsg, wParam, lParam);

}

///////////////////////////////////////////////////////////////////////////////////////////////////
이게 코드고 

아래 사진같이 오류가 뜨는데 저 오류 검색 해보니까 배열크기를 벗어나서 뜨는거라는데 뭘 고쳐줘야 할 지 모르겠어.. 도와줘...