home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_144 / 8.ddi / SCRNSAVE.ZIP / OWLSCRN.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  3.6 KB  |  139 lines

  1. // ObjectWindows - (C) Copyright 1992 by Borland International
  2. //
  3. // owlscrn.cpp
  4.  
  5. #include <owl.h>
  6. #include <dialog.h>
  7. #include <bwcc.h>
  8. #include <time.h>
  9. #include "tscrnsav.h"
  10.  
  11. char  szAppName[]  = "ScreenSaver.OWLSample";
  12. const WORD NUMDOTS =  900;
  13.  
  14. struct  DOTS
  15. {
  16.     POINT  ptVar;
  17.     DWORD  dwColor;
  18. };
  19.  
  20.  
  21. _CLASSDEF( TMyScrnSavWindow )
  22. class TMyScrnSavWindow : public TScrnSavWindow
  23. {
  24.         DOTS dtArray[NUMDOTS];
  25.         int  nCXScreen, nCYScreen, nDrawIndex, nEraseIndex;
  26.     public:
  27.         TMyScrnSavWindow( PTWindowsObject AParent, LPSTR ATitle,
  28.                           PTModule AModule = NULL );
  29.         virtual LPSTR GetClassName(){   return( szAppName ); }
  30.         virtual void  GetWindowClass( WNDCLASS & AWndClass );
  31.         virtual void  AnimateScreen();
  32. };
  33.  
  34.  
  35. TMyScrnSavWindow::TMyScrnSavWindow( PTWindowsObject AParent,
  36.                                     LPSTR ATitle,
  37.                                     PTModule AModule ) :
  38. TScrnSavWindow( AParent, ATitle, AModule )
  39. {
  40.     nDrawIndex   = 0;
  41.     nEraseIndex  = -2*( NUMDOTS/3 );
  42.     nCXScreen    = GetSystemMetrics( SM_CXSCREEN );
  43.     nCYScreen    = GetSystemMetrics( SM_CYSCREEN );
  44. }
  45.  
  46.  
  47. void TMyScrnSavWindow::GetWindowClass( WNDCLASS & AWndClass )
  48. {
  49.     TScrnSavWindow::GetWindowClass( AWndClass );
  50.     AWndClass.hbrBackground = ( HBRUSH )GetStockObject( BLACK_BRUSH );
  51. }
  52.  
  53.  
  54. void TMyScrnSavWindow::AnimateScreen()
  55. {
  56.     HDC    hDC;
  57.  
  58.     hDC = GetDC( HWindow );
  59.     if ( hDC )
  60.     {
  61.         SetROP2( hDC, R2_XORPEN );
  62.  
  63.         dtArray[nDrawIndex].ptVar.x = random( nCXScreen + 1 );
  64.         dtArray[nDrawIndex].ptVar.y = random( nCYScreen + 1 );
  65.         dtArray[nDrawIndex].dwColor = RGB( random( 0x100 ),
  66.                                            random( 0x100 ),
  67.                                            random( 0x100 ));
  68.  
  69.         SetPixel( hDC, dtArray[nDrawIndex].ptVar.x,
  70.                        dtArray[nDrawIndex].ptVar.y,
  71.                        ( COLORREF )dtArray[nDrawIndex].dwColor );
  72.         nDrawIndex++;
  73.         nDrawIndex %= NUMDOTS;
  74.  
  75.  
  76.         if ( nEraseIndex >= 0 )
  77.         {
  78.             SetPixel( hDC, dtArray[nEraseIndex].ptVar.x,
  79.                       dtArray[nEraseIndex].ptVar.y,
  80.                       ( COLORREF )dtArray[nEraseIndex].dwColor );
  81.             nEraseIndex++;
  82.             nEraseIndex %= NUMDOTS;
  83.         }
  84.         else
  85.             nEraseIndex++;
  86.  
  87.         ReleaseDC( HWindow, hDC );
  88.     }
  89. }
  90.  
  91.  
  92. _CLASSDEF( TMyScrnSavDlg )
  93. class TScrnSavDlg : public TDialog
  94. {
  95.     public:
  96.         TScrnSavDlg( PTWindowsObject AParent,
  97.                      LPSTR AName,
  98.                      PTModule AModule = NULL ) :
  99.         TDialog( AParent, AName, AModule )
  100.         {}
  101. };
  102.  
  103.  
  104.  
  105. _CLASSDEF( TMyScrnSavApp )
  106. class TMyScrnSavApp : public TScrnSavApp
  107. {
  108.     public:
  109.         TMyScrnSavApp( LPSTR AName, HINSTANCE AnInstance,
  110.                        HINSTANCE APrevInstance,
  111.                        LPSTR ACmdLine, int ACmdShow ) :
  112.         TScrnSavApp( AName, AnInstance, APrevInstance, ACmdLine, ACmdShow )
  113.         {}
  114.         virtual void  InitScrnSavWindow();
  115.         virtual void  InitConfigDialog();
  116. };
  117.  
  118.  
  119. void TMyScrnSavApp::InitScrnSavWindow()
  120. {
  121.     pScrnSavWnd = new TMyScrnSavWindow( NULL, szAppName );
  122. }
  123.  
  124.  
  125. void TMyScrnSavApp::InitConfigDialog()
  126. {
  127.     pConfigureDialog = new TScrnSavDlg( NULL, "CONFIGUREDIALOG" );
  128. }
  129.  
  130.  
  131. int PASCAL WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
  132.                     LPSTR lpCmdLine, int nCmdShow )
  133. {
  134.     TMyScrnSavApp App( szAppName, hInstance,
  135.                        hPrevInstance, lpCmdLine, nCmdShow );
  136.     App.Run();
  137.     return( App.Status );
  138. }
  139.