home *** CD-ROM | disk | FTP | other *** search
/ Windows Graphics Programming / Feng_Yuan_Win32_GDI_DirectX.iso / Samples / Chapt_10 / Scrambler / Scrambler.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-05-12  |  1.8 KB  |  43 lines

  1. //-----------------------------------------------------------------------------------//
  2. //              Windows Graphics Programming: Win32 GDI and DirectDraw               //
  3. //                             ISBN  0-13-086985-6                                   //
  4. //                                                                                   //
  5. //  Written            by  Yuan, Feng                             www.fengyuan.com   //
  6. //  Copyright (c) 2000 by  Hewlett-Packard Company                www.hp.com         //
  7. //  Published          by  Prentice Hall PTR, Prentice-Hall, Inc. www.phptr.com      //
  8. //                                                                                   //
  9. //  FileName   : scrambler.cpp                                                         //
  10. //  Description: Screen scrambler demo program, Chapter 10                           //
  11. //  Version    : 1.00.000, May 31, 2000                                              //
  12. //-----------------------------------------------------------------------------------//
  13.  
  14. #define STRICT
  15. #define WIN32_LEAN_AND_MEAN
  16.  
  17. #include <windows.h>
  18. #include <stdlib.h>
  19.  
  20. int WINAPI WinMain(HINSTANCE hInst, HINSTANCE, PSTR, int)
  21. {
  22.     HDC hDC = GetDC(NULL);
  23.     
  24.     int width  = GetSystemMetrics(SM_CXSCREEN);
  25.     int height = GetSystemMetrics(SM_CYSCREEN);
  26.  
  27.     for (int i=0; i<2000; i++)
  28.     {
  29.         HBRUSH hBrush = CreateSolidBrush(RGB(rand()%256, rand()%256, rand()%256));
  30.         SelectObject(hDC, hBrush);
  31.  
  32.         BOOL rslt = StretchBlt(hDC, rand() % width, rand() % height, -64, -64, 
  33.                                hDC, rand() % width, rand() % height, 32, 32, (rand() % 256) << 16);
  34.         SelectObject(hDC, GetStockObject(WHITE_BRUSH));
  35.         DeleteObject(hBrush);
  36.         Sleep(1);
  37.     }
  38.  
  39.     ReleaseDC(NULL, hDC);
  40.  
  41.     RedrawWindow(NULL, NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
  42.     return 0;
  43. }