Chinaunix首页 | 论坛 | 博客
  • 博客访问: 50613
  • 博文数量: 11
  • 博客积分: 85
  • 博客等级: 民兵
  • 技术积分: 163
  • 用 户 组: 普通用户
  • 注册时间: 2012-08-08 09:59
文章分类

全部博文(11)

文章存档

2013年(8)

2012年(3)

我的朋友

分类: WINDOWS

2012-08-08 10:15:39


点击(此处)折叠或打开

  1. /*------------------------------------------------------------
  2.    HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
  3.                  (c) Charles Petzold, 1998
  4.   ------------------------------------------------------------*/

  5. #include <windows.h>

  6. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;

  7. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  8.                     PSTR szCmdLine, int iCmdShow)
  9. {
  10.      static TCHAR szAppName[] = TEXT ("HelloWin") ;
  11.      HWND hwnd ;
  12.      MSG msg ;
  13.      WNDCLASS wndclass ;

  14.      wndclass.style = CS_HREDRAW | CS_VREDRAW ;
  15.      wndclass.lpfnWndProc = WndProc ;
  16.      wndclass.cbCl***tra = 0 ;
  17.      wndclass.cbWndExtra = 0 ;
  18.      wndclass.hInstance = hInstance ;
  19.      wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION) ;
  20.      wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
  21.      wndclass.hbrBackground = (HBRUSH) GetStockObject (LTGRAY_BRUSH) ;
  22.      wndclass.lpszMenuName = NULL ;
  23.      wndclass.lpszClassName = szAppName ;

  24.      if (!RegisterClass (&wndclass))
  25.      {
  26.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  27.                       szAppName, MB_ICONERROR) ;
  28.           return 0 ;
  29.      }

  30.      hwnd = CreateWindow (szAppName, // window class name
  31.                           TEXT ("The Hello Program"), // window caption
  32.                           WS_OVERLAPPEDWINDOW, // window style
  33.                           CW_USEDEFAULT, // initial x position
  34.                           CW_USEDEFAULT, // initial y position
  35.                           CW_USEDEFAULT, // initial x size
  36.                           CW_USEDEFAULT, // initial y size
  37.                           NULL, // parent window handle
  38.                           NULL, // window menu handle
  39.                           hInstance, // program instance handle
  40.                           NULL) ; // creation parameters

  41.      ShowWindow (hwnd, iCmdShow) ;
  42.      UpdateWindow (hwnd) ;

  43.      while (GetMessage (&msg, NULL, 0, 0))
  44.      {
  45.           TranslateMessage (&msg) ;
  46.           DispatchMessage (&msg) ;
  47.      }
  48.      return msg.wParam ;
  49. }

  50. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  51. {
  52.      HDC hdc ;
  53.      PAINTSTRUCT ps ;
  54.      RECT rect ;

  55.      switch (message)
  56.      {
  57.      case WM_CREATE:
  58.           PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
  59.           return 0 ;

  60.      case WM_PAINT:
  61.           hdc = BeginPaint (hwnd, &ps) ;

  62.           GetClientRect (hwnd, &rect) ;

  63.           DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
  64.                     DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;

  65.           EndPaint (hwnd, &ps) ;
  66.           return 0 ;

  67.      case WM_DESTROY:
  68.           PostQuitMessage (0) ;
  69.           return 0 ;
  70.      }
  71.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  72. }

阅读(1026) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:bootstrap

给主人留下些什么吧!~~