vs 2005 编译 windows 程序设计 第三章的简单程序
出现警告
hellowin.cpp(157) : warning C4244: “return”: 从“WPARAM”转换到“int”,可能丢失数据哪位帮忙一下,感谢!
HELLOWIN.C
        
/*------------------------------------------------------------------------
        
  HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
        
                 (c) Charles Petzold, 1998
        
-----------------------------------------------------------------------*/
        
#include <windows.h>
        LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
        int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
        
                   PSTR szCmdLine, int iCmdShow)
        
{
        
    static TCHAR szAppName[] = TEXT ("HelloWin") ;
        
    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_APPLICATION) ;
        
  wndclass.hCursor      = LoadCursor (NULL, IDC_ARROW) ;
        
   wndclass.hbrBackground= (HBRUSH) GetStockObject (WHITE_BRUSH) ;
        
  wndclass.lpszMenuNam  = NULL ;
        
    wndclass.lpszClassName= szAppName ;
            if (!RegisterClass (&wndclass))
        
    {
        
            MessageBox (  NULL, TEXT ("This program requires Windows NT!"),
        
                                  szAppName, MB_ICONERROR) ;
        
            return 0 ;
        
    }
        
    hwnd = CreateWindow( szAppName,      // window class name
        
                   TEXT ("The Hello Program"),   // window caption
        
                   WS_OVERLAPPEDWINDOW,  // window style
        
                   CW_USEDEFAULT,// initial x position
        
                   CW_USEDEFAULT,// initial y position
        
                   CW_USEDEFAULT,// initial x size
        
                   CW_USEDEFAULT,// initial y size
        
                   NULL,                 // parent window handle
        
               NULL,            // window menu handle
        
               hInstance,   // program instance handle
        
               NULL) ;      // creation parameters
        
   
        
    ShowWindow (hwnd, iCmdShow) ;
        
    UpdateWindow (hwnd) ;
        
   
        
    while (GetMessage (&msg, NULL, 0, 0))
        
    {
        
            TranslateMessage (&msg) ;
        
          DispatchMessage (&msg) ;
        
    }
        
    return msg.wParam ;
        
}
        LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        
{
        
    HDC                   hdc ;
        
    PAINTSTRUCT ps ;
        
    RECT          rect ;
        
   
        
    switch (message)
        
    {
        
    case WM_CREATE:
        
    PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
        
            return 0 ;
            case   WM_PAINT:
        
            hdc = BeginPaint (hwnd, &ps) ;
        
        
        
            GetClientRect (hwnd, &rect) ;
        
        
        
            DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
        
                   DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
        
                 EndPaint (hwnd, &ps) ;
        
                   return 0 ;
        
        
        
    case   WM_DESTROY:
        
            PostQuitMessage (0) ;
        
            return 0 ;
        
    }
        
  return DefWindowProc (hwnd, message, wParam, lParam) ;
        
}

解决方案 »

  1.   

    VS2005对于数据格式的要求变得很高了,前面加上(int)应该就可以了
      

  2.   

    不用管
    或int WINAPI WinMain 
    改成
    void WINAPI WinMain, 去掉最后的返回
      

  3.   

    return msg.wParam;这个何意?
      

  4.   

    WINAPI   WinMain   
    改成 
    void   WINAPI   WinMain,   去掉最后的返回 后e:\cproj\windows程序设计\3hellowin\3hellowin\3hellowin.cpp(32) : error C2556: “void WinMain(HINSTANCE,HINSTANCE,LPSTR,int)”: 重载函数与“int WinMain(HINSTANCE,HINSTANCE,LPSTR,int)”只是在返回类型上不同
    1>        d:\program files\microsoft visual studio 8\vc\platformsdk\include\winbase.h(1875) : 参见“WinMain”的声明
    1>e:\cproj\windows程序设计\3hellowin\3hellowin\3hellowin.cpp(32) : error C2371: “WinMain”: 重定义;不同的基类型
    1>        d:\program files\microsoft visual studio 8\vc\platformsdk\include\winbase.h(1875) : 参见“WinMain”的声明3hellowin.cpp(334) : warning C4715: “WinMain”: 不是所有的控件路径都返回值
      

  5.   

    return msg.wParam; --> return (int)msg.wParam;
      

  6.   

    感谢,thisisyjs.问题终于解决了。