Home Robotics C++ Physics II AP Physics B Electronics AP Java Astronomy Independent Study Summer Session Contests  About
                                                       

Some Useful API Structures and Functions

 

API Structures

 

Point

 

Used to send a single point from one routine to another without having to pass two parameters (x and y) which represents position of a pixel on the screen. It is useful when you want a function to return a point without having to use reference parameters.

 

Private Type POINT

      x as Long

      y as Long

End Type

 

Rect

 

As with point, it saves a lot of time when sending parameters between functions. It uses 4 variables which keep track of the 4 sides of a rectangular region. Note  that Windows itself uses rect when a window is moved on the screen.

 

Public Type RECT

      Left As Long

      Top As Long

      Right As Long

      Bottom As Long

End Type

 

RGBQUAD

 

This is useful any time you need to work with colors on a 32 bit display. The 4 components are Blue, Green, Red, and Alpha (alpha sets the level of opacity).

 

Private Type RGBQUAD

      Blue As Byte

      Green As Byte

      Red As Byte

      Alpha As Byte

End Type

 

 

 

API Functions

 

GetTickCount

 

Uses the system timer. Useful for keeping your program running at a stable speed regardless of frame rate.

 

      Private Declare Function GetTickCount Lib “kernel32” ( ) As Long

 

SetPixel

 

Lets you draw a single pixel on a drawing surface such as a PictureBox or ImageBox. The four parameters provide the destination, location, and color of the pixel.

 

      Private Declare Function SetPixel Lib “gdi32” (ByVal hDC as Long_

            ByVal X As Long, ByVal Y as Long, ByVal crColor As Long) As Long

                                   

GetPixel

 

Complements SetPixel – returns the color of a pixel at a specific location on the drawing surface. Its 3 parameters provide the destination and location of     the pixel.

 

      Private Declare Function GetPixel Lib “gdi32” (ByVal hDC as Long,_

            ByVal X as Long, ByVal Y as Long) As Long

 

Ellipse

 

Draws an ellipse at a specified location on the drawing surface. 5 parameters include the destination and the 4 sides of a rectangular region that bounds the shape. Color is set in advance using a custom drawing pen.

 

      Private Declare Function Ellipse Lib “gdi32”(ByVal hDC As Long,_

            ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long,_

            ByVal Y2 As Long) As Long

 

MoveTo

 

Moves the current drawing pointer to a new location on the destination surface. The 4 parameters include the drawing surface, location, and a POINT that is returned as ByRef with the old location of the pointer.

 

Private Declare Function MoveTo Lib “gdi32” Alias “MoveToEx”_

            (ByVal hDC As Long, ByVal X As Long , ByVal Y As Long, lpPoint As Point_

            ) As Long

 

LineTo

 

Draws a line from the current pointer position to a new location on the drawing surface. Color and style set in advance using custom drawing pen (covered later).

 

      Private Declare Function LineTo Lib “gdi32” (ByVal hDC As Long,_

            ByVal X As Long, ByVal Y As Long) As Long

 

PolyLine

 

Draws a series of lines stored in an array of points that mark the endpoints of each line segment. Color set in advance.

 

      Private Declare Function PolyLine Lib “gdi32” (ByVal hDC As Long,_

            lpPoint As POINT, ByVal nCount As Long) As Long

 

CreatePen

 

Creates a custom drawing pen for use with drawing functions such as LineTo and PolyLine. The pen is identified with a returned Window handle, like hWND and is stored in Windows. The 3 parameters are the pen style, drawing width, and RGB color.

 

      Private Declare Function CreatePen Lib “gdi32” (ByVal nPenStyle As Long,_

            ByVal nWidth As Long, ByVal crColor As Long) As Long

 

SelectObject

 

Used to select an object into a device context. Note that Device context is Windows terminology for a drawing surface. Selecting an object this way has the effect of associating the object with a specific device context. For example, a pen created with the CreatePen function

 

      Private Declare Function SelectObject Lib “gdi32” (ByVal hDC As Long,ByVal hObject As_

           Long) As Long

 

DeleteObject

 

Deletes a system resource created with functions such as CreatePen.

 

      Private Declare Function DeleteObject Lib “gdi32” (ByVal hObject As Long) As Long

 

GetObject

 

Retrieves information about an object with a Windows handle – useful for reading header information for a bitmap image. Parameters provide handle, size of the header, and the destination buffer for the data.

 

      Private Declare Function GetObject LIb “gdi32” Alias “GetObjectA” (_

            ByVal hObject As Long, ByVal nCount As Long, lpObject As Any) As Long