#include"windows.h"#include<vector>using namespace std;LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam);
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int CmdShow){
HWND hwnd;
WNDCLASS wndclass;
MSG message;
char lpszClassName[]="caret";
char lpszTitleName[]="插入符号";//变量的定义 wndclass.cbClsExtra=0;
wndclass.cbWndExtra=0;
wndclass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
wndclass.hCursor=(HCURSOR)LoadCursor(NULL,IDC_ARROW);
wndclass.hIcon=(HICON)LoadIcon(NULL,IDI_APPLICATION);
wndclass.hInstance=hInstance;
wndclass.lpfnWndProc=WndProc;
wndclass.lpszClassName=lpszClassName;
wndclass.lpszMenuName=NULL;
wndclass.style=CS_VREDRAW|CS_HREDRAW;//窗口类的定义 if(!RegisterClass(&wndclass))
{
MessageBeep(0);
return 0;
}//注册窗口类 hwnd=CreateWindow(lpszClassName,lpszTitleName,WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);//窗口的创建 ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);//绘制窗口的显示区域
while(GetMessage(&message,hwnd,0,0))
{
TranslateMessage(&message);
DispatchMessage(&message);
} return 0;}LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam){
HDC hdc;
static int cxclient,cyclient,cxchar,cychar,xcaret,ycaret;
int x,y,i;
PAINTSTRUCT ps;
TEXTMETRIC tm;
RECT rect={0,0,cxclient,cyclient};
POINT pt;
vector<TCHAR>word[500]; switch(message)
{
case WM_CREATE:
hdc=GetDC(hwnd); GetTextMetrics(hdc,&tm); cxchar=tm.tmAveCharWidth;
cychar=tm.tmExternalLeading+tm.tmHeight; ReleaseDC(hwnd,hdc); for(y=0;y<500;y++)
{
for(x=0;x<500;x++)
{
word[y].push_back(' ');
}

}
return 0; case WM_SIZE:
cxclient=LOWORD(lParam);
cyclient=HIWORD(lParam); xcaret=0;
ycaret=0;
if(hwnd==GetFocus())
SetCaretPos(cxchar*xcaret,cychar*ycaret);
InvalidateRect(hwnd,&rect,TRUE); return 0; case WM_SETFOCUS: CreateCaret(hwnd,NULL,0,cychar);
SetCaretPos(0,0);
ShowCaret(hwnd); return 0; case WM_KILLFOCUS:
HideCaret(hwnd);
DestroyCaret();
return 0; case WM_KEYDOWN:
for(i=0;i<LOWORD(lParam);i++)
{
switch(wParam)
{
case VK_HOME:
xcaret=0;
break;
case VK_END:
xcaret=(cxclient-1);
break;
case VK_UP:
if(0!=ycaret)
ycaret--;
else
MessageBeep(0);
break;
case VK_DOWN:
if(cyclient/cychar==ycaret)
MessageBeep(0);
else
ycaret++;
break;
case VK_LEFT:
if(0==xcaret)
MessageBeep(0);
else
xcaret--;
break;
case VK_RIGHT:
if((cxclient/cxchar-1)!=xcaret)
xcaret++;
else
MessageBeep(0);
break;
case VK_NEXT:
ycaret=cyclient/cychar;
break;
case VK_PRIOR:
ycaret=0;
break;
} } SetCaretPos(xcaret*cxchar,ycaret*cychar);
return 0; case WM_CHAR:
hdc=GetDC(hwnd);
HideCaret(hwnd);
for(i=0;i<LOWORD(lParam);i++)
{
GetCaretPos(&pt);
word[(pt.y/cychar)][(pt.x/cxchar)]=(TCHAR)wParam;
if(xcaret!=cxclient)
xcaret++;
else
ycaret++;
SetCaretPos(xcaret*cxchar,ycaret*cychar);
}
ReleaseDC(hwnd,hdc);
ShowCaret(hwnd);
return 0; case WM_PAINT:
hdc=BeginPaint(hwnd,&ps); for(y=0;y<cyclient/cychar;y++)
{
for(x=0;x<cxclient/cxchar;x++)
{
TextOut(hdc,x*cxchar,y*cychar,&word[y][x],1);
}
} HideCaret(hwnd);
SetCaretPos(0,0);
ShowCaret(hwnd);
EndPaint(hwnd,&ps);
return 0; case WM_DESTROY:
ExitProcess(0);return 0; default:
return DefWindowProc(hwnd,message,wParam,lParam); } return 0;
}
在调试的时候 WM_PAINT中的循环 在第二次进入的时候 显示 0xC0000005: Access Violation.怎么回事啊 麻烦会的人解释下啊