Main Page | Modules | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

General DC operations
[GDI functions]

Modules

Defines

Functions


Detailed Description

DC means Device Context, just like Graphics Context (GC) of X Lib. DC represents a rectangle area on the actual screen or a virtual screen created in memory. We call the rectangle area as "surface" of the DC.

You can call a GDI function and pass a DC to the function to draw lines, circles, or text. Commonly, you should call a function like GetClientDC or CreateCompatibleDC to get or create a DC, then call GDI functions to draw objects, e.g. MoveTo and LineTo. After finishing drawing, you should call ReleaseDC or DeleteMemDC function to release or destroy the DC.

MiniGUI reserved an global DC called HDC_SCREEN. You can use this DC directly without getting/creating or releasing/destroying.

For main windows or controls, MiniGUI will send a MSG_PAINT message to the window when the whole or part of window area have been invalidated. You should call BegainPaint function to get the DC, then repaint the window, and call EndPaint function to release the DC at the last.

Example:

case MSG_PAINT:
{
        HDC hdc;

        hdc = BeginPaint (hWnd);

        // Draw a line.
    MoveTo (hdc, 0, 0);
    LineTo (hdc, 100, 100);

        EndPaint (hWnd, hdc);
        break;
}

Define Documentation

#define CreateCompatibleDC hdc   )     CreateCompatibleDCEx(hdc, 0, 0);
 

Creates a memory DC which is compatible with a given DC.

This function creates a memory DC fully compatible with the reference DC hdc, including pixel format and geomatry.

Parameters:
hdc The reference DC.
Returns:
The handle to the memory DC, HDC_INVALID indicates an error.
Note:
Only defined as macro calling CreateCompatibleDCEx for _USE_NEWGAL. If _USE_NEWGAL is not defined, CreateCompatibleDC is defined as a function, and have the same semantics as this macro.
See also:
CreateCompatibleDCEx, DeleteMemDC

Definition at line 1514 of file gdi.h.

#define DeleteCompatibleDC hdc   )     DeleteMemDC(hdc)
 

Deletes a memory DC.

This function deletes a memory DC created by CreateCompatibleDC.

Parameters:
hdc The device context to be deleted.
Note:
Only defined as macro calling DeleteMemDC for _USE_NEWGAL. If _USE_NEWGAL is not defined, DeleteCompatibleDC is defined as a function, and have the same semantics as this macro.
See also:
CreateCompatibleDC, DeleteMemDC

Definition at line 1530 of file gdi.h.

#define HDC_INVALID   0
 

Indicates an invalid handle to device context.

Definition at line 1107 of file gdi.h.

#define HDC_SCREEN   0
 

Handle to the device context of the whole screen.

This DC is a special one. MiniGUI uses it to draw popup menus and other global objects. You can also use this DC to draw lines or text on the screen directly, and there is no need to get or release it.

If you do not want to create any main window, but you want to draw on the screen, you can use this DC.

Note:
MiniGUI does not do any clipping operation for this DC, so use this DC may make a mess of other windows.

Definition at line 1101 of file gdi.h.


Function Documentation

BOOL GUIAPI ConvertMemDC HDC  mem_dc,
HDC  ref_dc,
DWORD  flags
 

Converts a memory DC to have a same format as a reference DC.

This function converts a memory DC mem_dc in order to let it have the same pixel format as the reference DC ref_dc. This function will try to create a new surface for mem_dc, and then copies and maps the surface of ref_dc to it so the blit of the converted memory DC will be as fast as possible.

The flags parameter has the same semantics as CreateMemDC. You can also pass MEMDC_FLAG_RLEACCEL in the flags parameter and MiniGUI will try to RLE accelerate colorkey and alpha blits in the resulting memory DC.

Parameters:
mem_dc The device context to be converted.
ref_dc The reference device context.
flags The memory DC flags, has the same semantics as CreateMemDC.
Returns:
TRUE on success, otherwise FALSE.
Note:
Only defined for _USE_NEWGAL.
See also:
CreateMemDC, DeleteMemDC

HDC GUIAPI CreateCompatibleDCEx HDC  hdc,
int  width,
int  height
 

Creates a memory DC which is compatible with the specified reference DC.

This function creates a memory DC which have the same pixel format as the specified reference DC hdc. The same pixel format means that the memory DC will have the same pixel depth, the same RGB composition, or the same palette as the reference DC.

