/* %kw # %v %n %d %t # */ /* Version # 3 MULTIRES.C 8-Oct-93 14:26:16 # */ /***************************************************/ /* METAGRAPHICS SOFTWARE CORPORATION (c) 1992 */ /* Demonstrates how to use two different display */ /* adapters, such as VGA and Hercules, or to */ /* switch between two modes on the same adapter. */ /***************************************************/ #include #include #include #include #include #include #include #include "metawndo.h" /* master MetaWINDOW include file */ /* special stack size declaration if using Turbo or Borland C++ */ #ifdef TurboC extern unsigned _stklen = 14336U; /* stack size 14K */ #endif int GrafixCard, GrafixInput; void put_stuffup( void ); void put_Morestuffup( void ); void quit( char *msgptr ); #define mfDspGraf 0x0020 /* Display status - text(0)/graphics(1) */ void main( int argc, char *argv[] ) { int i; grafMap altBMap; grafPort *scrPort, altPort; /* choose a mode/display for the default port */ MetQuery(argc,argv); i = InitGraphics(GrafixCard); if( i != 0 ) GrInitErr(i); /* display reason for no go */ /* get pointer to current port */ GetPort( &scrPort ); printf("\n\n Press a key to choose another mode/display "); getch(); printf("\n Calling MetQuery....... "); MetQuery( argc, argv ); /* initialize second grafMap and grafPort */ i = InitBitmap( GrafixCard, &altBMap ); if( i ) { CloseBitmap( &altBMap ); quit("Error initializing second grafmap"); } InitPort( &altPort ); PortBitmap( &altBMap ); PortSize( altBMap.pixWidth, altBMap.pixHeight ); ClipRect( &altPort.portRect); EraseRect( &altPort.portRect); /* Set to default screen */ SetPort( scrPort ); SetDisplay( GrafPg0 ); put_stuffup(); getch(); /* Switch to second screen */ SetPort( &altPort ); SetDisplay( GrafPg0 ); put_stuffup(); getch(); /* Switch back to default screen */ SetPort( scrPort ); /* if both screens are on the same hardware, a transition from text to graphics modes must be performed to reset the hardware. Rather than really put it in text mode, we'll just lie about what mode its in */ scrPort->portMap->mapFlags &= ~mfDspGraf; SetDisplay( GrafPg0 ); put_Morestuffup(); getch(); /* Switch back to second screen */ SetPort( &altPort ); altBMap.mapFlags &= ~mfDspGraf; SetDisplay( GrafPg0 ); /* in case both screens on same hardware */ put_Morestuffup(); getch(); /* Set default screen back to text mode */ SetPort( scrPort ); SetDisplay( TextPg0 ); /* Set second screen back to text mode */ SetPort( &altPort ); SetDisplay( TextPg0 ); /* close the second grafMap */ i = CloseBitmap( &altBMap ); if( i ) quit("Error closing grafmap" ); quit("Normal end"); } void put_stuffup() { long max_clr; rect scrR; char lclmsg[40]; grafPort *thePort; /* get pointer to current port */ GetPort( &thePort ); max_clr= QueryColors(); max_clr++; DupRect( &thePort->portRect, &scrR ); FillRect( &scrR, 27 ); MoveTo( scrR.Xmax/4, scrR.Ymax/4 ); sprintf( lclmsg,"Mode - %dx%d, %ld colors", scrR.Xmax, scrR.Ymax, max_clr); DrawString( lclmsg ); } void put_Morestuffup() { rect R1, R2; int i, j, max_clr; char lclmsg[40]; grafPort *thePort; /* get pointer to current port */ GetPort(&thePort); DupRect( &thePort->portRect, &R1 ); FillRect( &R1, 8 ); DupRect( &R1, &R2 ); max_clr = (int) QueryColors() + 1; j = (R1.Xmax / max_clr) + 1; R2.Xmax = j; for( i=0; i <= max_clr; i++) { PenColor( i ); PaintRect( &R2 ); OffsetRect( &R2, j, 0 ); } PenColor( White ); MoveTo( R1.Xmax/4, R1.Ymax/4 ); sprintf( lclmsg, "Mode - %dx%d, %d colors", R1.Xmax, R1.Ymax, max_clr); DrawString( lclmsg ); } /* clean up and exit, print an exit message */ void quit( char *msgptr ) { printf("\n\n%s", msgptr); StopGraphics(); exit(0); } #include "metquery.c"