L_PaintDC
#include "l_bitmap.h"
L_INT EXT_FUNCTION L_PaintDC(hDC, pBitmap, pSrc, pClipSrc, pDst, pClipDst, uROP3)
HDC hDC; |
/* handle to the target device context */ |
pBITMAPHANDLE pBitmap; |
/* pointer to the bitmap handle */ |
LPRECT pSrc; |
/* pointer to the display source rectangle */ |
LPRECT pClipSrc; |
/* pointer to the display source clipping rectangle */ |
LPRECT pDst; |
/* pointer to the display destination rectangle */ |
LPRECT pClipDst; |
/* pointer to the display destination clipping rectangle */ |
L_UINT32 uROP3; |
/* windows ROP code for display */ |
Displays any image, at any size, to any device context (screen, printer, or memory dc). If the display surface has fewer colors than the image, this function dithers the output to that display surface without affecting the actual image data.
Parameter |
Description |
hDC |
Handle to a device context, such as a screen, to use as the display surface. The mapping mode of the device context must be MM_TEXT. |
pBitmap |
Pointer to the bitmap handle referencing the bitmap to paint. |
pSrc |
Pointer to the Windows RECT structure that specifies the part of the bitmap to use as the display source. |
|
The coordinates in the RECT structure are relative to the bitmap. You can pass NULL to use the default, which matches the bitmap. |
pClipSrc |
Pointer to the Windows RECT structure that specifies the portion of the display source to paint. Generally, this is used for updating the display when part of the source bitmap has changed. |
|
The coordinates in the RECT structure are relative to the bitmap. You can pass NULL to use the default, which matches the bitmap. |
pDst |
Pointer to the Windows RECT structure that determines how the source rectangle is scaled and how the image is positioned in the device context. |
|
The coordinates in the RECT structure are relative to the device context. There is no default for this parameter. You must specify the RECT structure. |
pClipDst |
Pointer to the Windows RECT structure that specifies the portion of the display rectangle to paint. Generally, this is used for updating changes in the display surface, such as when a user moves another window, uncovering a part of the image that had been covered up. |
|
The coordinates in the RECT structure are relative to the device context. You can pass NULL to use the default, which matches the device context. In most cases, however, you should use the rectangle returned by the Windows WM_PAINT message. |
uROP3 |
The Windows ROP code that determines how the destination rectangle is updated. This parameter takes the same codes as the Windows BitBlt function. For ordinary painting, use SRCCOPY. |
Returns
SUCCESS |
The function was successful. |
< 1 |
An error occurred. Refer to Return Codes. |
Comments
This function lets you specify a source rectangle (with coordinates relative to the bitmap) and a destination rectangle (with coordinates relative to the device context). Scaling of the displayed image depends on the relationship between these two rectangles, as shown in the following illustration.
Note: |
These illustrations are for a bitmap with a TOP_LEFT view perspective. For an explanation of bitmap coordinates and view perspectives, refer to Accounting for View Perspective. If the bitmap is not in TOP_LEFT view perspective, refer to Changing Bitmap Coordinates. |
In addition, you can specify a clipping area within either rectangle to limit the area to be painted. For the destination rectangle, a clipping area is commonly specified to repaint part of the image that was temporarily covered up. For a source rectangle, you can use a clipping area to update the display when only part of the image in the source rectangle has changed.
The following illustration shows how specifying a source clipping area affects the display. Text has been added to the source bitmap (using the bitmap as a display surface), and the source clipping area specifies the area to be repainted.
You can specify the various rectangles in any way that meets your needs. Coordinates can have negative values and they can extend beyond the bounds of the bitmap or the device context. In fact, it is common for the display rectangle to be bigger than the device context, where scroll bars are used to see different parts of the image.
In simple cases, you can use this function as follows:
Required DLLs and Libraries
LTDIS For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application. |
Platforms
Windows 95 / 98 / Me, Windows 2000 / XP, Windows CE.
See Also
Functions: |
L_PaintDCBuffer, L_PaintDCEffect, L_WindowLevel, L_CreatePaintPalette, L_RectToBitmap, L_RectFromBitmap |
Topics: |
|
|
|
|
Example
For complete sample code, refer to the PAINTDC example.
/* This example shows the minimum requirements for painting an image with a palette */
BITMAPHANDLE LeadBitmap; /* Bitmap handle for the image */
void TestFunction(HWND hWnd)
{
HDC hdc; /* Device context for the current window */
RECT rLeadDest; /* Destination rectangle for painting */
HPALETTE hSavedPalette = NULL; /* Temporary copy of the current system palette */
HPALETTE hOurPalette = NULL; /* The palette that we will use to paint */
/* Get the device context */
hdc = GetDC (hWnd);
/* Set the destination rectangle to be the same as the bitmap.
Other painting rectangles can take defaults. */
SetRect(&rLeadDest, 0, 0, BITMAPWIDTH(&LeadBitmap), BITMAPHEIGHT(&LeadBitmap));
/* Create the palette that we will use to paint */
hOurPalette = L_CreatePaintPalette (hdc, &LeadBitmap);
/* Select our palette and save the old one */
hSavedPalette = SelectPalette (hdc, hOurPalette, FALSE);
/* Realize our palette */
RealizePalette (hdc);
/* Paint the image */
L_PaintDC ( hdc, /* Device context */
&LeadBitmap,/* Bitmap handle */
NULL, /* Default source rectangle */
NULL, /* Default source clip area */
&rLeadDest, /* Destination rectangle */
NULL, /* Default destination clipping rectangle */
SRCCOPY); /* ROP3 code for a Normal Paint */
/* Restore the old palette */
SelectPalette (hdc, hSavedPalette, FALSE);
/* Delete the newly created palette */
DeleteObject (hOurPalette);
/* Release the device context */
ReleaseDC(hWnd, hdc);
return;
}