//test.cpp 
#include <windows.h> 
#include<stdlib.h>
#include<string.h>
//LRESULT CALLBACK WndProc( HWND hWnd, UINT iMessage, WPARAM wParam, LONG  lParam);
BOOL InitWindowsClass(HINSTANCE hInstance);
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow);
LRESULT CALLBACK WndProc( HWND hWnd, UINT iMessage, UINT wParam,LONG lParam ) 

static long nXChar,nCaps,nYChar;
HDC hDC;
short x;
TEXTMETRIC tm;
short LnCount=6;
PAINTSTRUCT PtStr;
static char *textbuf[]=
{
 "This is 1 line",
 "This is 2 line",
 "This is 3 line",
 "This is 4 line",
 "This is 5 line",
 "This is 6 line"
 
};
switch(iMessage)
{
case WM_CREATE:
hDC=GetDC(hWnd);
GetTextMetrics(hDC,&tm);
nXChar=tm.tmAveCharWidth;
nYChar=tm.tmHeight+tm.tmExternalLeading;
ReleaseDC(hWnd,hDC);
return 0;
case WM_PAINT:
hDC=BeginPaint(hWnd,&PtStr);
for(x=0;x<LnCount;x=x+1)
TextOut(hDC,nXChar,nYChar*(1+x),textbuf[x],lstrlen(textbuf[x]));
EndPaint(hWnd,&PtStr);
return 0;
case WM_DESTROY: 
PostQuitMessage(0); 
return 0;
default:
  return (DefWindowProc(hWnd,iMessage,wParam,lParam)); 

int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )

MSG Message;
if(!InitWindowsClass(hInstance))
return FALSE;
if(!InitWindows(hInstance,nCmdShow))
return FALSE;
while(GetMessage(&Message,0,0,0))

TranslateMessage(&Message); 
DispatchMessage(&Message); 
} return Message.wParam; 


BOOL InitWindowsClass(HINSTANCE hInstance)
{
WNDCLASS WndClass; 
WndClass.cbClsExtra=0; 
WndClass.cbWndExtra=0;
WndClass.hbrBackground=(HBRUSH)GetStockObject(WHITE_BRUSH);
WndClass.hCursor=LoadCursor(NULL,IDC_ARROW);
WndClass.hIcon=LoadIcon(NULL,"END");  
WndClass.hInstance=hInstance;
WndClass.lpfnWndProc=WndProc;
WndClass.lpszClassName="wintext";
WndClass.lpszMenuName=NULL;
WndClass.style= CS_HREDRAW|CS_VREDRAW;
return RegisterClass(&WndClass);
}
BOOL InitWindows(HINSTANCE hInstance,int nCmdShow)
{
 HWND hWnd;
 hWnd=CreateWindow(
"文本", 
"文本显示实例", 
WS_OVERLAPPEDWINDOW, 
CW_USEDEFAULT, 
0, 
CW_USEDEFAULT, 
     0, 
NULL, 
NULL, 
hInstance, 
NULL); 
 if(!hWnd)
 return FALSE;ShowWindow(hWnd,nCmdShow); 
UpdateWindow(hWnd); 
return TRUE;}
不知道什么地方错了

解决方案 »

  1.   

    WndClass.lpszClassName="wintext";hWnd=CreateWindow(
    "文本",  
    "文本显示实例",  
    -->hWnd = CreateWindow("wintext", ...);
      

  2.   

    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )
    {  
    MSG Message;
    if(!InitWindowsClass(hInstance))
    return FALSE;
    if(!InitWindows(hInstance,nCmdShow))
    return FALSE;
    while(GetMessage(&Message,0,0,0))
    {  
    TranslateMessage(&Message);  
    DispatchMessage(&Message);  
    }  return Message.wParam;  
    }  把这一个整个提到外面来
      

  3.   

    把switch(iMessage)那段放到
    int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow )这一段后面