The windows library.

2.1) Host computer informations.

type operating_system_type = Unix
                           | Dos
                           | MsWindows
                           | OS2
                           | WindowsNT
                           | MacOs
                           | NextStep
;;
type screen_type = MonochromeScreen
                 | ColorScreen;;
host_system : unit -> operating_system_type
host_system () returns the host system type.
screen_color : unit -> screen_type
screen_color () says if the screen is monochrome or not. If the screen can display shades of gray, the screen is indicated as ColorScreen.

2.2) Initialisation functions.

open_graph: unit -> unit
open_graph () opens the graphics mode. After the use of open_graph, functions like text_size return the default dimension for a newly created window.
close_graph: unit -> unit
close_graph () closes all the windows.
clear_graph : unit -> unit
clear_graph () erases the content of the current window.
screen_width : unit -> int
screen_width () return the width of the screen. This function must be used after open_graph.
screen_height : unit -> int
screen_height () returns the height of the screen.
set_clip_area : int -> int -> int -> int -> unit
set_clip_area x y w h defines a clipping rectangle in the current window. The lower left corner of the rectangle is in (x,y) and its width is w and its height h. All drawing functions are limited to the interior of clipping rectangle, until the definition of a new clipping rectangle or the modification of the current window. To work on a whole window, you simply have to call set_clip_area 0 0 (screen_width ()) (screen_height ()).
gr_flush : unit -> unit
gr_flush () flushes the graphic buffer. All the drawings in the buffer are displayed. get_event flushes the graphic display, as well as system.

2.3) Window management functions.

type window;;
the type window is an abstract type that identifies a window.
default_window : unit -> window
default_window () returns a basic window identifier.
add_window : int -> int -> int -> int -> string -> window
add_window x y w h Title opens a window with its lower left corner at (x,y), with a width of w, and a height of h, and with a title Title. The function returns the window identifier.
del_window : window -> unit
del_window id_win close the window defined by the identifier id_win. If the identifier is unmapped, a graphics exception is raised.
window_pos : window -> int * int
window_pos id_win returns the variable pair (x,y) of the real position of the lower left corner of the window defined by the identifier id_win. If the identifier is unmapped, the function returns (0,0).
window_width : window -> int
window_width id_win returns the width of the window defined by the identifier id_win. If the identifier is unmaped, the function returns 0.
window_height : window -> int
window_height id_win returns the height of the window defined by the identifier id_win. If the identifier is unmapped, the function returns 0.
set_draw_window : window -> unit
set_draw_window id_win sets the window defined by the identifier id_win as the current window. If the identifier is unmapped, all the drawing functions are ignored until a window is deleted, a window is added or a correct window is choosen as the current window.
set_current_window : window -> unit
set_current_window id_win sets the window defined by the identifier id_win as the current window. The window is raised to the top of the desktop. If the identifier is unmapped, all the drawing functions are ignored until a window is deleted, a window is added or a correct window is choosen as the current window.
get_current_window : unit -> window
get_current_window () returns the identifier of the current window.
set_window_car : int -> int -> int -> int -> unit
set_window_car x y w h changes the position and the size of the current window. Its lower left corner is placed at (x,y). Its width is set at w, and its height is set at h.

2.4) Events and associated functions.

The get_event function takes a list of elements of type event_type. This function returns a structure of type event. The return event is one of those appearing in the list, plus a redraw event or a close event.
type event_type =
    Button_down   (* A mouse button is pressed *)
  | Button_up     (* A mouse button is released *)
  | Key_pressed   (* A key is pressed *)
  | Mouse_motion  (* The mouse is moved *)
  | Poll          (* Don't wait; return immediately *)
  | Redraw		       (* The window need to be redrawn *)
  | Close		        (* The window  is closed *)
  | Size		         (* The window is resized *)
  | Time		         (* Time event *)
;;

type event =
{
  win     : window;   (* window identifier *)
  id_event: event_type;   (* event identifier *)
  mouse_x : int;   (* X coordinate of the mouse in the window *)
  mouse_y : int;   (* Y coordinate of the mouse in the window *)
  button  : bool;  (* true if a mouse button is pressed *)
  key     : int    (* the character for the key pressed *)
};;
where:
get_event : event_type list -> event
get_event List waits for an event listed in List or a redraw event or a close event, and returns a structure of type event.
set_time_event : int -> unit
set_time_event Delay sets the maximum delay to be block in get_event. If get_event is called with Time in its event list, and no other events are generated before Delay, then get_event returns a Time event.
The line get_event [ Button_down; Button_up; Key_pressed ] waits for a mouse button modification or a key press, but can also return a redraw or close event.

2.5) Colours.

type color == int
A colour its defined by is three components Red Green Blue, loaded in an integer with the form 0xRRGGBB.
set_color : color -> unit
set_color c defines the current color as c.
rgb : int -> int -> int -> int
rgb r g b returns the color whose red component is r, blue component b, and green component g.
black : color
white : color
red : color
green : color
blue : color
yellow : color
cyan : color
magenta : color
define some colours.
background : color
defines the background colour.
foreground : color
defines the foreground colour.

2.6) Line and pixel drawing.

