home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c221 / 7.ddi / MWHC.007 / M1 < prev    next >
Encoding:
Text File  |  1990-11-11  |  3.1 KB  |  102 lines

  1. /*-----------------------------------------------------------
  2.    RESOURC2.C -- Icon and Cursor Demonstration Program No. 2
  3.                  (c) Charles Petzold, 1990
  4.   -----------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. long FAR PASCAL WndProc  (HWND, WORD, WORD, LONG) ;
  9.  
  10. char   szAppName[] = "Resourc2" ;
  11. HANDLE hInst ;
  12.  
  13. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  14.                     LPSTR lpszCmdLine, int nCmdShow)
  15.      {
  16.      HBITMAP  hBitmap ;
  17.      HBRUSH   hBrush ;
  18.      HWND     hwnd ;
  19.      MSG      msg ;
  20.      WNDCLASS wndclass ;
  21.  
  22.      hBitmap = LoadBitmap (hInstance, szAppName) ;
  23.      hBrush = CreatePatternBrush (hBitmap) ;
  24.  
  25.      if (!hPrevInstance) 
  26.           {
  27.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  28.           wndclass.lpfnWndProc   = WndProc ;
  29.           wndclass.cbClsExtra    = 0 ;
  30.           wndclass.cbWndExtra    = 0 ;
  31.           wndclass.hInstance     = hInstance ;
  32.           wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
  33.           wndclass.hCursor       = LoadCursor (hInstance, szAppName) ;
  34.           wndclass.hbrBackground = hBrush ;
  35.           wndclass.lpszMenuName  = NULL ;
  36.           wndclass.lpszClassName = szAppName ;
  37.  
  38.           RegisterClass (&wndclass) ;
  39.           }
  40.  
  41.      hInst = hInstance ;
  42.  
  43.      hwnd = CreateWindow (szAppName, "Icon and Cursor Demo",
  44.                           WS_OVERLAPPEDWINDOW,
  45.                           CW_USEDEFAULT, CW_USEDEFAULT,
  46.                           CW_USEDEFAULT, CW_USEDEFAULT,
  47.                           NULL, NULL, hInstance, NULL) ;
  48.  
  49.      ShowWindow (hwnd, nCmdShow) ;
  50.      UpdateWindow (hwnd) ;
  51.  
  52.      while (GetMessage (&msg, NULL, 0, 0))
  53.           {
  54.           TranslateMessage (&msg) ;
  55.           DispatchMessage (&msg) ;
  56.           }
  57.  
  58.      DeleteObject (hBrush) ;       // clean-up
  59.      DeleteObject (hBitmap) ;
  60.  
  61.      return msg.wParam ;
  62.      }
  63.  
  64. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  65.      {
  66.      static HICON hIcon ;
  67.      static short cxIcon, cyIcon, cxClient, cyClient ;
  68.      HDC          hdc ;
  69.      PAINTSTRUCT  ps ;
  70.      RECT         rect ;
  71.      short        x, y ;
  72.  
  73.      switch (message)
  74.           {
  75.           case WM_CREATE:
  76.                hIcon = LoadIcon (hInst, szAppName) ;
  77.                cxIcon = GetSystemMetrics (SM_CXICON) ;
  78.                cyIcon = GetSystemMetrics (SM_CYICON) ;
  79.                return 0 ;
  80.  
  81.           case WM_SIZE:
  82.                cxClient = LOWORD (lParam) ;
  83.                cyClient = HIWORD (lParam) ;
  84.                return 0 ;
  85.  
  86.           case WM_PAINT:
  87.                hdc = BeginPaint (hwnd, &ps) ;
  88.  
  89.                for (y = cyIcon ; y < cyClient ; y += 2 * cyIcon)
  90.                     for (x = cxIcon ; x < cxClient ; x += 2 * cxIcon)
  91.                          DrawIcon (hdc, x, y, hIcon) ;
  92.  
  93.                EndPaint (hwnd, &ps) ;
  94.                return 0 ;
  95.  
  96.           case WM_DESTROY:
  97.                PostQuitMessage (0) ;
  98.                return 0 ;
  99.           }
  100.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  101.      }
  102.