Your wndproc is falling through to WM_DESTROY whenever it gets a WM_KEYDOWN message due to the way you've wriiten your break statements and closing braces. This will allow text input (the only WM_KEYDOWN that has any effect on the text is VK_BACK) -
Code:
long FAR PASCAL WndProc(HWND hWnd ,UINT wMessage,WPARAM wParam,LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hDC;
POINT pt;
TEXTMETRIC tm;
static int nCurPos=0;
static char cBuf[128];
static int nwidth,nheight;
static HFONT hFont,hOldFont;
switch(wMessage)
{
case WM_CREATE:
CreateCaret(hWnd,NULL,10,10);
ShowCaret(hWnd);
SetCaretPos(0,0);
hDC=GetDC(hWnd);
GetTextMetrics(hDC,&tm);
ReleaseDC(hWnd,hDC);
nwidth=tm.tmAveCharWidth;
nheight=tm.tmHeight;
break;
case WM_PAINT:
hDC=BeginPaint(hWnd,&ps);
SetTextColor(hDC,RGB(0,0,255));
TextOut(hDC,0,0,cBuf,lstrlen(cBuf));
SelectObject(hDC,hOldFont);
EndPaint(hWnd,&ps);
break;
case WM_CHAR:
if(nCurPos<127&&(IsCharAlphaNumeric((char)wParam)))
{
cBuf[nCurPos++]=(char)wParam;
cBuf[nCurPos]=0;
InvalidateRect(hWnd,NULL,TRUE);
}
break;
case WM_KEYDOWN:
GetCaretPos(&pt);
switch(wParam)
{
case VK_LEFT:
pt.x-=nwidth;
break;
case VK_RIGHT:
pt.x+=nwidth;
break;
case VK_UP:
pt.y-=nheight;
break;
case VK_DOWN:
pt.y+=nheight;
break;
case VK_HOME:
pt.y=0;
pt.x=0;
break;
case VK_END:
pt.y=1;
pt.x=1;
break;
case VK_BACK:
if(nCurPos>0)
{
nCurPos--;
cBuf[nCurPos]=0;
InvalidateRect (hWnd,NULL,TRUE);
}
break;
}
SetCaretPos(pt.x,pt.y);
break;
case WM_DESTROY:
DestroyCaret();
PostQuitMessage(0);
break;
default:
return DefWindowProc (hWnd,wMessage,wParam,lParam);
}
return 0;
}