home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / windows / winprogs.zip / RESOURC1.ZIP / RESOURC1.C next >
Text File  |  1990-12-26  |  3KB  |  113 lines

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