Sets the video mode.
#include <graph.h>
short __far _setvideomode( short mode );
mode | Desired mode |
The _setvideomode function selects a screen mode appropriate for a particular hardware/display configuration. The mode argument can be one of the manifest constants shown in Tables R.10 and R.11 and defined in GRAPH.H. Table R.10 describes only standard hardware; however, display hardware that is strictly compatible with IBM, Hercules, or Olivetti hardware should also work as described.
Table R.10 Manifest Constants for Screen Mode
Mode | Type1 | Size2 | Colors3 | Adapter4 |
_DEFAULTMODE | Mode existing at startup | , | |||
_MAXRESMODE | Highest resolution in graphics mode | , | |||
_MAXCOLORMODE | Maximum colors in graphics mode | , | |||
_TEXTBW40 | BW/T | 40 columns | 32 | CGA | |
_TEXTC40 | C/T | 40 columns | 32 | CGA | |
_TEXTBW80 | BW/T | 80 columns | 32 | CGA | |
_TEXTC80 | C/T | 80 columns | 32 | CGA | |
_MRES4COLOR | C/G | 320 ´ 200 | 4 | CGA | |
_MRESNOCOLOR | BW/G | 320 ´ 200 | 4 | CGA | |
_HRESBW | BW/G | 640 ´ 200 | 2 | CGA | |
_TEXTMONO | M/T | 80 columns | 32 | MDPA | |
_HERCMONO5 | M/G/Hercules graphics | 720 ´ 348, 2 | HGC | ||
_MRES16COLOR | C/G | 320 ´ 200 | 16 | EGA | |
_HRES16COLOR | C/G | 640 ´ 200 | 16 | EGA | |
_ERESNOCOLOR | M/G | 640 ´ 350 | 4 | EGA | |
_ERESCOLOR | C/G | 640 ´ 350 | 16/4 | EGA | |
_VRES2COLOR | C/G | 640 ´ 480 | 2 | VGA | |
_VRES16COLOR | C/G | 640 ´ 480 | 16 | VGA | |
_MRES256COLOR | C/G | 320 ´ 200 | 256 | VGA | |
_ORESCOLOR | C/G | 640 ´ 400 | 1 of 16 | OGA |
1 M indicates monochrome, BW indicates monochrome, C indicates color output, T indicates text, and G indicates graphics generation.
2 For text modes, size is given in characters (number of columns). For graphics modes, size is given in pixels (horizontal ´ vertical).
3 For monochrome displays, the number of colors is the number of attributes or shades of gray.
4 Adapters are the IBM (and compatible) Monochrome Adapter (MDPA), Color Graphics Adapter (CGA), Enhanced Graphics Adapter (EGA), Video Graphics Array (VGA), Hercules-compatible adapter (HGC), and Olivetti-compatible adapter (OGA).
5 In _HERCMONO mode, the text dimensions are 80 columns by 25 rows, with a 9 by 14 character box. The bottom two scan lines of row 25 are not visible.
Table R.11 lists the manifest constants that support the Super VGA screen modes specified by the Video Electronic Standards Association (VESA). Other nonstandard Super VGA modes may also be supported. Note that some, or all, of these manifest constants may be supported by graphics cards that support the VESA Super Video standard VS891001. Other modes may also be supported; a TSR driver may be required. For more details on these constants, see Chapter 9 of Programming Techniques (in the Microsoft C/C++ version 7.0 documentation set).
Table R.11 VESA Manifest Constants for Screen Mode
Mode | VESA No. | Type1 | Size | Colors | Adapter |
_ORES256COLOR | 0x0100 | C/G | 640 ´ 400 | 256 | SVGA |
_VRES256COLOR | 0x0101 | C/G | 640 ´ 480 | 256 | SVGA |
_SRES16COLOR2 | 0x0102 | C/G | 800 ´ 600 | 16 | SVGA |
_SRES256COLOR2 | 0x0103 | C/G | 800 ´ 600 | 256 | SVGA |
_XRES16COLOR3 | 0x0104 | C/G | 1024 ´ 768 | 16 | SVGA |
_XRES256COLOR3 | 0x0105 | C/G | 1024 ´ 768 | 256 | SVGA |
_ZRES16COLOR4 | 0x0106 | C/G | 1280 ´ 1024 | 16 | SVGA |
_ZRES256COLOR4 | 0x0107 | C/G | 1280 ´ 1024 | 256 | SVGA |
1 C indicates color output and G indicates graphics generation.
2 Requires NEC MultiSync 3D or equivalent or better.
3 Requires NEC MultiSync 4D or equivalent or better.
4 Requires NEC MultiSync 5D or equivalent or better.
Warning!:
Do not attempt to set _SRES16COLOR, _SRES256COLOR, _XRES16COLOR, _XRES256COLOR, _ZRES16COLOR, or _ZRES256COLOR without ensuring that your monitor can safely handle that resolution. Otherwise, you may risk damaging your display monitor! Consult your owner's manual for details.
_MAXRESMODE and _MAXCOLORMODE
The two special modes _MAXRESMODE and _MAXCOLORMODE select the highest resolution or greatest number of colors available with the current hardware, respectively. These two modes fail for adapters that do not support graphics modes. They never select _SRES, _XRES, or _ZRES mode.
Table R.12 lists the video mode selected for different adapter and monitor combinations when _MAXRESMODE or _MAXCOLORMODE is specified:
Table R.12 Modes Selected by _MAXRESMODE and _MAXCOLORMODE
Adapter/Monitor | _MAXRESMODE | _MAXCOLORMODE |
MDPA | fails | fails |
HGC | _HERCMONO | _HERCMONO |
CGA color1 | _HRESBW | _MRES4COLOR |
CGA noncolor1 | _HRESBW | _MRESNOCOLOR |
OCGA | _ORESCOLOR | _MRES4COLOR |
OEGA color | _ORESCOLOR | _ERESCOLOR |
EGA color 256K | _HRES16COLOR | _HRES16COLOR |
EGA color 64K | _HRES16COLOR | _HRES16COLOR |
EGA ecd 256K | _ERESCOLOR | _ERESCOLOR |
EGA ecd 64K | _ERESCOLOR | _HRES16COLOR |
EGA mono | _ERESNOCOLOR | _ERESNOCOLOR |
MCGA | _VRES2COLOR | _MRES256COLOR |
VGA | _VRES16COLOR | _MRES256COLOR |
OVGA | _VRES16COLOR | _MRES256COLOR |
SVGA | _VRES256COLOR2 | _VRES256COLOR2 |
1 Color monitor is assumed if the startup text mode was _TEXTC80 or _TEXTC40 or if the startup mode was graphics mode. Composite or other noncolor CGA monitor is assumed if startup mode was _TEXTBW80 or _TEXTBW40.
2 If _VRES256COLOR is supported by the adapter/monitor combination. If not, _MAXCOLORMODE will be either _ORES256COLOR (if supported) or _MRES256COLOR and _MAXRESMODE will be _VRES16COLOR.
Hercules Support
You must install the Hercules driver MSHERC.COM before running your program. Type MSHERC to load the driver. This can be automated by adding a line to your AUTOEXEC.BAT file.
If you have both a Hercules monochrome card and a color video card, you should install MSHERC.COM with the /H (/HALF) option. The /H option causes the driver to use one instead of two graphics pages. This prevents the two video cards from attempting to use the same memory. You do not need to use the /H option if you have only a Hercules card. See your Hercules hardware manuals for more details on compatibility.
To use a mouse, you must follow special instructions for Hercules cards in
Microsoft Mouse Programmer's Reference Guide. (This is sold separately;
it is not supplied with either Microsoft C/C++ or the mouse package.)
The function returns the number of text rows if the function is successful. If an error is encountered (that is, the mode selected is not supported by the current hardware configuration), the function returns 0.
Standards:None
16-Bit:DOS
32-Bit:None
_getvideoconfig, _settextrows, _setvideomoderows
/* SVIDMODE.C: This program sets a video mode from a string given on the
* command line.
*/
#include <graph.h>
#include <stdlib.h>
#include <string.h>
short modes[] = { _TEXTBW40, _TEXTC40, _TEXTBW80,
_TEXTC80, _MRES4COLOR, _MRESNOCOLOR,
_HRESBW, _TEXTMONO, _HERCMONO,
_MRES16COLOR, _HRES16COLOR, _ERESNOCOLOR,
_ERESCOLOR, _VRES2COLOR, _VRES16COLOR,
_MRES256COLOR, _ORESCOLOR
};
char *names[] = { "TEXTBW40", "TEXTC40", "TEXTBW80",
"TEXTC80", "MRES4COLOR", "MRESNOCOLOR",
"HRESBW", "TEXTMONO", "HERCMONO",
"MRES16COLOR", "HRES16COLOR", "ERESNOCOLOR",
"ERESCOLOR", "VRES2COLOR", "VRES16COLOR",
"MRES256COLOR","ORESCOLOR"
};
void error( char *msg );
void main( int argc, char *argv[] )
{
short i, num = sizeof( modes ) / sizeof( short );
struct _videoconfig vc;
if( argc < 2 )
error( "No argument given" );
/* If matching name found, change to corresponding mode. */
for( i = 0; i < num; i++ )
{
if( !_strcmpi( argv[1], names[i] ) )
{
_setvideomode( modes[i] );
_outtext( "New mode is: " );
_outtext( names[i] );
exit( 0 );
}
}
error( "Invalid mode string" );
}
void error( char *msg )
{
_outtext( msg );
exit( 1 );
}