plot : int -> int -> unit
plot x y draws a point at coordinates (x,y) with the current colour.
point_color : int -> int -> color
point_color x y returns the colour of the point at coordinates (x,y).
moveto : int -> int -> unit
moveto x y sets the current position (x,y).
current_point : unit -> int * int
current_point () returns the coordinates of the current point.
lineto : int -> int -> unit
lineto x y draws a line between the current point and the point at coordinates (x,y). The line is drawn with the current colour. The current point is set to coordinates (x,y).
draw_arc : int -> int -> int -> int -> int -> int -> unit
draw_arc x y rx ry a1 a2 draws an arc of ellipse. The center is at (x,y), the horizontal radius is rx, the vertical radius is ry. The arc is delimited by the two angles (in degrees) a1 and a2. It is drawn with the current colour.
draw_ellipse : int -> int -> int -> int -> unit
draw_ellipse x y rx ry draws an ellipse of center (x,y) and horizontal radius rx, vertical radius ry, with the current colour.
draw_circle : int -> int -> int -> unit
draw_circle x y r draws a circle of center (x,y) and radius r, with the current colour.

2.7) Text drawing.

type Font_Type = Default_font
               | Fixed_font
               | Proportional_font
;;

type Font_Attributes = Normal_font
                     | Italic
                     | Bold
                     | Underline
;;

type Font_Size = Size1_font
               | Size2_font
               | Size3_font
               | Size4_font
               | Size5_font
               | Size6_font
;;
The programmer can choose different fonts to draw the strings. The current font is changed with the function set_font.
draw_char : char -> unit
draw_char a draws the character a with its lower left corner at is the current point. The current point then shifts to the lower right corner of the drawn character.
draw_string : string -> unit
draw_string str draws the string str with the lower left corner at the current point. The current point then shifts to the lower right corner of the drawn string.
set_font : Font_Type -> Font_Attributes -> Font_Size -> unit
set_font Type Attributes Size defines the current font. If Type is set to Default_font, the other attributes are ignore. If the font can't be loaded, a graphic exception is raised.
text_size : string -> int * int
text_size str returns the width and the height of the string str as if it was drawn with the current font.

2.8) Shape filling.

fill_rect : int -> int -> int -> int -> unit
fill_rect x y w h fills a rectangle, with the current colour. The lower left corner is at (x,y), the width is w, the height is h.
fill_poly : (int * int) vect -> unit
fills a polygon with the current color. The vector define the vertices of the polygon.
fill_arc : int -> int -> int -> int -> int -> int -> unit
fill_arc x y rx ry a1 a2 fills an arc of ellipse between the angles a1 and a2. The center of the ellipse is at (x,y) the vertical radius is rx and the horizontal radius is ry.
fill_ellipse : int -> int -> int -> int -> unit
fill_ellipse x y rx ry fills an ellipse with the current colour. The ellipse is defined by is center at (x,y), its horizontal radius rx, and its vertical radius ry.
fill_circle : int -> int -> int -> unit
fill_circle x y r fills a circle of center (x,y), radius r, with the current colour.

2.9) Images.

type image;;
The type image is an abstract type. The function dump_image is used to convert an image into an array of colours and the function make_image is used to convert an array of colours into an image.
transp : color
This colour is used to define the points of an image made from an array of colours that mustn't modify the background of the window.
make_image : color vect vect -> image
make_image array converts the array of colours array into an image. Each line of the array must have the same size, otherwise a Graphic_failure exception is raised.
dump_image : image -> color vect vect
dump_image img converts the image img into an array of colours.
draw_image : image -> int -> int -> unit
draw_image img x y draws the image img with its lower left corner at (x,y).
get_image : int -> int -> int -> int -> image
get_image x y w h gets a rectangular portion of screen. The lower left corner of the rectangle is at (x,y), its width is w, its height is h.
create_image : int -> int -> image
create_image w h creates an undefined image of width w and height h.
blit_image : image -> int -> int -> unit
blit_image img x y copies a rectangular area of the screen into the image img. The rectangle is defined by its lower left corner at (x,y) and its width and its height which are the same as for the image img.
image_size : image -> int * int
image_size img returns the width and the height of the image img.
plot_image : image -> int -> int -> int -> unit
plot_image im x y color changes the point's colou of the image im at coordinates (x,y). If the coordinates are outside the image, im is not modified.
pixel_image : image -> int -> int -> int
pixel_image im x y returns the color of the point of the image im at coordinates (x,y). If the coordinates are outside the image, the function returns black.

2.10) Sounds.

sound : int -> int -> unit
sound freq dur plays a sound of frequency freq during dur seconds.

2.11) Functions on folders.

read_dir : unit -> string
Read_dir () returns a string with the following format: x1 name1\nx2 name2\n ... xn namen\n where x1...xn are either 'f' if namex is a file, or 'd' if namex is a folder.
current_dir : unit -> string
current_dir () returns the current folder.

2.12) Execution of programs.

system : string -> int
system Str runs the command Str. It returns -1 if an error occured, otherwise it returns the exit code of the command. The stdout and stderr streams are redirected towards the files camlwin.out and camlwin.err. These two files are created in the folder defined by the system variable CAMLWIN.

2.13) Clipboard access.

gr_copy_string : string -> unit
gr_copy_string str puts the string str in the clipboard. Under MsDos, the clipboard is stored in the file camlwin.buf, which is in the folder defined by the system variable CAMLWIN.
gr_past_string : unit -> string
gr_past_string () returns the string stored by the clipboard if there is one, otherwise its returns an empty string.