下面是一个例子,我在其中加了一点东西,想让他在客户区能输出点东西来,可是编译时有错误,请帮我看一下!谢谢!#include <windows.h>#if MSC_VER >=700
#progma warning (disable:4028)
#endifBOOL FirstInit (HANDLE);
LRESULT CALLBACK  FirstWndProc(HWND,unsigned int,unsigned int,LONG);int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
MSG msg;
HWND hWnd; if(! hPrevInstance)
{
if(! FirstInit(hInstance))
return FALSE;
} hWnd = CreateWindow("First",
"This is my first application",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0,
CW_USEDEFAULT,
0,
NULL,
NULL,
hInstance,
NULL); /*中间这段是我加上去的编译有问题*/
HDC hDC;
PAINTSTRUCT ps; hDC = BeginPaint(hWnd,&ps);
TextOut(hDC,12,34,"hello",5);
EndPaint(hWnd,&ps);
/*******************************/ ShowWindow(hWnd,nCmdShow);
UpdateWindow( hWnd ); while(GetMessage(&msg,NULL,0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return (int)msg.wParam;}BOOL FirstInit(HINSTANCE hInstance)
{
WNDCLASS weFirstClass; weFirstClass.hCursor = LoadCursor(NULL,IDC_ARROW);
weFirstClass.hIcon = LoadIcon(NULL,IDI_APPLICATION);
weFirstClass.lpszMenuName = NULL;
weFirstClass.lpszClassName = "First";
weFirstClass.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
weFirstClass.hInstance = hInstance;
weFirstClass.style =0;
weFirstClass.lpfnWndProc = FirstWndProc;
weFirstClass.cbClsExtra = 0;
weFirstClass.cbWndExtra = 0; if(! RegisterClass(&weFirstClass))
return FALSE;
return TRUE;
}LRESULT CALLBACK  FirstWndProc(HWND hWnd,unsigned int message,unsigned int wParam,LONG lParam)
{
switch (message)
{
case WM_DESTROY:
PostQuitMessage(0);

default:
return (DefWindowProc(hWnd,message,wParam,lParam));
break;
}
return  S_OK;
}

解决方案 »

  1.   

    WM_PAINT:
    /*中间这段是我加上去的编译有问题*/
    HDC hDC;
    PAINTSTRUCT ps; hDC = BeginPaint(hWnd,&ps);
    TextOut(hDC,12,34,"hello",5);
    EndPaint(hWnd,&ps);
    /*******************************/
    break;
      

  2.   

    你把问题段移到
    LRESULT CALLBACK  FirstWndProc(HWND hWnd,unsigned int message,unsigned int wParam,LONG lParam)
    {
        case WM_PAINT:
         ........
    }
    hDC = BeginPaint(hWnd,&ps);//得到hDC
    EndPaint(hWnd,&ps);       //删除WM_PAINT
    是处理 WM_PAINT 消息的,现在还没有WM_PAINT消息你怎么办?
      

  3.   

    好象加的位置不对。
    加的位置前窗体还没有显示出来。
    我觉得应该这样:
    LRESULT CALLBACK  FirstWndProc(HWND hWnd,unsigned int message,unsigned int wParam,LONG lParam)
    {
      ...
    case WM_PAINT:
      加的代码
      ...
    }
      

  4.   

    我现在这么做了,可还是有错:
    case WM_PAINT:
    HDC hDC;
    break;错误如下:
    --------------------Configuration: first - Win32 Debug--------------------
    Compiling...
    first.c
    G:\sample\first.c(90) : error C2275: 'HDC' : illegal use of this type as an expression
            d:\program files\microsoft visual studio\vc98\include\windef.h(239) : see declaration of 'HDC'
    G:\sample\first.c(90) : error C2146: syntax error : missing ';' before identifier 'hDC'
    G:\sample\first.c(90) : error C2065: 'hDC' : undeclared identifier
    Error executing cl.exe.
    Creating browse info file...first.exe - 3 error(s), 0 warning(s)
      

  5.   

    修改之后的,我这里是没问题了。
    LRESULT CALLBACK  FirstWndProc(HWND hWnd,unsigned int message,unsigned int wParam,LONG lParam)
    {
    HDC hDC;
    PAINTSTRUCT ps;
    switch (message)
    {
    case WM_DESTROY:
    PostQuitMessage(0);
    case WM_PAINT: hDC = BeginPaint(hWnd,&ps);
    TextOut(hDC,12,34,"hello",5);
    EndPaint(hWnd,&ps);
    default:
    return (DefWindowProc(hWnd,message,wParam,lParam));
    break;
    }
    return  S_OK;
    }