Advertisement
eXFq7GJ1cC

Untitled

Aug 6th, 2012
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.10 KB | None | 0 0
  1. /*------------------------------------------------------------
  2.    HELLOWIN.C -- Displays "Hello, Windows 98!" in client area
  3.                  (c) Charles Petzold, 1998
  4.   ------------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12. {
  13.      static TCHAR szAppName[] = TEXT ("HelloWin") ;
  14.      HWND         hwnd ;
  15.      MSG          msg ;
  16.      WNDCLASS     wndclass ;
  17.  
  18.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  19.      wndclass.lpfnWndProc   = WndProc ;
  20.      wndclass.cbClsExtra    = 0 ;
  21.      wndclass.cbWndExtra    = 0 ;
  22.      wndclass.hInstance     = hInstance ;
  23.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  24.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  25.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  26.      wndclass.lpszMenuName  = NULL ;
  27.      wndclass.lpszClassName = szAppName ;
  28.  
  29.      if (!RegisterClass (&wndclass))
  30.      {
  31.           MessageBox (NULL, TEXT ("This program requires Windows NT!"),
  32.                       szAppName, MB_ICONERROR) ;
  33.           return 0 ;
  34.      }
  35.      
  36.      hwnd = CreateWindow (szAppName,                  // window class name
  37.                           TEXT ("The Hello Program"), // window caption
  38.                           WS_OVERLAPPEDWINDOW,        // window style
  39.                           CW_USEDEFAULT,              // initial x position
  40.                           CW_USEDEFAULT,              // initial y position
  41.                           CW_USEDEFAULT,              // initial x size
  42.                           CW_USEDEFAULT,              // initial y size
  43.                           NULL,                       // parent window handle
  44.                           NULL,                       // window menu handle
  45.                           hInstance,                  // program instance handle
  46.                           NULL) ;                     // creation parameters
  47.      
  48.      ShowWindow (hwnd, iCmdShow) ;
  49.      UpdateWindow (hwnd) ;
  50.      
  51.      while (GetMessage (&msg, NULL, 0, 0))
  52.      {
  53.           TranslateMessage (&msg) ;
  54.           DispatchMessage (&msg) ;
  55.      }
  56.      return msg.wParam ;
  57. }
  58.  
  59. LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  60. {
  61.      HDC         hdc ;
  62.      PAINTSTRUCT ps ;
  63.      RECT        rect ;
  64.      
  65.      switch (message)
  66.      {
  67.      case WM_CREATE:
  68.           PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ;
  69.           return 0 ;
  70.          
  71.      case WM_PAINT:
  72.           hdc = BeginPaint (hwnd, &ps) ;
  73.          
  74.           GetClientRect (hwnd, &rect) ;
  75.          
  76.           DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
  77.                     DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
  78.          
  79.           EndPaint (hwnd, &ps) ;
  80.           return 0 ;
  81.          
  82.      case WM_DESTROY:
  83.           PostQuitMessage (0) ;
  84.           return 0 ;
  85.      }
  86.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement