#include <Windows.h>
#include <stdio.h>LRESULT CALLBACK les1(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
);
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
)
{WNDCLASS wndclass
  wndclass.cbClsExtra=0;
  wndclass.cbWndExtra=0;
  wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
  wndclass.hCursor=Loadcursor(NULL,IDC_IBEAM);
  wndclass.hIcon=LoadIcon(NULL,IDI_HAND);
  wndclass.hInstance=hInstance;
  wndclass.lpfnWndProc=Les1;
  wndclass.lpszClassName=lesson1;
  wndclass.style=CS_HREDRAW|CS_VREDRAW;
  wndclass.lpszMenuName=NULL;
 
  RegisterClass(&wndclass);  HWND hwnd;
  hwnd=HWND CreateWindow("lesson1","刘向培",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 les1(
  HWND hwnd,      // handle to window
  UINT uMsg,      // message identifier
  WPARAM wParam,  // first message parameter
  LPARAM lParam   // second message parameter
  )
  {
  Switch(uMsg)
  {
  case WM_CHAR:
  char xp[20];
  sprintf(xp,"xp Press %d",wParam);
  MessageBox(hwnd,xp,"No 1",0);
     
  break;   default:
  return DefWindowProc(hwnd,uMsg,wParam,lParam);
  }  return 0;
  }

解决方案 »

  1.   

    WNDCLASS wndclass------>>添加“;”
    Loadcursor(NULL,IDC_IBEAM);--->>LoadCursor注意大小写
    wndclass.lpfnWndProc=Les1;---->>les1注意大小写
    wndclass.lpszClassName=lesson1;----->>"lesson1"添加双引号
     hwnd=HWND CreateWindow("lesson1","刘向培",WS_OVERLAPPEDWINDOW,----->>去掉HWND
       0,0,600,400,NULL,NULL,hInstance,NULL);
     While(GetMessage(&msg,NULL,0,0)---->>while注意大小写
    Switch(uMsg)---->>switch,注意大小写
      

  2.   

    我复制过来运行下,17ERRors还说没错
      

  3.   

    我在创建的时候选错了;
    写的时候也没注意大小写;
    已经改过来了
    #include <windows.h>
    #include <stdio.h>LRESULT CALLBACK les1(
      HWND hwnd,      // handle to window
      UINT uMsg,      // message identifier
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
    );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
    )
    {
    WNDCLASS wndclass;
      wndclass.cbClsExtra=0;
      wndclass.cbWndExtra=0;
      wndclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
      wndclass.hCursor=LoadCursor(NULL,IDC_IBEAM);
      wndclass.hIcon=LoadIcon(NULL,IDI_HAND);
      wndclass.hInstance=hInstance;
      wndclass.lpfnWndProc=les1;
      wndclass.lpszClassName = "lesson1";
      wndclass.style=CS_HREDRAW|CS_VREDRAW;
      wndclass.lpszMenuName=NULL;
     
      RegisterClass(&wndclass);  HWND hwnd;
      hwnd = CreateWindow("lesson1","刘向培",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 les1(
      HWND hwnd,      // handle to window
      UINT uMsg,      // message identifier
      WPARAM wParam,  // first message parameter
      LPARAM lParam   // second message parameter
      )
      {
      switch(uMsg)
      {
      case WM_CHAR:
      char xp[20];
      sprintf(xp,"xp Press %d",wParam);
      MessageBox(hwnd,xp,"No 1",0);
         
      break;   default:
      return DefWindowProc(hwnd,uMsg,wParam,lParam);
      }  return 0;
      }
    再次感谢各位
    尤其是wxtsmart
      

  4.   

    楼主用的是哪个编译器?竟然编译时不提示错误?奇怪ing
      

  5.   

    没有处理WM_DESTROY消息,不能结束程序
      

  6.   

    sprintf(xp,"xp Press %d",wParam);
    MessageBox(hwnd,xp,"No 1",0);
    这段代码显示出来的不是键入的字母
    要显示键入的字母应该把%d改成%c吧