Parameters:
hdc The handle to the reference DC.
width The expected width of the result memory DC. If it is zero, the width will be equal to the width of the reference DC.
height The expected height of the result memory DC. If it is zero, the height will be equal to the height of the reference DC.
Returns:
The handle to the memory DC, HDC_INVALID indicates an error.
Note:
Only defined for _USE_NEWGAL.
See also:
CreateCompatibleDC

HDC GUIAPI CreateMemDC int  width,
int  height,
int  depth,
DWORD  flags,
Uint32  Rmask,
Uint32  Gmask,
Uint32  Bmask,
Uint32  Amask
 

Creates a memory DC.

This function creates a memory DC which have the specified flags and pixel format.

Parameters:
width The expected width of the result memory DC.
height The expected height of the result memory DC.
depth The expected color depth of the memory DC.
flags The memory DC flags, can be or'ed values of the following flags:
  • MEMDC_FLAG_SWSURFACE
    Creates the surface of memory DC in the system memory.
  • MEMDC_FLAG_HWSURFACE
    Creates the surface of memory DC in the video memory.
  • MEMDC_FLAG_SRCCOLORKEY
    The created memory DC will use a source color key to blit to other DC.
  • MEMDC_FLAG_SRCALPHA
    The created memory DC will use a source alpha blending to blit to other DC.
  • MEMDC_FLAG_RLEACCEL
    The memory DC will be RLE encoded

Parameters:
Rmask The bit-masks of the red components in a pixel value.
Gmask The bit-masks of the green components in a pixel value.
Bmask The bit-masks of the blue components in a pixel value.
Amask The bit-masks of the alpha components in a pixel value.
Returns:
The handle to the memory DC, HDC_INVALID indicates an error.
Note:
Only defined for _USE_NEWGAL.
See also:
CreateMemDCFromBitmap, CreateMemDCFromMyBitmap, CreateCompatibleDCEx

HDC GUIAPI CreateMemDCFromBitmap HDC  hdc,
BITMAP bmp
 

Creates a memory DC from a reference DC and a BITMAP object.

This function creates a memory DC compatible with the specified DC, and use the bits of the BITMAP object as the surface of the memory DC. The created memory DC will have the same geometry as the BITMAP object.

Parameters:
hdc The reference DC.
bmp The BITMAP object.
Returns:
The handle to the memory DC, HDC_INVALID indicates an error.
Note:
Only defined for _USE_NEWGAL.
See also:
CreateMemDCFromMyBitmap, DeleteMemDC, BITMAP

HDC GUIAPI CreateMemDCFromMyBitmap const MYBITMAP my_bmp,
RGB pal
 

Creates a memory DC from a device independent MYBITMAP object.

This function creates a memory DC which have the same pixel format as the MYBITMAP object my_bmp, and use the bits of the MYBITMAP object as the surface of the memory DC. The created memory DC will have the same geometry as the MYBITMAP object. If the depth of my_bmp is 8-bit, the function will use pal to initialize the palette of the memory DC.

Parameters:
my_bmp The device independent MYBITMAP object.
pal The palette of the MYBITMAP object. If the depth of my_bmp is larger than 8-bit, this argument can be NULL.
Returns:
The handle to the memory DC, HDC_INVALID indicates an error.
Note:
Only defined for _USE_NEWGAL.
See also:
CreateMemDCFromBitmap, DeleteMemDC, MYBITMAP

HDC GUIAPI CreatePrivateClientDC HWND  hwnd  ) 
 

Creates a private client DC of a window.

This function creates a private client DC of the window hwnd and returns the handle to the DC.

When you calling CreatePrivateClientDC function to create a private client DC, MiniGUI will create the DC in the system heap, rather than allocate one from the DC pool. Thus, you can keep up the DC in the life cycle of the window, and are not needed to release it for using by other windows.

Parameters:
hwnd The handle to the window.
Returns:
The handle to the DC, HDC_INVALID indicates an error.
See also:
DeletePrivateDC

HDC GUIAPI CreatePrivateDC HWND  hwnd  ) 
 

Creates a private window DC of a window.

This function creates a private window DC of the window hwnd and returns the handle to the DC.

When you calling CreatePrivateDC function to create a private DC, MiniGUI will create the DC in the system heap, rather than allocate one from the DC pool. Thus, you can keep up the private DC in the life cycle of the window, and are not needed to release it for using by other windows.

