Advertisement
eXFq7GJ1cC

Untitled

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