Drawing the Image

The following function draws an image and saves the client coordinates of the image's bounding rectangle. A subsequent function uses the bounding rectangle to determine whether the user has clicked the image.

// DrawTheImage - draws an image transparently and saves

// the bounding rectangle of the drawn image

// Returns TRUE if successful or FALSE otherwise.

// hwnd - handle of the window in which to draw the image

// himl - handle of the image list that contains the image

// cx and cy - client coordinates for the upper-left corner of the image

//

// Global variables and constants

// g_nImage - index of the image to draw

// g_rcImage - bounding rectangle of the image

// CX_IMAGE and CY_IMAGE - width and height of the image

extern int g_nImage;

extern RECT g_rcImage;

#define CX_IMAGE 32

#define CY_IMAGE 32

BOOL DrawTheImage(HWND hwnd, HIMAGELIST himl, int cx, int cy)

{

HDC hdc;

if ((hdc = GetDC(hwnd)) == NULL)

return FALSE;

if (!ImageList_Draw(himl, g_nImage, hdc, cx, cy, ILD_TRANSPARENT))

return FALSE;

ReleaseDC(hwnd, hdc);

SetRect(&g_rcImage, cx, cy, CX_IMAGE + cx, CY_IMAGE + cy);

return TRUE;

}

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database