Parameters:
hwnd The handle to the window.
Returns:
The handle to the DC, HDC_INVALID indicates an error.
See also:
DeletePrivateDC

void GUIAPI DeleteMemDC HDC  mem_dc  ) 
 

Deletes a memory DC.

This function deletes the memory DC mem_dc, and frees the surface of the DC. For the memory DC created from BITMAP object or MYBITMAP object, the bits used by the surface of the DC will be reserved.

Parameters:
mem_dc The device context to be deleted.
Note:
Only defined for _USE_NEWGAL.
See also:
CreateMemDC, CreateMemDCFromBitmap, CreateMemDCFromMyBitmap

void GUIAPI DeletePrivateDC HDC  hdc  ) 
 

Deletes the DC returned by CreatePrivateDC or CreatePrivateClientDC.

Parameters:
hdc The handle to the DC.
See also:
CreatePrivateDC, CreatePrivateClientDC

HDC GUIAPI GetClientDC HWND  hwnd  ) 
 

Gets a client DC of a window.

This function gets a client DC of the specified hwnd, and returns the handle to the DC. MiniGUI will try to return an unused DC from the internal DC pool, rather than allocate a new one from the system heap. Thus, you should release the DC when you finish drawing as soon as possible.

Parameters:
hwnd The handle to the window.
Returns:
The handle to the DC, HDC_INVALID indicates an error.
Note:
You should call ReleaseDC to release the DC when you are done.
See also:
GetDC, ReleaseDC

HDC GUIAPI GetDC HWND  hwnd  ) 
 

Gets a window DC of a window.

This function gets a window DC of the specified hwnd, and returns the handle to the DC. MiniGUI will try to return an unused DC from the internal DC pool, rather than allocate a new one from the system heap. Thus, you should release the DC when you finish drawing as soon as possible.

Parameters:
hwnd The handle to the window.
Returns:
The handle to the DC, HDC_INVALID indicates an error.
Note:
You should call ReleaseDC to release the DC when you are done.
See also:
GetClientDC, ReleaseDC

unsigned int GUIAPI GetGDCapability HDC  hdc,
int  iItem
 

Returns a capability of a DC.

This function returns the capability of the specified item iItem of the DC hdc.

Parameters:
hdc The handle to the DC.
iItem An integer presents the capablity, can be one of the following values:
  • GDCAP_COLORNUM
    Tell GetGDCapability to return the colors number of the DC. Note the for a DC with 32-bit depth, the function will return 0xFFFFFFFF, not 0x100000000.
  • GDCAP_HPIXEL
    Tell GetGCapability to return the horizontal resolution of the DC.
  • GDCAP_VPIXEL
    Tell GetGDCapability to return the vertical resolution of the DC.
  • GDCAP_MAXX
    Tell GetGDCapability to return the maximal visible x value of the DC.
  • GDCAP_MAXY
    Tell GetGDCapability to return the maximal visible y value of the DC.
  • GDCAP_DEPTH
    Tell GetGDCapability to return the color depth of the DC. The returned value can be 1, 4, 8, 15, 16, 24, or 32.
  • GDCAP_BITSPP
    Tell GetGDCapability to return the bits number for storing a pixle in the DC.
  • GDCAP_BPP
    Tell GetGDCapability to return the bytes number for storing a pixle in the DC.
  • GDCAP_RMASK
    Tell GetGDCapability to return the pixel red color mask for the DC.
  • GDCAP_GMASK
    Tell GetGDCapability to return the pixel green color mask for the DC.
  • GDCAP_BMASK
    Tell GetGDCapability to return the pixel blue color mask for the DC.

Returns:
The capbility.

HDC GUIAPI GetPrivateClientDC HWND  hwnd  ) 
 

Returns the private client DC of a window.

This function returns the private client DC of the window hwnd which have extended style WS_EX_USEPRIVATECDC.

When a main window have the extended style WS_EX_USEPRIVATECDC, or a control class have the style CS_OWNDC, MiniGUI will create a private client DC for this window in the creation progress of the window, and destroy the DC when you destroy the window, and use this private client DC in default message handlers. So there will be some improvments on drawing/repaint performance. You can alos call this function to get the private client DC, and use it to draw anything in your window.

Parameters:
hwnd The handle to the window.
Returns:
The handle to the private client DC, HDC_INVALID indicates an error.
See also:
CreatePrivateClientDC

