INF: _QCGINIT() Can Be Useful for Dual-Monitor Programming

ID Number: Q72529

6.00 6.00a 6.00ax 7.00

MS-DOS

Summary:

Microsoft C versions 6.0, 6.0a, 6.0ax, C/C++ version 7.0, and QuickC

versions 2.0, 2.01, 2.5, and 2.51 contain an undocumented function,

called _QCGINIT(), in their graphics libraries. This function is used

to reinitialize the internal graphics information for the graphics

library functions and can be especially useful when creating an

application that accesses two different video monitors in a system.

More Information:

As mentioned above, the _QCGINIT() function is important for programs

that use two monitors: one monitor connected to a monochrome adapter

and another that is connected to a color adapter. Because one

application might switch between using the two graphics cards, the

graphics configuration data stored by the startup code must be updated

because the graphics routines need to know which card is in use.

_QCGINIT() fulfills this need.

For example, in a dual-monitor system, the _setvideomode() function

fails to switch to a graphics mode if the monochrome adapter is

currently active, even though the color graphics card is present. The

_QCGINIT() function will determine which graphics adapter is currently

selected and set internal information (such as which graphics modes

are available).

For more information on the _QCGINIT() function, query on the

following words:

_QCGINIT and dual and monitor

Note: _QCGINIT() is an undocumented function that may or may not be

included in subsequent releases of the graphics library. Please keep

this in mind when writing code to take advantage of this function.

Microsoft makes no claims and offers no promises regarding this

function in the areas of performance, reliability, future

availability, or customer support.

The sample program below demonstrates how to use _QCGINIT(). The

program requires a dual-monitor system and it requires that you make

the monochrome adapter the active display before invoking it. The

program first makes the VGA adapter the active display and switches to

the 640x350 VGA graphics mode. It then draws a line on the VGA screen,

saves the VGA screen, and switches back to the monochrome display.

Once the monochrome adapter is the active display, the program

restores the monochrome screen and prints a line of text. The sequence

of drawing another line on the VGA screen and printing another line of

text on the monochrome display occurs 20 times and then the program

terminates.

In this example, the _QCGINIT() routine is critical, because the

graphics routine must know whether it is currently using the

monochrome adapter or VGA adapter.

Sample Code

-----------

/* Compile options needed: /AL

*/

#include <stdio.h>

#include <graph.h>

/* prototypes for functions */

void _QCGINIT(void);

void set_to_vga(void);

void set_to_mono(void);

void save_mono_screen(void);

void restore_mono_screen(void);

/* Define buffers for screens */

char mono_buffer[8000];

char _huge image[120000];

/* This program draws lines on the VGA monitor while printing on

monochrome monitor */

void main(void)

{

int count;

/* Clear text screen */

_clearscreen(_GCLEARSCREEN);

for (count=0;count<20;count++)

{

/* Save the contents on the monochrome screen because

_setvideomode will clear the screen the next time around */

save_mono_screen();

set_to_vga();

if (count)

_putimage(0,0,image,_GPSET);

/* Draw some arbitrary lines on the VGA monitor */

_moveto(30,count);

_lineto(100,count);

/* Save the screen */

_getimage(0,0,639,349,image);

set_to_mono();

restore_mono_screen(); /* Restore screen because _setvideomode

cleared the video memory */

/* Print to the monochrome screen */

_settextposition(count,1);

_outtext("I drew a line\n");

}

}

void set_to_vga(void)

{

/* Switch to VGA */

_asm

{

sub ax,ax

mov es,ax

mov dl,es:[410h]

and dl,11101111B

mov es:[410h],dl

mov ah,0

mov al,11h

int 10h

}

/* Reinitialize graphics routines to recognize VGA */

_QCGINIT();

}

void set_to_mono()

{

/* Switch to monochrome */

_asm

{

sub ax,ax

mov es,ax

mov dl,es:[410h]

or dl,00010000B

mov es:[410h],dl

mov ah,0

mov al,7

int 10h

}

/* Re-initialize graphics routines to recognize monochrome

adapter */

_QCGINIT();

}

/* This is a routine to save the monochrome screen to a buffer */

void save_mono_screen(void)

{

_asm

{

push ds

mov ax,0b000h

mov ds,ax

mov si,0

mov ax,seg mono_buffer

mov es,ax

mov di,0

mov cx,2000

rep movsw

pop ds

}

}

/* This is a routine to restore the monochrome screen. */

void restore_mono_screen(void)

{

_asm

{

push ds

mov ax,seg mono_buffer

mov ds,ax

mov si,0

mov ax,0b000h

mov es,ax

mov di,0

mov cx,2000

rep movsw

pop ds

}

}

Additional reference words: 6.00 6.00a 6.00ax 7.00