initwindow


Syntax
#include "graphics.h"
int initwindow(int width, int height, const char* title="Windows BGI", int left=0, int top=0, bool dbflag=false, closeflag=true);
Description[WIN]
The initwindow function is available in the winbgim implementation of BGI graphics. You do not need to include conio.h; just include graphics.h. The function initializes the graphics system by opening a graphics window of the specified size. The first two parameters (width and height) are required, but all other parameters have default values.

The title parameter is the title that will be printed at the top of the window (with a default of "Windows BGI".)

The left and top parameters determine the screen coordinates of the left and top sides of the window.

The dbflag parameter determines whether double-buffering for the window is automatically turned on as described in the swapbuffers function (true means that double-buffering will be turned on).

If the closeflag parameter is true, then the user can click on the window's close button to shut down the entire program.

Return Value
The original version of initgraph was a void function (with no flag argument), and only one graphics window could be created in any program. The new version allows multiple graphics windows to be created. The return value from the new initwindow function is a unique int identifier that can be used as an argument to setcurrentwindow in order to set which of several windows is currently being used. Immediately after calling initwindow, the current window is always the window that was just created.

See also
closegraph
getcurrentwindow
getmaxheight
getmaxwidth
initgraph
setcurrentwindow
swapbuffers

Example
/* initwindow example */ 
#include "graphics.h"

int main(void)
{
   /* initialize graphics window at 400 x 300 */
   initwindow(400, 300);

   /* draw a line */
   line(0, 0, getmaxx(), getmaxy());

   /* clean up */
   getch();
   closegraph();
   return 0;
}
/* initwindow example with two windows */ 
#include "graphics.h"

int main(void)
{
   int wid1, wid2;

   /* initialize graphics windows */
   wid1 = initwindow(400, 300);
   wid2 = initwindow(300, 400, 200, 100);

   /* draw lines */
   setcurrentwindow(wid1);
   line(0, 0, getmaxx(), getmaxy());
   setcurrentwindow(wid2);
   line(0, 0, getmaxx(), getmaxy());

   /* clean up */
   getch();
   closegraph();
   return 0;
}

Back to index