home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / progwin / chap08 / resourc1.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  2.9 KB  |  93 lines

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