home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP09 / RESOURC1.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  2.9 KB  |  91 lines

  1. /*-----------------------------------------------------------
  2.    RESOURC1.C -- Icon and Cursor Demonstration Program No. 1
  3.                  (c) Charles Petzold, 1996
  4.   -----------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. char      szAppName[] = "Resourc1" ;
  11. HINSTANCE hInst ;
  12.  
  13. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  14.                     PSTR szCmdLine, int iCmdShow)
  15.      {
  16.      HWND       hwnd ;
  17.      MSG        msg ;
  18.      WNDCLASSEX wndclass ;
  19.  
  20.      wndclass.cbSize        = sizeof (wndclass) ;
  21.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  22.      wndclass.lpfnWndProc   = WndProc ;
  23.      wndclass.cbClsExtra    = 0 ;
  24.      wndclass.cbWndExtra    = 0 ;
  25.      wndclass.hInstance     = hInstance ;
  26.      wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
  27.      wndclass.hCursor       = LoadCursor (hInstance, szAppName) ;
  28.      wndclass.hbrBackground = (HBRUSH) (COLOR_WINDOW + 1) ;
  29.      wndclass.lpszMenuName  = NULL ;
  30.      wndclass.lpszClassName = szAppName ;
  31.      wndclass.hIconSm       = LoadIcon (hInstance, szAppName) ;
  32.  
  33.      RegisterClassEx (&wndclass) ;
  34.  
  35.      hInst = hInstance ;
  36.  
  37.      hwnd = CreateWindow (szAppName, "Icon and Cursor Demo",
  38.                           WS_OVERLAPPEDWINDOW,
  39.                           CW_USEDEFAULT, CW_USEDEFAULT,
  40.                           CW_USEDEFAULT, CW_USEDEFAULT,
  41.                           NULL, NULL, hInstance, NULL) ;
  42.  
  43.      ShowWindow (hwnd, iCmdShow) ;
  44.      UpdateWindow (hwnd) ;
  45.  
  46.      while (GetMessage (&msg, NULL, 0, 0))
  47.           {
  48.           TranslateMessage (&msg) ;
  49.           DispatchMessage (&msg) ;
  50.           }
  51.      return msg.wParam ;
  52.      }
  53.  
  54. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  55.      {
  56.      static HICON hIcon ;
  57.      static int   cxIcon, cyIcon, cxClient, cyClient ;
  58.      HDC          hdc ;
  59.      PAINTSTRUCT  ps ;
  60.      int          x, y ;
  61.  
  62.      switch (iMsg)
  63.           {
  64.           case WM_CREATE :
  65.                hIcon = LoadIcon (hInst, szAppName) ;
  66.                cxIcon = GetSystemMetrics (SM_CXICON) ;
  67.                cyIcon = GetSystemMetrics (SM_CYICON) ;
  68.                return 0 ;
  69.  
  70.           case WM_SIZE :
  71.                cxClient = LOWORD (lParam) ;
  72.                cyClient = HIWORD (lParam) ;
  73.                return 0 ;
  74.  
  75.           case WM_PAINT :
  76.                hdc = BeginPaint (hwnd, &ps) ;
  77.  
  78.                for (y = cyIcon ; y < cyClient ; y += 2 * cyIcon)
  79.                     for (x = cxIcon ; x < cxClient ; x += 2 * cxIcon)
  80.                          DrawIcon (hdc, x, y, hIcon) ;
  81.  
  82.                EndPaint (hwnd, &ps) ;
  83.                return 0 ;
  84.  
  85.           case WM_DESTROY :
  86.                PostQuitMessage (0) ;
  87.                return 0 ;
  88.           }
  89.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  90.      }
  91.