home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c495 / watcm951.arj / CPPSRC.WPK / SHAPES.CPP < prev   
Encoding:
C/C++ Source or Header  |  1993-02-16  |  2.6 KB  |  113 lines

  1. #include <stdlib.h>
  2.  
  3. #define    INCL_WIN
  4. #define    INCL_GPI
  5. #include <os2.h>
  6.  
  7. int        SizeX;
  8. int        SizeY;
  9. HWND        FrameHandle;
  10. HWND        WinHandle;
  11. HMQ        hMessageQueue;
  12. HAB        AnchorBlock;
  13.  
  14.  
  15. static int    Random( int high )
  16. {
  17.     return( ( (double)rand() / 32767 ) * high );
  18. }
  19.  
  20. static void NewColor( HPS ps )
  21. {
  22.     GpiSetColor( ps, Random( 15 ) + 1 );
  23. }
  24.  
  25. static void DrawEllipse()
  26. {
  27.     POINTL    ptl;
  28.     HPS        ps;
  29.     static int    Odd = 0;
  30.     int        parm1,parm2;
  31.  
  32.     ps = WinGetPS( WinHandle );
  33.     ptl.x = Random( SizeX );
  34.     ptl.y = Random( SizeY );
  35.     GpiMove( ps, &ptl );
  36.     ptl.x = Random( SizeX );
  37.     ptl.y = Random( SizeY );
  38.     parm1 = Random( 50 );
  39.     parm2 = Random( 50 );
  40.     if( Random( 10 ) >= 5 ) {
  41.     NewColor( ps );
  42.     GpiBox( ps, DRO_FILL, &ptl, 0, 0 );
  43.     NewColor( ps );
  44.     GpiBox( ps, DRO_OUTLINE, &ptl, 0, 0 );
  45.     } else {
  46.     NewColor( ps );
  47.     GpiBox( ps, DRO_FILL, &ptl, parm1, parm2 );
  48.     NewColor( ps );
  49.     GpiBox( ps, DRO_OUTLINE, &ptl, parm1, parm2 );
  50.     }
  51.     Odd++;
  52.     Odd &= 1;
  53.     WinReleasePS( ps );
  54. }
  55.  
  56. MRESULT    EXPENTRY MainDriver( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  57. {
  58.     HPS        ps;
  59.     RECTL    rcl;
  60.  
  61.     switch( msg ) {
  62.     case WM_CREATE:
  63.     WinHandle = hwnd;
  64.     WinStartTimer( AnchorBlock, WinHandle, 1, 150 ) ;
  65.     break;
  66.     case WM_TIMER:
  67.         DrawEllipse();
  68.     return( 0 );
  69.     case WM_SIZE:
  70.     SizeX = SHORT1FROMMP( mp2 );
  71.     SizeY = SHORT2FROMMP( mp2 );
  72.     return( 0 );
  73.     case WM_PAINT:
  74.         ps = WinBeginPaint( WinHandle, NULL, NULL );
  75.     WinQueryWindowRect( WinHandle, &rcl );
  76.     WinFillRect( ps, &rcl, CLR_WHITE );
  77.     WinEndPaint( ps );
  78.     return( 0 );
  79.     }
  80.     return( WinDefWindowProc( WinHandle, msg, mp1, mp2 ) );
  81. }
  82.  
  83. int    main()
  84. {
  85.     ULONG    style;
  86.     QMSG    qmsg;
  87.  
  88.     AnchorBlock = WinInitialize( 0 );
  89.     if( AnchorBlock == 0 ) return( 0 );
  90.     hMessageQueue = WinCreateMsgQueue( AnchorBlock, 0 );
  91.     if( hMessageQueue == 0 ) return( 0 );
  92.     if( !WinRegisterClass( AnchorBlock, (PSZ)"WATCOM", (PFNWP)MainDriver,
  93.                            CS_SIZEREDRAW, 0 ) ) {
  94.     return( 0 );
  95.     }
  96.     style = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX |
  97.         FCF_SHELLPOSITION | FCF_TASKLIST;
  98.     FrameHandle = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &style,
  99.                       (PSZ)"WATCOM", (PSZ)"", 0, NULL, 0,
  100.                       &WinHandle );
  101.     if( FrameHandle == 0 ) return( 0 );
  102.  
  103.     while( WinGetMsg( AnchorBlock, &qmsg, NULL, 0, 0 ) ) {
  104.     WinDispatchMsg( AnchorBlock, &qmsg );
  105.     }
  106.  
  107.     WinDestroyWindow( FrameHandle );
  108.     WinDestroyMsgQueue( hMessageQueue );
  109.     WinTerminate( AnchorBlock );
  110.  
  111.     return( 1 );
  112. }
  113.