Uint8 *GUIAPI LockDC HDC  hdc,
const RECT rw_rc,
int *  width,
int *  height,
int *  pitch
 

Locks a dc to get direct access to pixels in the DC.

Calling this function will try to lock the DC hdc to directly access the pixels of the DC. You should tell this function the rectangle to be accessed, and the function will return the effective width, height and pitch of the DC. The access beyond effective width and height will be invalid.

Locking a DC which uses screen surface will lock some global objects, such as mouse cursor, and so on. All GDI calls of other threads (in MiniGUI-Threads) or other process (in MiniGUI-Processes) will be blocked as well. So you should call UnlockDC to unlock the DC as soon as possible, and should not call any system function in the duration of locking the DC.

Parameters:
hdc The handle to the device context.
rw_rc The rectangle in device coordinate system to be accessed in the DC.
width The width of the effective rectangle can access will be returned through this pointer.
height The height of the effective rectangle can access will be returned through this pointer.
pitch The pitch of the scan line of the DC will be returned through this pointer. Pitch means the length of the scan line in bytes.
Returns:
The bits pointer to the upper-left corner of the effective rectangle, NULL on error.
Note:
Only defined for _USE_NEWGAL.
See also:
UnlockDC
Example:

    /*
     * lock the dc and draw the scan line with random color.
     */

    int i, width, height, pitch;
    RECT rc = {0, 0, 200, 200};
    int bpp = GetGDCapability (hdc, GDCAP_BPP);
    Uint8* frame_buffer = LockDC (hdc, &rc, &width, &height, &pitch);
    Uint8* row = frame_buffer;

    for (i = 0; i < *height; i++) {
        memset (row, rand ()%0x100, *width * bpp);
        row += *pitch;
    }

    UnlockDC (hdc);

void GUIAPI ReleaseDC HDC  hdc  ) 
 

Releases a DC from DC pool.

This function releases the DC returned by GetDC or GetClientDC.

Parameters:
hdc The handle to the DC.
See also:
GetDC, GetClientDC

BOOL GUIAPI SetMemDCAlpha HDC  mem_dc,
DWORD  flags,
Uint8  alpha
 

Sets the alpha value for the entire surface of a DC, as opposed to using the alpha component of each pixel.

This function sets the alpha value for the entire surface of the DC mem_dc, as opposed to using the alpha component of each pixel. This value measures the range of transparency of the surface, 0 being completely transparent to 255 being completely opaque. An alpha value of 255 causes blits to be opaque, the source pixels copied to the destination (the default). Note that per-surface alpha can be combined with colorkey transparency.

If flags is 0, alpha blending is disabled for the surface. If flags is MEMDC_FLAG_SRCALPHA, alpha blending is enabled for the surface. OR'ing the flag with MEMDC_FLAG_RLEACCEL requests RLE acceleration for the surface; if MEMDC_FLAG_RLEACCEL is not specified, the RLE acceleration will be removed.

Parameters:
mem_dc The device context.
flags The alpha value specific memory DC flags.
alpha the alpha value for the entire surface of the DC mem_dc.
Returns:
TRUE on success, otherwise FALSE.
Note:
Only defined for _USE_NEWGAL.
See also:
SetMemDCColorKey

BOOL GUIAPI SetMemDCColorKey HDC  mem_dc,
DWORD  flags,
Uint32  color_key
 

Sets the color key (transparent pixel) of a memory DC.

This function sets the color key (transparent pixel) of the memory DC mem_dc. If flags is MEMDC_FLAG_SRCCOLORKEY (optionally OR'ed with MEMDC_FLAG_RLEACCEL), color_key will be the transparent pixel in the source DC of a blit. MEMDC_FLAG_RLEACCEL requests RLE acceleration for the source of the DC if present, and removes RLE acceleration if absent. If flags is 0, this function clears any current color key.

Parameters:
mem_dc The device context.
flags The color key specific memory DC flags.
color_key The color_key of the memory DC.
Returns:
TRUE on success, otherwise FALSE.
Note:
Only defined for _USE_NEWGAL.
See also:
SetMemDCAlpha

void GUIAPI UnlockDC HDC  hdc  ) 
 

Unlocks a locked DC.

Parameters:
hdc The locked DC.
Note:
Only defined for _USE_NEWGAL.
See also:
LockDC


Generated on Mon Jun 26 13:54:29 2006 for MiniGUI V1.6.9 API Reference by  doxygen 1.4.2