#include<windows.h>
#include<stdio.h>
  
LRESULT CALLBACK WinSunProc(
  HWND hwnd, 
  UINT uMsg, 
  WPARAM wParam, 
  LPARAM lParam 
); int WINAPI WinMain(
  HINSTANCE hInstance, 
  HINSTANCE hPrevInstance, 
  LPWSTR lpCmdLine, 
  int nShowCmd )
{
   WNDCLASS wndclas;
   wndclas.cbClsExtra=0;
   wndclas.cbWndExtra=0;
   wndclas.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
   wndclas.hCursor=LoadCursor(NULL,IDC_CROSS);
   wndclas.hIcon=LoadIcon(NULL,IDI_ERROR);
   wndclas.hInstance=hInstance;
   wndclas.lpfnWndProc=WinSunProc;
   wndclas.lpszClassName="weixin2003";
   wndclas.lpszMenuName=NULL;
   wndclas.style=CS_VREDRAW|CS_HREDRAW;
   
   RegisterClass(&wndclas);   HWND hwnd;
   hwnd=CreateWindow("weixin2003","计算机中心!",
   WS_OVERLAPPEDWINDOW,0,0,400,
   600,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,"yingying",strlen("yingying"));
ReleaseDC(hwnd,hdc);
break;
case WM_PAINT:
        HDC hDC;
        PAINTSTRUCT ps;
hdc=BeginPaint(hwnd,&ps);
TextOut(hDC,0,50,"woaini",strlen("woaini"));
EndPaint(hwnd,&ps);
break;
case WM_CLOSE:
if(IDYES==MessageBox(hwnd,"break is yes or no!","weixin",MB_YESNO))
{
DestroyWindow(hwnd);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd,uMsg,wParam,lParam);

}    return 0;
  
};
//一个简单的vc程序 错误很奇怪!WinMian出错!请
//大家帮帮忙!!

解决方案 »

  1.   

    case WM_PAINT:
            HDC hDC;
            PAINTSTRUCT ps;
    hdc=BeginPaint(hwnd,&ps);
    TextOut(hDC,0,50,"woaini",strlen("woaini"));
    EndPaint(hwnd,&ps);
    break;首先你这里的hDC错了.hdc=BeginPaint(hwnd,&ps);自己看清楚吧.而且相信还有其他地方有错.洗澡了.
      

  2.   

    报什么错?
    sprintf(szChar,"char is d%",wParam);
    这里应该是:
    sprintf(szChar,"char is %d",wParam);
    WM_PAINT里面hDC大小写错误。
      

  3.   

    哦谢谢了还有好多错的。---------------Configuration: vc1 - Win32 Debug--------------------
    Compiling...
    vc1.cpp
    D:\study\vc\vc1.cpp(16) : error C2731: 'WinMain' : function cannot be overloaded
            D:\study\vc\vc1.cpp(11) : see declaration of 'WinMain'
    执行 cl.exe 时出错.vc1.obj - 1 error(s), 0 warning(s)
      

  4.   

    你的WinMain函数定义有错误,标准的WinMain 应该是:
    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
    )这个格式是完全不能够该得。
    你将你的第三个参数的类型改为LPSTR 试一试。
      

  5.   

    LPWSTR lpCmdLine, => LPSTR lpCmdLine,
      

  6.   

    谢谢前面的兄弟呀我去试一试呀,可是又出现了新问题呀/--------------------Configuration: vc1 - Win32 Debug--------------------
    Linking...
    LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main
    Debug/vc1.exe : fatal error LNK1120: 1 unresolved externals
    执行 link.exe 时出错.vc1.exe - 1 error(s), 0 warning(s)
      

  7.   

    Project settings -> C/C++ -> Preprocessor ,然后把_CONSOLE 改成 _WINDOWS ,确定后重新编译就行了。
      

  8.   

    谢谢大家呀。不过楼上兄弟所说把_CONSOLE 改成 _WINDOWS 还是不行的。