注册 登录
编程论坛 C++教室

求救:error C2731: 'WinMain' : function cannot be overloaded:急

xgoshawk 发布于 2008-03-04 20:08, 2521 次点击
#include<windows.h>
#include<stdio.h>
//#include<stdafx.h>

LRESULT CALLBACK WinSunProc(
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
);

int WINAPI WinMain(
  HINSTANCE hInstance,
  HINSTANCE hPrevInstance,
  LPWSTR lpCmdLine,
  int nShowCmd
)
{
    WNDCLASS wndcls;
    wndcls.cbClsExtra=0;
    wndcls.cbWndExtra=0;
    wndcls.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
    wndcls.hCursor=LoadCursor(NULL,IDC_CROSS);
    wndcls.hIcon=LoadIcon(NULL,IDI_ERROR);
    wndcls.hInstance=hInstance;
    wndcls.lpfnWndProc=WinSunProc;
    wndcls.lpszClassName="weixin2003";
    wndcls.lpszMenuName=NULL;
    wndcls.style=CS_HREDRAW|CS_VREDRAW;
    RegisterClass(&wndcls);

    HWND hwnd;
    hwnd=CreateWindow("weixin2003","北京维新",WS_OVERLAPPEDWINDOW,0,0,600,400,NULL,NULL,hInstance,NULL);
    ShowWindow(hwnd,SW_SHOWNORMAL);
    UpdateWindow(hwnd);


    MSG msg;
    while(GetMessage(&msg,NULL,0,0))
    {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
    return 0;
}

LRESULT CALLBACK WinSunProc(
  HWND hwnd,
  UINT uMsg,
  WPARAM wParam,
  LPARAM lParam
)
{
    switch(uMsg)
    {
          case WM_CHAR:
              char szchar[20];
              sprintf(szchar,"char is %d",wParam);
              MessageBox(hwnd,szchar,"weixin",0);
          break;
          case WM_LBUTTONDOWN:
              MessageBox(hwnd,"mouse clicked","weixin",0);
              HDC hdc;
              hdc=GetDC(hwnd);
              TextOut(hdc,0,50,"边城",strlen("边城"));
              ReleaseDC(hwnd,hdc);
          break;
          case WM_PAINT:
              HDC hDC;
              PAINTSTRUCT ps;
              hDC=BeginPaint(hwnd,&ps);
              TextOut(hDC,0,0,"维新培训",strlen("维新培训"));
              EndPaint(hwnd,&ps);
          break;
          case WM_CLOSE:
              if(IDYES==MessageBox(hwnd,"关闭?","weixin",MB_YESNO))
              {
                 DestroyWindow(hwnd);
              }
          break;
          case WM_DESTROY:
                PostQuitMessage(0);
          break;
          default:
              return DefWindowProc(hwnd,uMsg,wParam,lParam);
    }
    return 0;
}

编译时:
c:\c_practice\winmain\winmain.cpp(18) : error C2731: 'WinMain' : function cannot be overloaded
        c:\c_practice\winmain\winmain.cpp(12) : see declaration of 'WinMain'
执行 cl.exe 时出错.
Creating browse info file...

winmain.exe - 1 error(s), 0 warning(s)

不知道为什么,我也是抄教科书上的。谢了
1 回复
#2
sunkaidong2008-03-04 20:32
int WINAPI WinMain(
  HINSTANCE hInstance,  // handle to current instance
  HINSTANCE hPrevInstance,  // handle to previous instance
  LPSTR lpCmdLine,      // pointer to command line
  int nCmdShow          // show state of window
)
1