建立的是console程序,写win32程序

建立的是console程序,写win32程序  
  在setting->Link->Project   option里面  
    /subsystem:windows

 

  1. #include <windows.h>    
  2. #include <stdio.h>    
  3. LRESULT CALLBACK WinSunProc(HWND hwnd,  //   handle   to   window    
  4. UINT uMsg,  //   message   identifier    
  5. WPARAM wParam,  //   first   message   parameter    
  6. LPARAM lParam  //   second   message   parameter    
  7. );
  8. int WINAPI WinMain(HINSTANCE hInstance, 
  9. //   handle   to   current   instance    
  10. HINSTANCE hPrevInstance,  //   handle   to   previous   instance    
  11. LPSTR lpCmdLine,  //   pointer   to   command   line    
  12. int nCmdShow  //   show   state   of   window    
  13. );
  14. int WINAPI WinMain(HINSTANCE hInstance, 
  15. //   handle   to   current   instance    
  16. HINSTANCE hPrevInstance,  //   handle   to   previous   instance    
  17. LPSTR lpCmdLine,  //   pointer   to   command   line    
  18. int nCmdShow  //   show   state   of   window    
  19. )
  20. {
  21.   WNDCLASS wndcls;
  22.   wndcls.lpfnWndProc = WinSunProc;
  23.   wndcls.cbClsExtra = 0;
  24.   wndcls.cbWndExtra = 0;
  25.   wndcls.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
  26.   wndcls.hCursor = LoadCursor(NULL, IDC_CROSS);
  27.   wndcls.hIcon = LoadIcon(NULL, IDI_ERROR);
  28.   wndcls.hInstance = hInstance;
  29.   wndcls.lpszClassName = "Weixin2006";
  30.   wndcls.lpszMenuName = NULL;
  31.   wndcls.style = CS_HREDRAW | CS_VREDRAW;
  32.   RegisterClass(&wndcls);
  33.   HWND hwnd;
  34.   hwnd = CreateWindow("Weixin2006""刘霖坤第一个窗口程序", WS_OVERLAPPEDWINDOW,
  35.     0, 0, 600, 400, NULL, NULL, hInstance, NULL);
  36.   UpdateWindow(hwnd);
  37.   MSG msg;
  38.   while (GetMessage(&msg, NULL, 0, 0))
  39.   {
  40.     TranslateMessage(&msg);
  41.     DispatchMessage(&msg);
  42.   }
  43.   return 0;
  44. }
  45. LRESULT CALLBACK WindSunProc(HWND hwnd,  //   handle   to   window    
  46. UINT uMsg,  //   message   identifier    
  47. WPARAM wParam,  //   first   message   parameter    
  48. LPARAM lParam  //   second   message   parameter    
  49. )
  50. {
  51.   switch (uMsg)
  52.   {
  53.     case WM_CHAR:
  54.       char szChar[20];
  55.       sprintf(szChar, "char   is   %c", wParam);
  56.       MessageBox(hwnd, szChar, "llk", 0);
  57.       break;
  58.     case WM_LBUTTONDOWN:
  59.       MessageBox(hwnd, szChar, "llk", 0);
  60.       HDC hdc;
  61.       hdc = GetDC(hwnd);
  62.       TextOut(hdc, 0, 50, "计算机c++练习", strlen("计算机c++练习"));
  63.       ReleaseDC(hwnd, hdc);
  64.       break;
  65.     case WM_PAINT:
  66.       HDC hDC;
  67.       PAINTSTRUCT ps;
  68.       hDC = BeginPaint(hwnd, &ps);
  69.       TextOut(hDC, 0, 0, "sdlkfsdf", strlen("frist   one"));
  70.       EndPaint(hwnd, &ps);
  71.       break;
  72.     case WM_CLOSE:
  73.       if (MessageBox(hwnd, "是否真的结束?""weixin", MB_YESNO))
  74.       {
  75.         DestroyWindow(hwnd);
  76.       }
  77.       break;
  78.     case WM_DESTROY:
  79.       PostQuitMessage(0);
  80.       break;
  81.     default:
  82.       return DefWindowProc(hwnd, uMsg, wParam, lParam);
  83.   }
  84.   return 0;
  85. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值