home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c500 / 1.ddi / SRC386.WPK / SHAPES.C < prev   
Encoding:
C/C++ Source or Header  |  1992-05-28  |  2.6 KB  |  117 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. MRESULT    EXPENTRY MainDriver( HWND hwnd, USHORT msg, MPARAM mp1, MPARAM mp2 )
  16. {
  17.     HPS        ps;
  18.     RECTL    rcl;
  19.  
  20.     switch( msg ) {
  21.     case WM_CREATE:
  22.     WinHandle = hwnd;
  23.     WinStartTimer( AnchorBlock, WinHandle, 1, 150 ) ;
  24.     break;
  25.     case WM_TIMER:
  26.         DrawEllipse();
  27.     return( 0 );
  28.     case WM_SIZE:
  29.     SizeX = SHORT1FROMMP( mp2 );
  30.     SizeY = SHORT2FROMMP( mp2 );
  31.     return( 0 );
  32.     case WM_PAINT:
  33.         ps = WinBeginPaint( WinHandle, NULL, NULL );
  34.     WinQueryWindowRect( WinHandle, &rcl );
  35.     WinFillRect( ps, &rcl, CLR_WHITE );
  36.     WinEndPaint( ps );
  37.     return( 0 );
  38.     }
  39.     return( WinDefWindowProc( WinHandle, msg, mp1, mp2 ) );
  40. }
  41.  
  42.  
  43. int    main()
  44. {
  45.     ULONG    style;
  46.     QMSG    qmsg;
  47.  
  48.     AnchorBlock = WinInitialize( 0 );
  49.     if( AnchorBlock == 0 ) return( 0 );
  50.     hMessageQueue = WinCreateMsgQueue( AnchorBlock, 0 );
  51.     if( hMessageQueue == 0 ) return( 0 );
  52.     if( !WinRegisterClass( AnchorBlock, "WATCOM", (PFNWP)MainDriver,
  53.                            CS_SIZEREDRAW, 0 ) ) {
  54.     return( 0 );
  55.     }
  56.     style = FCF_TITLEBAR | FCF_SYSMENU | FCF_SIZEBORDER | FCF_MINMAX |
  57.         FCF_SHELLPOSITION | FCF_TASKLIST;
  58.     FrameHandle = WinCreateStdWindow( HWND_DESKTOP, WS_VISIBLE, &style,
  59.                       "WATCOM", "", 0, NULL, 0,
  60.                       &WinHandle );
  61.     if( FrameHandle == 0 ) return( 0 );
  62.  
  63.     while( WinGetMsg( AnchorBlock, &qmsg, NULL, 0, 0 ) ) {
  64.     WinDispatchMsg( AnchorBlock, &qmsg );
  65.     }
  66.  
  67.     WinDestroyWindow( FrameHandle );
  68.     WinDestroyMsgQueue( hMessageQueue );
  69.     WinTerminate( AnchorBlock );
  70.  
  71.     return( 1 );
  72. }
  73.  
  74.  
  75. static int    Random( int high )
  76. {
  77.     return( ( (double)rand() / 32767 ) * high );
  78. }
  79.  
  80.  
  81. static void NewColor( HPS ps )
  82. {
  83.     GpiSetColor( ps, Random( 15 ) + 1 );
  84. }
  85.  
  86.  
  87. static void DrawEllipse()
  88. {
  89.     POINTL    ptl;
  90.     HPS        ps;
  91.     static int    Odd = 0;
  92.     int        parm1,parm2;
  93.  
  94.     ps = WinGetPS( WinHandle );
  95.     ptl.x = Random( SizeX );
  96.     ptl.y = Random( SizeY );
  97.     GpiMove( ps, &ptl );
  98.     ptl.x = Random( SizeX );
  99.     ptl.y = Random( SizeY );
  100.     parm1 = Random( 50 );
  101.     parm2 = Random( 50 );
  102.     if( Random( 10 ) >= 5 ) {
  103.     NewColor( ps );
  104.     GpiBox( ps, DRO_FILL, &ptl, 0, 0 );
  105.     NewColor( ps );
  106.     GpiBox( ps, DRO_OUTLINE, &ptl, 0, 0 );
  107.     } else {
  108.     NewColor( ps );
  109.     GpiBox( ps, DRO_FILL, &ptl, parm1, parm2 );
  110.     NewColor( ps );
  111.     GpiBox( ps, DRO_OUTLINE, &ptl, parm1, parm2 );
  112.     }
  113.     Odd++;
  114.     Odd &= 1;
  115.     WinReleasePS( ps );
  116. }
  117.