📄 imagelist.c
字号:
*/
COLORREF WINAPI
ImageList_GetBkColor (HIMAGELIST himl)
{
return himl ? himl->clrBk : CLR_NONE;
}
/*************************************************************************
* ImageList_GetDragImage [COMCTL32.@]
*
* Returns the handle to the internal drag image list.
*
* PARAMS
* ppt [O] Pointer to the drag position. Can be NULL.
* pptHotspot [O] Pointer to the position of the hot spot. Can be NULL.
*
* RETURNS
* Success: Handle of the drag image list.
* Failure: NULL.
*/
HIMAGELIST WINAPI
ImageList_GetDragImage (POINT *ppt, POINT *pptHotspot)
{
if (is_valid(InternalDrag.himl)) {
if (ppt) {
ppt->x = InternalDrag.x;
ppt->y = InternalDrag.y;
}
if (pptHotspot) {
pptHotspot->x = InternalDrag.dxHotspot;
pptHotspot->y = InternalDrag.dyHotspot;
}
return (InternalDrag.himl);
}
return NULL;
}
/*************************************************************************
* ImageList_GetFlags [COMCTL32.@]
*
* Gets the flags of the specified image list.
*
* PARAMS
* himl [I] Handle to image list
*
* RETURNS
* Image list flags.
*
* BUGS
* Stub.
*/
DWORD WINAPI
ImageList_GetFlags(HIMAGELIST himl)
{
FIXME("(%p):empty stub\n", himl);
return 0;
}
/*************************************************************************
* ImageList_GetIcon [COMCTL32.@]
*
* Creates an icon from a masked image of an image list.
*
* PARAMS
* himl [I] handle to image list
* i [I] image index
* flags [I] drawing style flags
*
* RETURNS
* Success: icon handle
* Failure: NULL
*/
HICON WINAPI
ImageList_GetIcon (HIMAGELIST himl, INT i, UINT fStyle)
{
ICONINFO ii;
HICON hIcon;
HBITMAP hOldDstBitmap;
HDC hdcDst;
POINT pt;
TRACE("%p %d %d\n", himl, i, fStyle);
if (!is_valid(himl) || (i < 0) || (i >= himl->cCurImage)) return NULL;
ii.fIcon = TRUE;
ii.xHotspot = 0;
ii.yHotspot = 0;
/* create colour bitmap */
hdcDst = GetDC(0);
ii.hbmColor = CreateCompatibleBitmap(hdcDst, himl->cx, himl->cy);
ReleaseDC(0, hdcDst);
hdcDst = CreateCompatibleDC(0);
imagelist_point_from_index( himl, i, &pt );
/* draw mask*/
ii.hbmMask = CreateBitmap (himl->cx, himl->cy, 1, 1, NULL);
hOldDstBitmap = SelectObject (hdcDst, ii.hbmMask);
if (himl->hbmMask) {
BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
himl->hdcMask, pt.x, pt.y, SRCCOPY);
}
else
PatBlt (hdcDst, 0, 0, himl->cx, himl->cy, BLACKNESS);
/* draw image*/
SelectObject (hdcDst, ii.hbmColor);
BitBlt (hdcDst, 0, 0, himl->cx, himl->cy,
himl->hdcImage, pt.x, pt.y, SRCCOPY);
/*
* CreateIconIndirect requires us to deselect the bitmaps from
* the DCs before calling
*/
SelectObject(hdcDst, hOldDstBitmap);
hIcon = CreateIconIndirect (&ii);
DeleteObject (ii.hbmMask);
DeleteObject (ii.hbmColor);
DeleteDC (hdcDst);
return hIcon;
}
/*************************************************************************
* ImageList_GetIconSize [COMCTL32.@]
*
* Retrieves the size of an image in an image list.
*
* PARAMS
* himl [I] handle to image list
* cx [O] pointer to the image width.
* cy [O] pointer to the image height.
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*
* NOTES
* All images in an image list have the same size.
*/
BOOL WINAPI
ImageList_GetIconSize (HIMAGELIST himl, INT *cx, INT *cy)
{
if (!is_valid(himl))
return FALSE;
if ((himl->cx <= 0) || (himl->cy <= 0))
return FALSE;
if (cx)
*cx = himl->cx;
if (cy)
*cy = himl->cy;
return TRUE;
}
/*************************************************************************
* ImageList_GetImageCount [COMCTL32.@]
*
* Returns the number of images in an image list.
*
* PARAMS
* himl [I] handle to image list
*
* RETURNS
* Success: Number of images.
* Failure: 0
*/
INT WINAPI
ImageList_GetImageCount (HIMAGELIST himl)
{
if (!is_valid(himl))
return 0;
return himl->cCurImage;
}
/*************************************************************************
* ImageList_GetImageInfo [COMCTL32.@]
*
* Returns information about an image in an image list.
*
* PARAMS
* himl [I] handle to image list
* i [I] image index
* pImageInfo [O] pointer to the image information
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*/
BOOL WINAPI
ImageList_GetImageInfo (HIMAGELIST himl, INT i, IMAGEINFO *pImageInfo)
{
POINT pt;
if (!is_valid(himl) || (pImageInfo == NULL))
return FALSE;
if ((i < 0) || (i >= himl->cCurImage))
return FALSE;
pImageInfo->hbmImage = himl->hbmImage;
pImageInfo->hbmMask = himl->hbmMask;
imagelist_point_from_index( himl, i, &pt );
pImageInfo->rcImage.top = pt.y;
pImageInfo->rcImage.bottom = pt.y + himl->cy;
pImageInfo->rcImage.left = pt.x;
pImageInfo->rcImage.right = pt.x + himl->cx;
return TRUE;
}
/*************************************************************************
* ImageList_GetImageRect [COMCTL32.@]
*
* Retrieves the rectangle of the specified image in an image list.
*
* PARAMS
* himl [I] handle to image list
* i [I] image index
* lpRect [O] pointer to the image rectangle
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*
* NOTES
* This is an UNDOCUMENTED function!!!
*/
BOOL WINAPI
ImageList_GetImageRect (HIMAGELIST himl, INT i, LPRECT lpRect)
{
POINT pt;
if (!is_valid(himl) || (lpRect == NULL))
return FALSE;
if ((i < 0) || (i >= himl->cCurImage))
return FALSE;
imagelist_point_from_index( himl, i, &pt );
lpRect->left = pt.x;
lpRect->top = pt.y;
lpRect->right = pt.x + himl->cx;
lpRect->bottom = pt.y + himl->cy;
return TRUE;
}
/*************************************************************************
* ImageList_LoadImage [COMCTL32.@]
* ImageList_LoadImageA [COMCTL32.@]
*
* Creates an image list from a bitmap, icon or cursor.
*
* See ImageList_LoadImageW.
*/
HIMAGELIST WINAPI
ImageList_LoadImageA (HINSTANCE hi, LPCSTR lpbmp, INT cx, INT cGrow,
COLORREF clrMask, UINT uType, UINT uFlags)
{
HIMAGELIST himl;
LPWSTR lpbmpW;
DWORD len;
if (!HIWORD(lpbmp))
return ImageList_LoadImageW(hi, (LPCWSTR)lpbmp, cx, cGrow, clrMask,
uType, uFlags);
len = MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, NULL, 0);
lpbmpW = Alloc(len * sizeof(WCHAR));
MultiByteToWideChar(CP_ACP, 0, lpbmp, -1, lpbmpW, len);
himl = ImageList_LoadImageW(hi, lpbmpW, cx, cGrow, clrMask, uType, uFlags);
Free (lpbmpW);
return himl;
}
/*************************************************************************
* ImageList_LoadImageW [COMCTL32.@]
*
* Creates an image list from a bitmap, icon or cursor.
*
* PARAMS
* hi [I] instance handle
* lpbmp [I] name or id of the image
* cx [I] width of each image
* cGrow [I] number of images to expand
* clrMask [I] mask color
* uType [I] type of image to load
* uFlags [I] loading flags
*
* RETURNS
* Success: handle to the loaded image list
* Failure: NULL
*
* SEE
* LoadImage ()
*/
HIMAGELIST WINAPI
ImageList_LoadImageW (HINSTANCE hi, LPCWSTR lpbmp, INT cx, INT cGrow,
COLORREF clrMask, UINT uType, UINT uFlags)
{
HIMAGELIST himl = NULL;
HANDLE handle;
INT nImageCount;
handle = LoadImageW (hi, lpbmp, uType, 0, 0, uFlags);
if (!handle) {
ERR("Error loading image!\n");
return NULL;
}
if (uType == IMAGE_BITMAP) {
BITMAP bmp;
GetObjectW (handle, sizeof(BITMAP), &bmp);
/* To match windows behavior, if cx is set to zero and
the flag DI_DEFAULTSIZE is specified, cx becomes the
system metric value for icons. If the flag is not specified
the function sets the size to the height of the bitmap */
if (cx == 0)
{
if (uFlags & DI_DEFAULTSIZE)
cx = GetSystemMetrics (SM_CXICON);
else
cx = bmp.bmHeight;
}
nImageCount = bmp.bmWidth / cx;
himl = ImageList_Create (cx, bmp.bmHeight, ILC_MASK | ILC_COLOR,
nImageCount, cGrow);
if (!himl) {
DeleteObject (handle);
return NULL;
}
ImageList_AddMasked (himl, (HBITMAP)handle, clrMask);
}
else if ((uType == IMAGE_ICON) || (uType == IMAGE_CURSOR)) {
ICONINFO ii;
BITMAP bmp;
GetIconInfo (handle, &ii);
GetObjectW (ii.hbmColor, sizeof(BITMAP), (LPVOID)&bmp);
himl = ImageList_Create (bmp.bmWidth, bmp.bmHeight,
ILC_MASK | ILC_COLOR, 1, cGrow);
if (!himl) {
DeleteObject (ii.hbmColor);
DeleteObject (ii.hbmMask);
DeleteObject (handle);
return NULL;
}
ImageList_Add (himl, ii.hbmColor, ii.hbmMask);
DeleteObject (ii.hbmColor);
DeleteObject (ii.hbmMask);
}
DeleteObject (handle);
return himl;
}
/*************************************************************************
* ImageList_Merge [COMCTL32.@]
*
* Create an image list containing a merged image from two image lists.
*
* PARAMS
* himl1 [I] handle to first image list
* i1 [I] first image index
* himl2 [I] handle to second image list
* i2 [I] second image index
* dx [I] X offset of the second image relative to the first.
* dy [I] Y offset of the second image relative to the first.
*
* RETURNS
* Success: The newly created image list. It contains a single image
* consisting of the second image merged with the first.
* Failure: NULL, if either himl1 or himl2 are invalid.
*
* NOTES
* - The returned image list should be deleted by the caller using
* ImageList_Destroy() when it is no longer required.
* - If either i1 or i2 are not valid image indices they will be treated
* as a blank image.
*/
HIMAGELIST WINAPI
ImageList_Merge (HIMAGELIST himl1, INT i1, HIMAGELIST himl2, INT i2,
INT dx, INT dy)
{
HIMAGELIST himlDst = NULL;
INT cxDst, cyDst;
INT xOff1, yOff1, xOff2, yOff2;
POINT pt1, pt2;
TRACE("(himl1=%p i1=%d himl2=%p i2=%d dx=%d dy=%d)\n", himl1, i1, himl2,
i2, dx, dy);
if (!is_valid(himl1) || !is_valid(himl2))
return NULL;
if (dx > 0) {
cxDst = max (himl1->cx, dx + himl2->cx);
xOff1 = 0;
xOff2 = dx;
}
else if (dx < 0) {
cxDst = max (himl2->cx, himl1->cx - dx);
xOff1 = -dx;
xOff2 = 0;
}
else {
cxDst = max (himl1->cx, himl2->cx);
xOff1 = 0;
xOff2 = 0;
}
if (dy > 0) {
cyDst = max (himl1->cy, dy + himl2->cy);
yOff1 = 0;
yOff2 = dy;
}
else if (dy < 0) {
cyDst = max (himl2->cy, himl1->cy - dy);
yOff1 = -dy;
yOff2 = 0;
}
else {
cyDst = max (himl1->cy, himl2->cy);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -