2 * Cursor and icon support
4 * Copyright 1995 Alexandre Julliard
5 * 1996 Martin Von Loewis
7 * 1998 Turchanov Sergey
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
28 * Cursors and icons are stored in a global heap block, with the
31 * CURSORICONINFO info;
35 * The bits structures are in the format of a device-dependent bitmap.
37 * This layout is very sub-optimal, as the bitmap bits are stored in
38 * the X client instead of in the server like other bitmaps; however,
39 * some programs (notably Paint Brush) expect to be able to manipulate
40 * the bits directly :-(
44 #include "wine/port.h"
54 #include "wine/winbase16.h"
55 #include "wine/winuser16.h"
56 #include "wine/exception.h"
57 #include "wine/debug.h"
58 #include "user_private.h"
60 WINE_DEFAULT_DEBUG_CHANNEL(cursor);
61 WINE_DECLARE_DEBUG_CHANNEL(icon);
62 WINE_DECLARE_DEBUG_CHANNEL(resource);
75 } CURSORICONFILEDIRENTRY;
82 CURSORICONFILEDIRENTRY idEntries[1];
87 #define CID_RESOURCE 0x0001
88 #define CID_WIN32 0x0004
89 #define CID_NONSHARED 0x0008
91 static RECT CURSOR_ClipRect; /* Cursor clipping rect */
95 static const WCHAR DISPLAYW[] = {'D','I','S','P','L','A','Y',0};
97 /**********************************************************************
98 * ICONCACHE for cursors/icons loaded with LR_SHARED.
100 * FIXME: This should not be allocated on the system heap, but on a
101 * subsystem-global heap (i.e. one for all Win16 processes,
102 * and one for each Win32 process).
104 typedef struct tagICONCACHE
106 struct tagICONCACHE *next;
117 static ICONCACHE *IconAnchor = NULL;
119 static CRITICAL_SECTION IconCrst;
120 static CRITICAL_SECTION_DEBUG critsect_debug =
123 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
124 0, 0, { (DWORD_PTR)(__FILE__ ": IconCrst") }
126 static CRITICAL_SECTION IconCrst = { &critsect_debug, -1, 0, 0, 0, 0 };
128 static const WORD ICON_HOTSPOT = 0x4242;
131 /***********************************************************************
134 * Helper function to map a file to memory:
136 * [RETURN] ptr - pointer to mapped file
137 * [RETURN] filesize - pointer size of file to be stored if not NULL
139 static void *map_fileW( LPCWSTR name, LPDWORD filesize )
141 HANDLE hFile, hMapping;
144 hFile = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ, NULL,
145 OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0 );
146 if (hFile != INVALID_HANDLE_VALUE)
148 hMapping = CreateFileMappingW( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
151 ptr = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
152 CloseHandle( hMapping );
154 *filesize = GetFileSize( hFile, NULL );
156 CloseHandle( hFile );
162 /***********************************************************************
163 * get_bitmap_width_bytes
165 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
168 static int get_bitmap_width_bytes( int width, int bpp )
173 return 2 * ((width+15) / 16);
175 return 2 * ((width+3) / 4);
180 return width + (width & 1);
187 WARN("Unknown depth %d, please report.\n", bpp );
193 /***********************************************************************
194 * get_dib_width_bytes
196 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
198 static int get_dib_width_bytes( int width, int depth )
204 case 1: words = (width + 31) / 32; break;
205 case 4: words = (width + 7) / 8; break;
206 case 8: words = (width + 3) / 4; break;
208 case 16: words = (width + 1) / 2; break;
209 case 24: words = (width * 3 + 3)/4; break;
211 WARN("(%d): Unsupported depth\n", depth );
220 /***********************************************************************
223 * Return the size of the bitmap info structure including color table.
225 static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
227 int colors, masks = 0;
229 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
231 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
232 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
233 return sizeof(BITMAPCOREHEADER) + colors *
234 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
236 else /* assume BITMAPINFOHEADER */
238 colors = info->bmiHeader.biClrUsed;
239 if (colors > 256) /* buffer overflow otherwise */
241 if (!colors && (info->bmiHeader.biBitCount <= 8))
242 colors = 1 << info->bmiHeader.biBitCount;
243 if (info->bmiHeader.biCompression == BI_BITFIELDS) masks = 3;
244 return sizeof(BITMAPINFOHEADER) + masks * sizeof(DWORD) + colors *
245 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
250 /***********************************************************************
253 * Returns whether a DIB can be converted to a monochrome DDB.
255 * A DIB can be converted if its color table contains only black and
256 * white. Black must be the first color in the color table.
258 * Note : If the first color in the color table is white followed by
259 * black, we can't convert it to a monochrome DDB with
260 * SetDIBits, because black and white would be inverted.
262 static BOOL is_dib_monochrome( const BITMAPINFO* info )
264 if (info->bmiHeader.biBitCount != 1) return FALSE;
266 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
268 const RGBTRIPLE *rgb = ((const BITMAPCOREINFO*)info)->bmciColors;
270 /* Check if the first color is black */
271 if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
275 /* Check if the second color is white */
276 return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
277 && (rgb->rgbtBlue == 0xff));
281 else /* assume BITMAPINFOHEADER */
283 const RGBQUAD *rgb = info->bmiColors;
285 /* Check if the first color is black */
286 if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
287 (rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
291 /* Check if the second color is white */
292 return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
293 && (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
299 /***********************************************************************
302 * Get the info from a bitmap header.
303 * Return 1 for INFOHEADER, 0 for COREHEADER,
304 * 4 for V4HEADER, 5 for V5HEADER, -1 for error.
306 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
307 LONG *height, WORD *bpp, DWORD *compr )
309 if (header->biSize == sizeof(BITMAPINFOHEADER))
311 *width = header->biWidth;
312 *height = header->biHeight;
313 *bpp = header->biBitCount;
314 *compr = header->biCompression;
317 if (header->biSize == sizeof(BITMAPCOREHEADER))
319 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)header;
320 *width = core->bcWidth;
321 *height = core->bcHeight;
322 *bpp = core->bcBitCount;
326 if (header->biSize == sizeof(BITMAPV4HEADER))
328 const BITMAPV4HEADER *v4hdr = (const BITMAPV4HEADER *)header;
329 *width = v4hdr->bV4Width;
330 *height = v4hdr->bV4Height;
331 *bpp = v4hdr->bV4BitCount;
332 *compr = v4hdr->bV4V4Compression;
335 if (header->biSize == sizeof(BITMAPV5HEADER))
337 const BITMAPV5HEADER *v5hdr = (const BITMAPV5HEADER *)header;
338 *width = v5hdr->bV5Width;
339 *height = v5hdr->bV5Height;
340 *bpp = v5hdr->bV5BitCount;
341 *compr = v5hdr->bV5Compression;
344 ERR("(%d): unknown/wrong size for header\n", header->biSize );
348 /**********************************************************************
349 * CURSORICON_FindSharedIcon
351 static HICON CURSORICON_FindSharedIcon( HMODULE hModule, HRSRC hRsrc )
356 EnterCriticalSection( &IconCrst );
358 for ( ptr = IconAnchor; ptr; ptr = ptr->next )
359 if ( ptr->hModule == hModule && ptr->hRsrc == hRsrc )
366 LeaveCriticalSection( &IconCrst );
371 /*************************************************************************
372 * CURSORICON_FindCache
374 * Given a handle, find the corresponding cache element
377 * Handle [I] handle to an Image
380 * Success: The cache entry
384 static ICONCACHE* CURSORICON_FindCache(HICON hIcon)
387 ICONCACHE *pRet=NULL;
388 BOOL IsFound = FALSE;
390 EnterCriticalSection( &IconCrst );
392 for (ptr = IconAnchor; ptr != NULL && !IsFound; ptr = ptr->next)
394 if ( hIcon == ptr->hIcon )
401 LeaveCriticalSection( &IconCrst );
406 /**********************************************************************
407 * CURSORICON_AddSharedIcon
409 static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HICON hIcon )
411 ICONCACHE *ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(ICONCACHE) );
414 ptr->hModule = hModule;
417 ptr->hGroupRsrc = hGroupRsrc;
420 EnterCriticalSection( &IconCrst );
421 ptr->next = IconAnchor;
423 LeaveCriticalSection( &IconCrst );
426 /**********************************************************************
427 * CURSORICON_DelSharedIcon
429 static INT CURSORICON_DelSharedIcon( HICON hIcon )
434 EnterCriticalSection( &IconCrst );
436 for ( ptr = IconAnchor; ptr; ptr = ptr->next )
437 if ( ptr->hIcon == hIcon )
439 if ( ptr->count > 0 ) ptr->count--;
444 LeaveCriticalSection( &IconCrst );
449 /**********************************************************************
450 * CURSORICON_FreeModuleIcons
452 void CURSORICON_FreeModuleIcons( HMODULE16 hMod16 )
454 ICONCACHE **ptr = &IconAnchor;
455 HMODULE hModule = HMODULE_32(GetExePtr( hMod16 ));
457 EnterCriticalSection( &IconCrst );
461 if ( (*ptr)->hModule == hModule )
463 ICONCACHE *freePtr = *ptr;
464 *ptr = freePtr->next;
466 GlobalFree16(HICON_16(freePtr->hIcon));
467 HeapFree( GetProcessHeap(), 0, freePtr );
473 LeaveCriticalSection( &IconCrst );
477 * The following macro functions account for the irregularities of
478 * accessing cursor and icon resources in files and resource entries.
480 typedef BOOL (*fnGetCIEntry)( LPVOID dir, int n,
481 int *width, int *height, int *bits );
483 /**********************************************************************
484 * CURSORICON_FindBestIcon
486 * Find the icon closest to the requested size and number of colors.
488 static int CURSORICON_FindBestIcon( LPVOID dir, fnGetCIEntry get_entry,
489 int width, int height, int colors )
491 int i, cx, cy, bits, bestEntry = -1;
492 UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
493 UINT iTempXDiff, iTempYDiff, iTempColorDiff;
496 iTotalDiff = 0xFFFFFFFF;
497 iColorDiff = 0xFFFFFFFF;
498 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
500 iTempXDiff = abs(width - cx);
501 iTempYDiff = abs(height - cy);
503 if(iTotalDiff > (iTempXDiff + iTempYDiff))
507 iTotalDiff = iXDiff + iYDiff;
511 /* Find Best Colors for Best Fit */
512 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
514 if(abs(width - cx) == iXDiff && abs(height - cy) == iYDiff)
516 iTempColorDiff = abs(colors - (1<<bits));
517 if(iColorDiff > iTempColorDiff)
520 iColorDiff = iTempColorDiff;
528 static BOOL CURSORICON_GetResIconEntry( LPVOID dir, int n,
529 int *width, int *height, int *bits )
531 CURSORICONDIR *resdir = dir;
534 if ( resdir->idCount <= n )
536 icon = &resdir->idEntries[n].ResInfo.icon;
537 *width = icon->bWidth;
538 *height = icon->bHeight;
539 *bits = resdir->idEntries[n].wBitCount;
543 /**********************************************************************
544 * CURSORICON_FindBestCursor
546 * Find the cursor closest to the requested size.
548 * FIXME: parameter 'color' ignored.
550 static int CURSORICON_FindBestCursor( LPVOID dir, fnGetCIEntry get_entry,
551 int width, int height, int color )
553 int i, maxwidth, maxheight, cx, cy, bits, bestEntry = -1;
555 /* Double height to account for AND and XOR masks */
559 /* First find the largest one smaller than or equal to the requested size*/
561 maxwidth = maxheight = 0;
562 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
564 if ((cx <= width) && (cy <= height) &&
565 (cx > maxwidth) && (cy > maxheight))
572 if (bestEntry != -1) return bestEntry;
574 /* Now find the smallest one larger than the requested size */
576 maxwidth = maxheight = 255;
577 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
579 if (((cx < maxwidth) && (cy < maxheight)) || (bestEntry == -1))
590 static BOOL CURSORICON_GetResCursorEntry( LPVOID dir, int n,
591 int *width, int *height, int *bits )
593 CURSORICONDIR *resdir = dir;
596 if ( resdir->idCount <= n )
598 cursor = &resdir->idEntries[n].ResInfo.cursor;
599 *width = cursor->wWidth;
600 *height = cursor->wHeight;
601 *bits = resdir->idEntries[n].wBitCount;
605 static CURSORICONDIRENTRY *CURSORICON_FindBestIconRes( CURSORICONDIR * dir,
606 int width, int height, int colors )
610 n = CURSORICON_FindBestIcon( dir, CURSORICON_GetResIconEntry,
611 width, height, colors );
614 return &dir->idEntries[n];
617 static CURSORICONDIRENTRY *CURSORICON_FindBestCursorRes( CURSORICONDIR *dir,
618 int width, int height, int color )
620 int n = CURSORICON_FindBestCursor( dir, CURSORICON_GetResCursorEntry,
621 width, height, color );
624 return &dir->idEntries[n];
627 static BOOL CURSORICON_GetFileEntry( LPVOID dir, int n,
628 int *width, int *height, int *bits )
630 CURSORICONFILEDIR *filedir = dir;
631 CURSORICONFILEDIRENTRY *entry;
633 if ( filedir->idCount <= n )
635 entry = &filedir->idEntries[n];
636 *width = entry->bWidth;
637 *height = entry->bHeight;
638 *bits = entry->bColorCount;
642 static CURSORICONFILEDIRENTRY *CURSORICON_FindBestCursorFile( CURSORICONFILEDIR *dir,
643 int width, int height, int color )
645 int n = CURSORICON_FindBestCursor( dir, CURSORICON_GetFileEntry,
646 width, height, color );
649 return &dir->idEntries[n];
652 static CURSORICONFILEDIRENTRY *CURSORICON_FindBestIconFile( CURSORICONFILEDIR *dir,
653 int width, int height, int color )
655 int n = CURSORICON_FindBestIcon( dir, CURSORICON_GetFileEntry,
656 width, height, color );
659 return &dir->idEntries[n];
662 /***********************************************************************
665 * A helper function that stretches a bitmap buffer into an HBITMAP.
668 * hDest [I] The handle of the destination bitmap.
669 * pDestInfo [I] The BITMAPINFO of the destination bitmap.
670 * pSrcInfo [I] The BITMAPINFO of the source bitmap.
671 * pSrcBits [I] A pointer to the source bitmap buffer.
673 static BOOL stretch_blt_icon(HBITMAP hDest, BITMAPINFO *pDestInfo, BITMAPINFO *pSrcInfo, char *pSrcBits)
677 HDC hdcMem = CreateCompatibleDC(screen_dc);
681 hOld = SelectObject(hdcMem, hDest);
682 res = StretchDIBits(hdcMem,
683 0, 0, pDestInfo->bmiHeader.biWidth, pDestInfo->bmiHeader.biHeight,
684 0, 0, pSrcInfo->bmiHeader.biWidth, pSrcInfo->bmiHeader.biHeight,
685 pSrcBits, pSrcInfo, DIB_RGB_COLORS, SRCCOPY);
686 SelectObject(hdcMem, hOld);
693 static HICON CURSORICON_CreateIconFromBMI( BITMAPINFO *bmi,
694 POINT16 hotspot, BOOL bIcon,
696 INT width, INT height,
700 int sizeAnd, sizeXor;
701 HBITMAP hAndBits = 0, hXorBits = 0; /* error condition for later */
702 BITMAP bmpXor, bmpAnd;
704 BITMAPINFO *pSrcInfo, *pDestInfo;
706 if (dwVersion == 0x00020000)
708 FIXME_(cursor)("\t2.xx resources are not supported\n");
712 /* Check bitmap header */
714 if ( (bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
715 (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) ||
716 bmi->bmiHeader.biCompression != BI_RGB) )
718 WARN_(cursor)("\tinvalid resource bitmap header.\n");
722 size = bitmap_info_size( bmi, DIB_RGB_COLORS );
724 if (!width) width = bmi->bmiHeader.biWidth;
725 if (!height) height = bmi->bmiHeader.biHeight/2;
727 /* Scale the hotspot */
728 if (((bmi->bmiHeader.biHeight/2 != height) || (bmi->bmiHeader.biWidth != width)) &&
729 hotspot.x != ICON_HOTSPOT && hotspot.y != ICON_HOTSPOT)
731 hotspot.x = (hotspot.x * width) / bmi->bmiHeader.biWidth;
732 hotspot.y = (hotspot.y * height) / (bmi->bmiHeader.biHeight / 2);
735 if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
738 /* Make sure we have room for the monochrome bitmap later on.
739 * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
740 * up to and including the biBitCount. In-memory icon resource
741 * format is as follows:
743 * BITMAPINFOHEADER icHeader // DIB header
744 * RGBQUAD icColors[] // Color table
745 * BYTE icXOR[] // DIB bits for XOR mask
746 * BYTE icAND[] // DIB bits for AND mask
749 pSrcInfo = HeapAlloc( GetProcessHeap(), 0,
750 max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)));
751 pDestInfo = HeapAlloc( GetProcessHeap(), 0,
752 max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)));
753 if (pSrcInfo && pDestInfo)
755 memcpy( pSrcInfo, bmi, size );
756 pSrcInfo->bmiHeader.biHeight /= 2;
758 memcpy( pDestInfo, bmi, size );
759 pDestInfo->bmiHeader.biWidth = width;
760 pDestInfo->bmiHeader.biHeight = height;
761 pDestInfo->bmiHeader.biSizeImage = 0;
763 /* Create the XOR bitmap */
764 if(pSrcInfo->bmiHeader.biBitCount == 32)
766 void *pDIBBuffer = NULL;
767 hXorBits = CreateDIBSection(screen_dc, pDestInfo, DIB_RGB_COLORS, &pDIBBuffer, NULL, 0);
771 if (!stretch_blt_icon(hXorBits, pDestInfo, pSrcInfo, (char*)bmi + size))
773 DeleteObject(hXorBits);
780 hXorBits = CreateCompatibleBitmap(screen_dc, width, height);
784 if(!stretch_blt_icon(hXorBits, pDestInfo, pSrcInfo, (char*)bmi + size))
786 DeleteObject(hXorBits);
794 char* xbits = (char *)bmi + size +
795 get_dib_width_bytes( bmi->bmiHeader.biWidth,
796 bmi->bmiHeader.biBitCount ) * abs( bmi->bmiHeader.biHeight ) / 2;
798 pSrcInfo->bmiHeader.biBitCount = 1;
799 if (pSrcInfo->bmiHeader.biSize != sizeof(BITMAPCOREHEADER))
801 RGBQUAD *rgb = pSrcInfo->bmiColors;
803 pSrcInfo->bmiHeader.biClrUsed = pSrcInfo->bmiHeader.biClrImportant = 2;
804 rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
805 rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
806 rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
810 RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)pSrcInfo) + 1);
812 rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
813 rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
816 /* Create the AND bitmap */
817 hAndBits = CreateBitmap(width, height, 1, 1, NULL);
819 if(!stretch_blt_icon(hAndBits, pDestInfo, pSrcInfo, xbits))
821 DeleteObject(hAndBits);
827 DeleteObject( hXorBits );
833 HeapFree( GetProcessHeap(), 0, pSrcInfo );
834 HeapFree( GetProcessHeap(), 0, pDestInfo );
837 if( !hXorBits || !hAndBits )
839 WARN_(cursor)("\tunable to create an icon bitmap.\n");
843 /* Now create the CURSORICONINFO structure */
844 GetObjectA( hXorBits, sizeof(bmpXor), &bmpXor );
845 GetObjectA( hAndBits, sizeof(bmpAnd), &bmpAnd );
846 sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
847 sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
849 hObj = GlobalAlloc16( GMEM_MOVEABLE,
850 sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
853 CURSORICONINFO *info;
855 info = GlobalLock16( hObj );
856 info->ptHotSpot.x = hotspot.x;
857 info->ptHotSpot.y = hotspot.y;
858 info->nWidth = bmpXor.bmWidth;
859 info->nHeight = bmpXor.bmHeight;
860 info->nWidthBytes = bmpXor.bmWidthBytes;
861 info->bPlanes = bmpXor.bmPlanes;
862 info->bBitsPerPixel = bmpXor.bmBitsPixel;
864 /* Transfer the bitmap bits to the CURSORICONINFO structure */
866 GetBitmapBits( hAndBits, sizeAnd, info + 1 );
867 GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd );
868 GlobalUnlock16( hObj );
871 DeleteObject( hAndBits );
872 DeleteObject( hXorBits );
873 return HICON_32(hObj);
877 /**********************************************************************
878 * .ANI cursor support
880 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
881 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
882 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
884 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
885 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
886 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
887 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
888 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
889 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
891 #define ANI_FLAG_ICON 0x1
892 #define ANI_FLAG_SEQUENCE 0x2
908 const unsigned char *data;
911 static void dump_ani_header( const ani_header *header )
913 TRACE(" header size: %d\n", header->header_size);
914 TRACE(" frames: %d\n", header->num_frames);
915 TRACE(" steps: %d\n", header->num_steps);
916 TRACE(" width: %d\n", header->width);
917 TRACE(" height: %d\n", header->height);
918 TRACE(" bpp: %d\n", header->bpp);
919 TRACE(" planes: %d\n", header->num_planes);
920 TRACE(" display rate: %d\n", header->display_rate);
921 TRACE(" flags: 0x%08x\n", header->flags);
943 static void riff_find_chunk( DWORD chunk_id, DWORD chunk_type, const riff_chunk_t *parent_chunk, riff_chunk_t *chunk )
945 const unsigned char *ptr = parent_chunk->data;
946 const unsigned char *end = parent_chunk->data + (parent_chunk->data_size - (2 * sizeof(DWORD)));
948 if (chunk_type == ANI_LIST_ID || chunk_type == ANI_RIFF_ID) end -= sizeof(DWORD);
952 if ((!chunk_type && *(DWORD *)ptr == chunk_id )
953 || (chunk_type && *(DWORD *)ptr == chunk_type && *((DWORD *)ptr + 2) == chunk_id ))
955 ptr += sizeof(DWORD);
956 chunk->data_size = *(DWORD *)ptr;
957 ptr += sizeof(DWORD);
958 if (chunk_type == ANI_LIST_ID || chunk_type == ANI_RIFF_ID) ptr += sizeof(DWORD);
964 ptr += sizeof(DWORD);
965 ptr += *(DWORD *)ptr;
966 ptr += sizeof(DWORD);
974 * RIFF:'ACON' RIFF chunk
975 * |- CHUNK:'anih' Header
976 * |- CHUNK:'seq ' Sequence information (optional)
977 * \- LIST:'fram' Frame list
978 * |- CHUNK:icon Cursor frames
983 static HCURSOR CURSORICON_CreateIconFromANI( const LPBYTE bits, DWORD bits_size,
984 INT width, INT height, INT colors )
987 ani_header header = {0};
988 LPBYTE frame_bits = 0;
990 CURSORICONFILEDIRENTRY *entry;
992 riff_chunk_t root_chunk = { bits_size, bits };
993 riff_chunk_t ACON_chunk = {0};
994 riff_chunk_t anih_chunk = {0};
995 riff_chunk_t fram_chunk = {0};
996 const unsigned char *icon_data;
998 TRACE("bits %p, bits_size %d\n", bits, bits_size);
1000 if (!bits) return 0;
1002 riff_find_chunk( ANI_ACON_ID, ANI_RIFF_ID, &root_chunk, &ACON_chunk );
1003 if (!ACON_chunk.data)
1005 ERR("Failed to get root chunk.\n");
1009 riff_find_chunk( ANI_anih_ID, 0, &ACON_chunk, &anih_chunk );
1010 if (!anih_chunk.data)
1012 ERR("Failed to get 'anih' chunk.\n");
1015 memcpy( &header, anih_chunk.data, sizeof(header) );
1016 dump_ani_header( &header );
1018 riff_find_chunk( ANI_fram_ID, ANI_LIST_ID, &ACON_chunk, &fram_chunk );
1019 if (!fram_chunk.data)
1021 ERR("Failed to get icon list.\n");
1025 /* FIXME: For now, just load the first frame. Before we can load all the
1026 * frames, we need to write the needed code in wineserver, etc. to handle
1027 * cursors. Once this code is written, we can extend it to support .ani
1028 * cursors and then update user32 and winex11.drv to load all frames.
1030 * Hopefully this will at least make some games (C&C3, etc.) more playable
1033 FIXME("Loading all frames for .ani cursors not implemented.\n");
1034 icon_data = fram_chunk.data + (2 * sizeof(DWORD));
1036 entry = CURSORICON_FindBestIconFile( (CURSORICONFILEDIR *) icon_data,
1037 width, height, colors );
1039 frame_bits = HeapAlloc( GetProcessHeap(), 0, entry->dwDIBSize );
1040 memcpy( frame_bits, icon_data + entry->dwDIBOffset, entry->dwDIBSize );
1042 if (!header.width || !header.height)
1044 header.width = entry->bWidth;
1045 header.height = entry->bHeight;
1048 hotspot.x = entry->xHotspot;
1049 hotspot.y = entry->yHotspot;
1051 cursor = CURSORICON_CreateIconFromBMI( (BITMAPINFO *) frame_bits, hotspot,
1052 FALSE, 0x00030000, header.width, header.height, 0 );
1054 HeapFree( GetProcessHeap(), 0, frame_bits );
1060 /**********************************************************************
1061 * CreateIconFromResourceEx (USER32.@)
1063 * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
1064 * with cbSize parameter as well.
1066 HICON WINAPI CreateIconFromResourceEx( LPBYTE bits, UINT cbSize,
1067 BOOL bIcon, DWORD dwVersion,
1068 INT width, INT height,
1074 hotspot.x = ICON_HOTSPOT;
1075 hotspot.y = ICON_HOTSPOT;
1077 TRACE_(cursor)("%p (%u bytes), ver %08x, %ix%i %s %s\n",
1078 bits, cbSize, dwVersion, width, height,
1079 bIcon ? "icon" : "cursor", (cFlag & LR_MONOCHROME) ? "mono" : "" );
1082 bmi = (BITMAPINFO *)bits;
1083 else /* get the hotspot */
1085 POINT16 *pt = (POINT16 *)bits;
1087 bmi = (BITMAPINFO *)(pt + 1);
1090 return CURSORICON_CreateIconFromBMI( bmi, hotspot, bIcon, dwVersion,
1091 width, height, cFlag );
1095 /**********************************************************************
1096 * CreateIconFromResource (USER32.@)
1098 HICON WINAPI CreateIconFromResource( LPBYTE bits, UINT cbSize,
1099 BOOL bIcon, DWORD dwVersion)
1101 return CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, 0,0,0);
1105 static HICON CURSORICON_LoadFromFile( LPCWSTR filename,
1106 INT width, INT height, INT colors,
1107 BOOL fCursor, UINT loadflags)
1109 CURSORICONFILEDIRENTRY *entry;
1110 CURSORICONFILEDIR *dir;
1116 TRACE("loading %s\n", debugstr_w( filename ));
1118 bits = map_fileW( filename, &filesize );
1122 /* Check for .ani. */
1123 if (memcmp( bits, "RIFF", 4 ) == 0)
1125 hIcon = CURSORICON_CreateIconFromANI( bits, filesize, width, height,
1130 dir = (CURSORICONFILEDIR*) bits;
1131 if ( filesize < sizeof(*dir) )
1134 if ( filesize < (sizeof(*dir) + sizeof(dir->idEntries[0])*(dir->idCount-1)) )
1138 entry = CURSORICON_FindBestCursorFile( dir, width, height, colors );
1140 entry = CURSORICON_FindBestIconFile( dir, width, height, colors );
1145 /* check that we don't run off the end of the file */
1146 if ( entry->dwDIBOffset > filesize )
1148 if ( entry->dwDIBOffset + entry->dwDIBSize > filesize )
1151 /* Set the actual hotspot for cursors and ICON_HOTSPOT for icons. */
1154 hotspot.x = entry->xHotspot;
1155 hotspot.y = entry->yHotspot;
1159 hotspot.x = ICON_HOTSPOT;
1160 hotspot.y = ICON_HOTSPOT;
1162 hIcon = CURSORICON_CreateIconFromBMI( (BITMAPINFO *)&bits[entry->dwDIBOffset],
1163 hotspot, !fCursor, 0x00030000,
1164 width, height, loadflags );
1166 TRACE("loaded %s -> %p\n", debugstr_w( filename ), hIcon );
1167 UnmapViewOfFile( bits );
1171 /**********************************************************************
1174 * Load a cursor or icon from resource or file.
1176 static HICON CURSORICON_Load(HINSTANCE hInstance, LPCWSTR name,
1177 INT width, INT height, INT colors,
1178 BOOL fCursor, UINT loadflags)
1182 HRSRC hRsrc, hGroupRsrc;
1184 CURSORICONDIRENTRY *dirEntry;
1189 TRACE("%p, %s, %dx%d, colors %d, fCursor %d, flags 0x%04x\n",
1190 hInstance, debugstr_w(name), width, height, colors, fCursor, loadflags);
1192 if ( loadflags & LR_LOADFROMFILE ) /* Load from file */
1193 return CURSORICON_LoadFromFile( name, width, height, colors, fCursor, loadflags );
1195 if (!hInstance) hInstance = user32_module; /* Load OEM cursor/icon */
1197 /* Normalize hInstance (must be uniquely represented for icon cache) */
1199 if (!HIWORD( hInstance ))
1200 hInstance = HINSTANCE_32(GetExePtr( HINSTANCE_16(hInstance) ));
1202 /* Get directory resource ID */
1204 if (!(hRsrc = FindResourceW( hInstance, name,
1205 (LPWSTR)(fCursor ? RT_GROUP_CURSOR : RT_GROUP_ICON) )))
1209 /* Find the best entry in the directory */
1211 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
1212 if (!(dir = LockResource( handle ))) return 0;
1214 dirEntry = CURSORICON_FindBestCursorRes( dir, width, height, colors );
1216 dirEntry = CURSORICON_FindBestIconRes( dir, width, height, colors );
1217 if (!dirEntry) return 0;
1218 wResId = dirEntry->wResId;
1219 dwBytesInRes = dirEntry->dwBytesInRes;
1220 FreeResource( handle );
1222 /* Load the resource */
1224 if (!(hRsrc = FindResourceW(hInstance,MAKEINTRESOURCEW(wResId),
1225 (LPWSTR)(fCursor ? RT_CURSOR : RT_ICON) ))) return 0;
1227 /* If shared icon, check whether it was already loaded */
1228 if ( (loadflags & LR_SHARED)
1229 && (hIcon = CURSORICON_FindSharedIcon( hInstance, hRsrc ) ) != 0 )
1232 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
1233 bits = LockResource( handle );
1234 hIcon = CreateIconFromResourceEx( bits, dwBytesInRes,
1235 !fCursor, 0x00030000, width, height, loadflags);
1236 FreeResource( handle );
1238 /* If shared icon, add to icon cache */
1240 if ( hIcon && (loadflags & LR_SHARED) )
1241 CURSORICON_AddSharedIcon( hInstance, hRsrc, hGroupRsrc, hIcon );
1246 /***********************************************************************
1249 * Make a copy of a cursor or icon.
1251 static HICON CURSORICON_Copy( HINSTANCE16 hInst16, HICON hIcon )
1253 char *ptrOld, *ptrNew;
1255 HICON16 hOld = HICON_16(hIcon);
1258 if (!(ptrOld = GlobalLock16( hOld ))) return 0;
1259 if (hInst16 && !(hInst16 = GetExePtr( hInst16 ))) return 0;
1260 size = GlobalSize16( hOld );
1261 hNew = GlobalAlloc16( GMEM_MOVEABLE, size );
1262 FarSetOwner16( hNew, hInst16 );
1263 ptrNew = GlobalLock16( hNew );
1264 memcpy( ptrNew, ptrOld, size );
1265 GlobalUnlock16( hOld );
1266 GlobalUnlock16( hNew );
1267 return HICON_32(hNew);
1270 /*************************************************************************
1271 * CURSORICON_ExtCopy
1273 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified
1276 * Handle [I] handle to an Image
1277 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON)
1278 * iDesiredCX [I] The Desired width of the Image
1279 * iDesiredCY [I] The desired height of the Image
1280 * nFlags [I] The flags from CopyImage
1283 * Success: The new handle of the Image
1286 * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented.
1287 * LR_MONOCHROME should be implemented by CreateIconFromResourceEx.
1288 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache.
1293 static HICON CURSORICON_ExtCopy(HICON hIcon, UINT nType,
1294 INT iDesiredCX, INT iDesiredCY,
1299 TRACE_(icon)("hIcon %p, nType %u, iDesiredCX %i, iDesiredCY %i, nFlags %u\n",
1300 hIcon, nType, iDesiredCX, iDesiredCY, nFlags);
1307 /* Best Fit or Monochrome */
1308 if( (nFlags & LR_COPYFROMRESOURCE
1309 && (iDesiredCX > 0 || iDesiredCY > 0))
1310 || nFlags & LR_MONOCHROME)
1312 ICONCACHE* pIconCache = CURSORICON_FindCache(hIcon);
1314 /* Not Found in Cache, then do a straight copy
1316 if(pIconCache == NULL)
1318 hNew = CURSORICON_Copy(0, hIcon);
1319 if(nFlags & LR_COPYFROMRESOURCE)
1321 TRACE_(icon)("LR_COPYFROMRESOURCE: Failed to load from cache\n");
1326 int iTargetCY = iDesiredCY, iTargetCX = iDesiredCX;
1332 CURSORICONDIR *pDir;
1333 CURSORICONDIRENTRY *pDirEntry;
1334 BOOL bIsIcon = (nType == IMAGE_ICON);
1336 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
1338 if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE))
1339 || (iDesiredCX == 0 && iDesiredCY == 0))
1341 iDesiredCY = GetSystemMetrics(bIsIcon ?
1342 SM_CYICON : SM_CYCURSOR);
1343 iDesiredCX = GetSystemMetrics(bIsIcon ?
1344 SM_CXICON : SM_CXCURSOR);
1347 /* Retrieve the CURSORICONDIRENTRY
1349 if (!(hMem = LoadResource( pIconCache->hModule ,
1350 pIconCache->hGroupRsrc)))
1354 if (!(pDir = LockResource( hMem )))
1363 pDirEntry = CURSORICON_FindBestIconRes(
1364 pDir, iDesiredCX, iDesiredCY, 256 );
1368 pDirEntry = CURSORICON_FindBestCursorRes(
1369 pDir, iDesiredCX, iDesiredCY, 1);
1372 wResId = pDirEntry->wResId;
1373 dwBytesInRes = pDirEntry->dwBytesInRes;
1376 TRACE_(icon)("ResID %u, BytesInRes %u, Width %d, Height %d DX %d, DY %d\n",
1377 wResId, dwBytesInRes, pDirEntry->ResInfo.icon.bWidth,
1378 pDirEntry->ResInfo.icon.bHeight, iDesiredCX, iDesiredCY);
1382 if (!(hRsrc = FindResourceW(pIconCache->hModule ,
1383 MAKEINTRESOURCEW(wResId), (LPWSTR)(bIsIcon ? RT_ICON : RT_CURSOR))))
1387 if (!(hMem = LoadResource( pIconCache->hModule , hRsrc )))
1392 pBits = LockResource( hMem );
1394 if(nFlags & LR_DEFAULTSIZE)
1396 iTargetCY = GetSystemMetrics(SM_CYICON);
1397 iTargetCX = GetSystemMetrics(SM_CXICON);
1400 /* Create a New Icon with the proper dimension
1402 hNew = CreateIconFromResourceEx( pBits, dwBytesInRes,
1403 bIsIcon, 0x00030000, iTargetCX, iTargetCY, nFlags);
1407 else hNew = CURSORICON_Copy(0, hIcon);
1412 /***********************************************************************
1413 * CreateCursor (USER32.@)
1415 HCURSOR WINAPI CreateCursor( HINSTANCE hInstance,
1416 INT xHotSpot, INT yHotSpot,
1417 INT nWidth, INT nHeight,
1418 LPCVOID lpANDbits, LPCVOID lpXORbits )
1420 CURSORICONINFO info;
1422 TRACE_(cursor)("%dx%d spot=%d,%d xor=%p and=%p\n",
1423 nWidth, nHeight, xHotSpot, yHotSpot, lpXORbits, lpANDbits);
1425 info.ptHotSpot.x = xHotSpot;
1426 info.ptHotSpot.y = yHotSpot;
1427 info.nWidth = nWidth;
1428 info.nHeight = nHeight;
1429 info.nWidthBytes = 0;
1431 info.bBitsPerPixel = 1;
1433 return HICON_32(CreateCursorIconIndirect16(0, &info, lpANDbits, lpXORbits));
1437 /***********************************************************************
1438 * CreateIcon (USER.407)
1440 HICON16 WINAPI CreateIcon16( HINSTANCE16 hInstance, INT16 nWidth,
1441 INT16 nHeight, BYTE bPlanes, BYTE bBitsPixel,
1442 LPCVOID lpANDbits, LPCVOID lpXORbits )
1444 CURSORICONINFO info;
1446 TRACE_(icon)("%dx%dx%d, xor=%p, and=%p\n",
1447 nWidth, nHeight, bPlanes * bBitsPixel, lpXORbits, lpANDbits);
1449 info.ptHotSpot.x = ICON_HOTSPOT;
1450 info.ptHotSpot.y = ICON_HOTSPOT;
1451 info.nWidth = nWidth;
1452 info.nHeight = nHeight;
1453 info.nWidthBytes = 0;
1454 info.bPlanes = bPlanes;
1455 info.bBitsPerPixel = bBitsPixel;
1457 return CreateCursorIconIndirect16( hInstance, &info, lpANDbits, lpXORbits );
1461 /***********************************************************************
1462 * CreateIcon (USER32.@)
1464 * Creates an icon based on the specified bitmaps. The bitmaps must be
1465 * provided in a device dependent format and will be resized to
1466 * (SM_CXICON,SM_CYICON) and depth converted to match the screen's color
1467 * depth. The provided bitmaps must be top-down bitmaps.
1468 * Although Windows does not support 15bpp(*) this API must support it
1469 * for Winelib applications.
1471 * (*) Windows does not support 15bpp but it supports the 555 RGB 16bpp
1475 * Success: handle to an icon
1478 * FIXME: Do we need to resize the bitmaps?
1480 HICON WINAPI CreateIcon(
1481 HINSTANCE hInstance, /* [in] the application's hInstance */
1482 INT nWidth, /* [in] the width of the provided bitmaps */
1483 INT nHeight, /* [in] the height of the provided bitmaps */
1484 BYTE bPlanes, /* [in] the number of planes in the provided bitmaps */
1485 BYTE bBitsPixel, /* [in] the number of bits per pixel of the lpXORbits bitmap */
1486 LPCVOID lpANDbits, /* [in] a monochrome bitmap representing the icon's mask */
1487 LPCVOID lpXORbits) /* [in] the icon's 'color' bitmap */
1492 TRACE_(icon)("%dx%d, planes %d, bpp %d, xor %p, and %p\n",
1493 nWidth, nHeight, bPlanes, bBitsPixel, lpXORbits, lpANDbits);
1496 iinfo.xHotspot = ICON_HOTSPOT;
1497 iinfo.yHotspot = ICON_HOTSPOT;
1498 iinfo.hbmMask = CreateBitmap( nWidth, nHeight, 1, 1, lpANDbits );
1499 iinfo.hbmColor = CreateBitmap( nWidth, nHeight, bPlanes, bBitsPixel, lpXORbits );
1501 hIcon = CreateIconIndirect( &iinfo );
1503 DeleteObject( iinfo.hbmMask );
1504 DeleteObject( iinfo.hbmColor );
1510 /***********************************************************************
1511 * CreateCursorIconIndirect (USER.408)
1513 HGLOBAL16 WINAPI CreateCursorIconIndirect16( HINSTANCE16 hInstance,
1514 CURSORICONINFO *info,
1520 int sizeAnd, sizeXor;
1522 hInstance = GetExePtr( hInstance ); /* Make it a module handle */
1523 if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
1524 info->nWidthBytes = get_bitmap_width_bytes(info->nWidth,info->bBitsPerPixel);
1525 sizeXor = info->nHeight * info->nWidthBytes;
1526 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
1527 if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
1528 sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
1530 FarSetOwner16( handle, hInstance );
1531 ptr = GlobalLock16( handle );
1532 memcpy( ptr, info, sizeof(*info) );
1533 memcpy( ptr + sizeof(CURSORICONINFO), lpANDbits, sizeAnd );
1534 memcpy( ptr + sizeof(CURSORICONINFO) + sizeAnd, lpXORbits, sizeXor );
1535 GlobalUnlock16( handle );
1540 /***********************************************************************
1541 * CopyIcon (USER.368)
1543 HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
1545 TRACE_(icon)("%04x %04x\n", hInstance, hIcon );
1546 return HICON_16(CURSORICON_Copy(hInstance, HICON_32(hIcon)));
1550 /***********************************************************************
1551 * CopyIcon (USER32.@)
1553 HICON WINAPI CopyIcon( HICON hIcon )
1555 TRACE_(icon)("%p\n", hIcon );
1556 return CURSORICON_Copy( 0, hIcon );
1560 /***********************************************************************
1561 * CopyCursor (USER.369)
1563 HCURSOR16 WINAPI CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
1565 TRACE_(cursor)("%04x %04x\n", hInstance, hCursor );
1566 return HICON_16(CURSORICON_Copy(hInstance, HCURSOR_32(hCursor)));
1569 /**********************************************************************
1570 * DestroyIcon32 (USER.610)
1572 * This routine is actually exported from Win95 USER under the name
1573 * DestroyIcon32 ... The behaviour implemented here should mimic
1574 * the Win95 one exactly, especially the return values, which
1575 * depend on the setting of various flags.
1577 WORD WINAPI DestroyIcon32( HGLOBAL16 handle, UINT16 flags )
1581 TRACE_(icon)("(%04x, %04x)\n", handle, flags );
1583 /* Check whether destroying active cursor */
1585 if ( get_user_thread_info()->cursor == HICON_32(handle) )
1587 WARN_(cursor)("Destroying active cursor!\n" );
1591 /* Try shared cursor/icon first */
1593 if ( !(flags & CID_NONSHARED) )
1595 INT count = CURSORICON_DelSharedIcon(HICON_32(handle));
1598 return (flags & CID_WIN32)? TRUE : (count == 0);
1600 /* FIXME: OEM cursors/icons should be recognized */
1603 /* Now assume non-shared cursor/icon */
1605 retv = GlobalFree16( handle );
1606 return (flags & CID_RESOURCE)? retv : TRUE;
1609 /***********************************************************************
1610 * DestroyIcon (USER32.@)
1612 BOOL WINAPI DestroyIcon( HICON hIcon )
1614 return DestroyIcon32(HICON_16(hIcon), CID_WIN32);
1618 /***********************************************************************
1619 * DestroyCursor (USER32.@)
1621 BOOL WINAPI DestroyCursor( HCURSOR hCursor )
1623 return DestroyIcon32(HCURSOR_16(hCursor), CID_WIN32);
1626 /***********************************************************************
1627 * bitmap_has_alpha_channel
1629 * Analyses bits bitmap to determine if alpha data is present.
1632 * bpp [I] The bits-per-pixel of the bitmap
1633 * bitmapBits [I] A pointer to the bitmap data
1634 * bitmapLength [I] The length of the bitmap in bytes
1637 * TRUE if an alpha channel is discovered, FALSE
1640 * Windows' behaviour is that if the icon bitmap is 32-bit and at
1641 * least one pixel has a non-zero alpha, then the bitmap is a
1642 * treated as having an alpha channel transparentcy. Otherwise,
1643 * it's treated as being completely opaque.
1646 static BOOL bitmap_has_alpha_channel( int bpp, unsigned char *bitmapBits,
1647 unsigned int bitmapLength )
1649 /* Detect an alpha channel by looking for non-zero alpha pixels */
1652 unsigned int offset;
1653 for(offset = 3; offset < bitmapLength; offset += 4)
1655 if(bitmapBits[offset] != 0)
1664 /***********************************************************************
1665 * premultiply_alpha_channel
1667 * Premultiplies the color channels of a 32-bit bitmap by the alpha
1668 * channel. This is a necessary step that must be carried out on
1669 * the image before it is passed to GdiAlphaBlend
1672 * destBitmap [I] The destination bitmap buffer
1673 * srcBitmap [I] The source bitmap buffer
1674 * bitmapLength [I] The length of the bitmap in bytes
1677 static void premultiply_alpha_channel( unsigned char *destBitmap,
1678 unsigned char *srcBitmap,
1679 unsigned int bitmapLength )
1681 unsigned char *destPixel = destBitmap;
1682 unsigned char *srcPixel = srcBitmap;
1684 while(destPixel < destBitmap + bitmapLength)
1686 unsigned char alpha = srcPixel[3];
1687 *(destPixel++) = *(srcPixel++) * alpha / 255;
1688 *(destPixel++) = *(srcPixel++) * alpha / 255;
1689 *(destPixel++) = *(srcPixel++) * alpha / 255;
1690 *(destPixel++) = *(srcPixel++);
1694 /***********************************************************************
1695 * DrawIcon (USER32.@)
1697 BOOL WINAPI DrawIcon( HDC hdc, INT x, INT y, HICON hIcon )
1699 CURSORICONINFO *ptr;
1701 HBITMAP hXorBits = NULL, hAndBits = NULL, hBitTemp = NULL;
1702 COLORREF oldFg, oldBg;
1703 unsigned char *xorBitmapBits;
1704 unsigned int dibLength;
1706 TRACE("%p, (%d,%d), %p\n", hdc, x, y, hIcon);
1708 if (!(ptr = GlobalLock16(HICON_16(hIcon)))) return FALSE;
1709 if (!(hMemDC = CreateCompatibleDC( hdc ))) return FALSE;
1711 dibLength = ptr->nHeight * get_bitmap_width_bytes(
1712 ptr->nWidth, ptr->bBitsPerPixel);
1714 xorBitmapBits = (unsigned char *)(ptr + 1) + ptr->nHeight *
1715 get_bitmap_width_bytes(ptr->nWidth, 1);
1717 oldFg = SetTextColor( hdc, RGB(0,0,0) );
1718 oldBg = SetBkColor( hdc, RGB(255,255,255) );
1720 if(bitmap_has_alpha_channel(ptr->bBitsPerPixel, xorBitmapBits, dibLength))
1722 BITMAPINFOHEADER bmih;
1723 unsigned char *dibBits;
1725 memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
1726 bmih.biSize = sizeof(BITMAPINFOHEADER);
1727 bmih.biWidth = ptr->nWidth;
1728 bmih.biHeight = -ptr->nHeight;
1729 bmih.biPlanes = ptr->bPlanes;
1730 bmih.biBitCount = 32;
1731 bmih.biCompression = BI_RGB;
1733 hXorBits = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
1734 (void*)&dibBits, NULL, 0);
1736 if (hXorBits && dibBits)
1738 BLENDFUNCTION pixelblend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
1740 /* Do the alpha blending render */
1741 premultiply_alpha_channel(dibBits, xorBitmapBits, dibLength);
1742 hBitTemp = SelectObject( hMemDC, hXorBits );
1743 /* Destination width/height has to be "System Large" size */
1744 GdiAlphaBlend(hdc, x, y, GetSystemMetrics(SM_CXICON),
1745 GetSystemMetrics(SM_CYICON), hMemDC,
1746 0, 0, ptr->nWidth, ptr->nHeight, pixelblend);
1747 SelectObject( hMemDC, hBitTemp );
1752 hAndBits = CreateBitmap( ptr->nWidth, ptr->nHeight, 1, 1, ptr + 1 );
1753 hXorBits = CreateBitmap( ptr->nWidth, ptr->nHeight, ptr->bPlanes,
1754 ptr->bBitsPerPixel, xorBitmapBits);
1756 if (hXorBits && hAndBits)
1758 hBitTemp = SelectObject( hMemDC, hAndBits );
1759 StretchBlt( hdc, x, y, GetSystemMetrics(SM_CXICON),
1760 GetSystemMetrics(SM_CYICON), hMemDC, 0, 0,
1761 ptr->nWidth, ptr->nHeight, SRCAND );
1762 SelectObject( hMemDC, hXorBits );
1763 StretchBlt( hdc, x, y, GetSystemMetrics(SM_CXICON),
1764 GetSystemMetrics(SM_CYICON), hMemDC, 0, 0,
1765 ptr->nWidth, ptr->nHeight, SRCINVERT );
1766 SelectObject( hMemDC, hBitTemp );
1771 if (hXorBits) DeleteObject( hXorBits );
1772 if (hAndBits) DeleteObject( hAndBits );
1773 GlobalUnlock16(HICON_16(hIcon));
1774 SetTextColor( hdc, oldFg );
1775 SetBkColor( hdc, oldBg );
1779 /***********************************************************************
1780 * DumpIcon (USER.459)
1782 DWORD WINAPI DumpIcon16( SEGPTR pInfo, WORD *lpLen,
1783 SEGPTR *lpXorBits, SEGPTR *lpAndBits )
1785 CURSORICONINFO *info = MapSL( pInfo );
1786 int sizeAnd, sizeXor;
1788 if (!info) return 0;
1789 sizeXor = info->nHeight * info->nWidthBytes;
1790 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
1791 if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO);
1792 if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd;
1793 if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
1794 return MAKELONG( sizeXor, sizeXor );
1798 /***********************************************************************
1799 * SetCursor (USER32.@)
1801 * Set the cursor shape.
1804 * A handle to the previous cursor shape.
1806 HCURSOR WINAPI SetCursor( HCURSOR hCursor /* [in] Handle of cursor to show */ )
1808 struct user_thread_info *thread_info = get_user_thread_info();
1811 if (hCursor == thread_info->cursor) return hCursor; /* No change */
1812 TRACE("%p\n", hCursor);
1813 hOldCursor = thread_info->cursor;
1814 thread_info->cursor = hCursor;
1815 /* Change the cursor shape only if it is visible */
1816 if (thread_info->cursor_count >= 0)
1818 USER_Driver->pSetCursor(GlobalLock16(HCURSOR_16(hCursor)));
1819 GlobalUnlock16(HCURSOR_16(hCursor));
1824 /***********************************************************************
1825 * ShowCursor (USER32.@)
1827 INT WINAPI ShowCursor( BOOL bShow )
1829 struct user_thread_info *thread_info = get_user_thread_info();
1831 TRACE("%d, count=%d\n", bShow, thread_info->cursor_count );
1835 if (++thread_info->cursor_count == 0) /* Show it */
1837 USER_Driver->pSetCursor(GlobalLock16(HCURSOR_16(thread_info->cursor)));
1838 GlobalUnlock16(HCURSOR_16(thread_info->cursor));
1843 if (--thread_info->cursor_count == -1) /* Hide it */
1844 USER_Driver->pSetCursor( NULL );
1846 return thread_info->cursor_count;
1849 /***********************************************************************
1850 * GetCursor (USER32.@)
1852 HCURSOR WINAPI GetCursor(void)
1854 return get_user_thread_info()->cursor;
1858 /***********************************************************************
1859 * ClipCursor (USER32.@)
1861 BOOL WINAPI ClipCursor( const RECT *rect )
1865 SetRect( &virt, 0, 0, GetSystemMetrics( SM_CXVIRTUALSCREEN ),
1866 GetSystemMetrics( SM_CYVIRTUALSCREEN ) );
1867 OffsetRect( &virt, GetSystemMetrics( SM_XVIRTUALSCREEN ),
1868 GetSystemMetrics( SM_YVIRTUALSCREEN ) );
1870 TRACE( "Clipping to: %s was: %s screen: %s\n", wine_dbgstr_rect(rect),
1871 wine_dbgstr_rect(&CURSOR_ClipRect), wine_dbgstr_rect(&virt) );
1873 if (!IntersectRect( &CURSOR_ClipRect, &virt, rect ))
1874 CURSOR_ClipRect = virt;
1876 USER_Driver->pClipCursor( rect );
1881 /***********************************************************************
1882 * GetClipCursor (USER32.@)
1884 BOOL WINAPI GetClipCursor( RECT *rect )
1886 /* If this is first time - initialize the rect */
1887 if (IsRectEmpty( &CURSOR_ClipRect )) ClipCursor( NULL );
1889 return CopyRect( rect, &CURSOR_ClipRect );
1893 /***********************************************************************
1894 * SetSystemCursor (USER32.@)
1896 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
1898 FIXME("(%p,%08x),stub!\n", hcur, id);
1903 /**********************************************************************
1904 * LookupIconIdFromDirectoryEx (USER.364)
1906 * FIXME: exact parameter sizes
1908 INT16 WINAPI LookupIconIdFromDirectoryEx16( LPBYTE dir, BOOL16 bIcon,
1909 INT16 width, INT16 height, UINT16 cFlag )
1911 return LookupIconIdFromDirectoryEx( dir, bIcon, width, height, cFlag );
1914 /**********************************************************************
1915 * LookupIconIdFromDirectoryEx (USER32.@)
1917 INT WINAPI LookupIconIdFromDirectoryEx( LPBYTE xdir, BOOL bIcon,
1918 INT width, INT height, UINT cFlag )
1920 CURSORICONDIR *dir = (CURSORICONDIR*)xdir;
1922 if( dir && !dir->idReserved && (dir->idType & 3) )
1924 CURSORICONDIRENTRY* entry;
1929 palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
1932 colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts;
1937 entry = CURSORICON_FindBestIconRes( dir, width, height, colors );
1939 entry = CURSORICON_FindBestCursorRes( dir, width, height, colors );
1941 if( entry ) retVal = entry->wResId;
1943 else WARN_(cursor)("invalid resource directory\n");
1947 /**********************************************************************
1948 * LookupIconIdFromDirectory (USER32.@)
1950 INT WINAPI LookupIconIdFromDirectory( LPBYTE dir, BOOL bIcon )
1952 return LookupIconIdFromDirectoryEx( dir, bIcon,
1953 bIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
1954 bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME );
1957 /**********************************************************************
1958 * GetIconID (USER.455)
1960 WORD WINAPI GetIconID16( HGLOBAL16 hResource, DWORD resType )
1962 LPBYTE lpDir = GlobalLock16(hResource);
1964 TRACE_(cursor)("hRes=%04x, entries=%i\n",
1965 hResource, lpDir ? ((CURSORICONDIR*)lpDir)->idCount : 0);
1970 return (WORD)LookupIconIdFromDirectoryEx16( lpDir, FALSE,
1971 GetSystemMetrics(SM_CXCURSOR), GetSystemMetrics(SM_CYCURSOR), LR_MONOCHROME );
1973 return (WORD)LookupIconIdFromDirectoryEx16( lpDir, TRUE,
1974 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0 );
1976 WARN_(cursor)("invalid res type %d\n", resType );
1981 /**********************************************************************
1982 * LoadCursorIconHandler (USER.336)
1984 * Supposed to load resources of Windows 2.x applications.
1986 HGLOBAL16 WINAPI LoadCursorIconHandler16( HGLOBAL16 hResource, HMODULE16 hModule, HRSRC16 hRsrc )
1988 FIXME_(cursor)("(%04x,%04x,%04x): old 2.x resources are not supported!\n",
1989 hResource, hModule, hRsrc);
1993 /**********************************************************************
1994 * LoadIconHandler (USER.456)
1996 HICON16 WINAPI LoadIconHandler16( HGLOBAL16 hResource, BOOL16 bNew )
1998 LPBYTE bits = LockResource16( hResource );
2000 TRACE_(cursor)("hRes=%04x\n",hResource);
2002 return HICON_16(CreateIconFromResourceEx( bits, 0, TRUE,
2003 bNew ? 0x00030000 : 0x00020000, 0, 0, LR_DEFAULTCOLOR));
2006 /***********************************************************************
2007 * LoadCursorW (USER32.@)
2009 HCURSOR WINAPI LoadCursorW(HINSTANCE hInstance, LPCWSTR name)
2011 TRACE("%p, %s\n", hInstance, debugstr_w(name));
2013 return LoadImageW( hInstance, name, IMAGE_CURSOR, 0, 0,
2014 LR_SHARED | LR_DEFAULTSIZE );
2017 /***********************************************************************
2018 * LoadCursorA (USER32.@)
2020 HCURSOR WINAPI LoadCursorA(HINSTANCE hInstance, LPCSTR name)
2022 TRACE("%p, %s\n", hInstance, debugstr_a(name));
2024 return LoadImageA( hInstance, name, IMAGE_CURSOR, 0, 0,
2025 LR_SHARED | LR_DEFAULTSIZE );
2028 /***********************************************************************
2029 * LoadCursorFromFileW (USER32.@)
2031 HCURSOR WINAPI LoadCursorFromFileW (LPCWSTR name)
2033 TRACE("%s\n", debugstr_w(name));
2035 return LoadImageW( 0, name, IMAGE_CURSOR, 0, 0,
2036 LR_LOADFROMFILE | LR_DEFAULTSIZE );
2039 /***********************************************************************
2040 * LoadCursorFromFileA (USER32.@)
2042 HCURSOR WINAPI LoadCursorFromFileA (LPCSTR name)
2044 TRACE("%s\n", debugstr_a(name));
2046 return LoadImageA( 0, name, IMAGE_CURSOR, 0, 0,
2047 LR_LOADFROMFILE | LR_DEFAULTSIZE );
2050 /***********************************************************************
2051 * LoadIconW (USER32.@)
2053 HICON WINAPI LoadIconW(HINSTANCE hInstance, LPCWSTR name)
2055 TRACE("%p, %s\n", hInstance, debugstr_w(name));
2057 return LoadImageW( hInstance, name, IMAGE_ICON, 0, 0,
2058 LR_SHARED | LR_DEFAULTSIZE );
2061 /***********************************************************************
2062 * LoadIconA (USER32.@)
2064 HICON WINAPI LoadIconA(HINSTANCE hInstance, LPCSTR name)
2066 TRACE("%p, %s\n", hInstance, debugstr_a(name));
2068 return LoadImageA( hInstance, name, IMAGE_ICON, 0, 0,
2069 LR_SHARED | LR_DEFAULTSIZE );
2072 /**********************************************************************
2073 * GetIconInfo (USER32.@)
2075 BOOL WINAPI GetIconInfo(HICON hIcon, PICONINFO iconinfo)
2077 CURSORICONINFO *ciconinfo;
2080 ciconinfo = GlobalLock16(HICON_16(hIcon));
2084 TRACE("%p => %dx%d, %d bpp\n", hIcon,
2085 ciconinfo->nWidth, ciconinfo->nHeight, ciconinfo->bBitsPerPixel);
2087 if ( (ciconinfo->ptHotSpot.x == ICON_HOTSPOT) &&
2088 (ciconinfo->ptHotSpot.y == ICON_HOTSPOT) )
2090 iconinfo->fIcon = TRUE;
2091 iconinfo->xHotspot = ciconinfo->nWidth / 2;
2092 iconinfo->yHotspot = ciconinfo->nHeight / 2;
2096 iconinfo->fIcon = FALSE;
2097 iconinfo->xHotspot = ciconinfo->ptHotSpot.x;
2098 iconinfo->yHotspot = ciconinfo->ptHotSpot.y;
2101 height = ciconinfo->nHeight;
2103 if (ciconinfo->bBitsPerPixel > 1)
2105 iconinfo->hbmColor = CreateBitmap( ciconinfo->nWidth, ciconinfo->nHeight,
2106 ciconinfo->bPlanes, ciconinfo->bBitsPerPixel,
2107 (char *)(ciconinfo + 1)
2108 + ciconinfo->nHeight *
2109 get_bitmap_width_bytes (ciconinfo->nWidth,1) );
2113 iconinfo->hbmColor = 0;
2117 iconinfo->hbmMask = CreateBitmap ( ciconinfo->nWidth, height,
2118 1, 1, ciconinfo + 1);
2120 GlobalUnlock16(HICON_16(hIcon));
2125 /**********************************************************************
2126 * CreateIconIndirect (USER32.@)
2128 HICON WINAPI CreateIconIndirect(PICONINFO iconinfo)
2133 int xor_objsize = 0, sizeXor = 0, sizeAnd, planes, bpp;
2135 TRACE("color %p, mask %p, hotspot %ux%u, fIcon %d\n",
2136 iconinfo->hbmColor, iconinfo->hbmMask,
2137 iconinfo->xHotspot, iconinfo->yHotspot, iconinfo->fIcon);
2139 if (!iconinfo->hbmMask) return 0;
2141 planes = GetDeviceCaps( screen_dc, PLANES );
2142 bpp = GetDeviceCaps( screen_dc, BITSPIXEL );
2144 if (iconinfo->hbmColor)
2146 xor_objsize = GetObjectW( iconinfo->hbmColor, sizeof(bmpXor), &bmpXor );
2147 TRACE("color: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
2148 bmpXor.dsBm.bmWidth, bmpXor.dsBm.bmHeight, bmpXor.dsBm.bmWidthBytes,
2149 bmpXor.dsBm.bmPlanes, bmpXor.dsBm.bmBitsPixel);
2150 /* we can use either depth 1 or screen depth for xor bitmap */
2151 if (bmpXor.dsBm.bmPlanes == 1 && bmpXor.dsBm.bmBitsPixel == 1) planes = bpp = 1;
2152 sizeXor = bmpXor.dsBm.bmHeight * planes * get_bitmap_width_bytes( bmpXor.dsBm.bmWidth, bpp );
2154 GetObjectW( iconinfo->hbmMask, sizeof(bmpAnd), &bmpAnd );
2155 TRACE("mask: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
2156 bmpAnd.bmWidth, bmpAnd.bmHeight, bmpAnd.bmWidthBytes,
2157 bmpAnd.bmPlanes, bmpAnd.bmBitsPixel);
2159 sizeAnd = bmpAnd.bmHeight * get_bitmap_width_bytes(bmpAnd.bmWidth, 1);
2161 hObj = GlobalAlloc16( GMEM_MOVEABLE,
2162 sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
2165 CURSORICONINFO *info;
2167 info = GlobalLock16( hObj );
2169 /* If we are creating an icon, the hotspot is unused */
2170 if (iconinfo->fIcon)
2172 info->ptHotSpot.x = ICON_HOTSPOT;
2173 info->ptHotSpot.y = ICON_HOTSPOT;
2177 info->ptHotSpot.x = iconinfo->xHotspot;
2178 info->ptHotSpot.y = iconinfo->yHotspot;
2181 if (iconinfo->hbmColor)
2183 info->nWidth = bmpXor.dsBm.bmWidth;
2184 info->nHeight = bmpXor.dsBm.bmHeight;
2185 info->nWidthBytes = bmpXor.dsBm.bmWidthBytes;
2186 info->bPlanes = planes;
2187 info->bBitsPerPixel = bpp;
2191 info->nWidth = bmpAnd.bmWidth;
2192 info->nHeight = bmpAnd.bmHeight / 2;
2193 info->nWidthBytes = get_bitmap_width_bytes(bmpAnd.bmWidth, 1);
2195 info->bBitsPerPixel = 1;
2198 /* Transfer the bitmap bits to the CURSORICONINFO structure */
2200 /* Some apps pass a color bitmap as a mask, convert it to b/w */
2201 if (bmpAnd.bmBitsPixel == 1)
2203 GetBitmapBits( iconinfo->hbmMask, sizeAnd, info + 1 );
2208 HBITMAP hbmp_old, hbmp_mem_old, hbmp_mono;
2211 hdc_mem = CreateCompatibleDC( hdc );
2213 hbmp_mono = CreateBitmap( bmpAnd.bmWidth, bmpAnd.bmHeight, 1, 1, NULL );
2215 hbmp_old = SelectObject( hdc, iconinfo->hbmMask );
2216 hbmp_mem_old = SelectObject( hdc_mem, hbmp_mono );
2218 BitBlt( hdc_mem, 0, 0, bmpAnd.bmWidth, bmpAnd.bmHeight, hdc, 0, 0, SRCCOPY );
2220 SelectObject( hdc, hbmp_old );
2221 SelectObject( hdc_mem, hbmp_mem_old );
2223 DeleteDC( hdc_mem );
2224 ReleaseDC( 0, hdc );
2226 GetBitmapBits( hbmp_mono, sizeAnd, info + 1 );
2227 DeleteObject( hbmp_mono );
2230 if (iconinfo->hbmColor)
2232 char *dst_bits = (char*)(info + 1) + sizeAnd;
2234 if (bmpXor.dsBm.bmPlanes == planes && bmpXor.dsBm.bmBitsPixel == bpp)
2235 GetBitmapBits( iconinfo->hbmColor, sizeXor, dst_bits );
2239 int dib_width = get_dib_width_bytes( info->nWidth, info->bBitsPerPixel );
2240 int bitmap_width = get_bitmap_width_bytes( info->nWidth, info->bBitsPerPixel );
2242 bminfo.bmiHeader.biSize = sizeof(bminfo);
2243 bminfo.bmiHeader.biWidth = info->nWidth;
2244 bminfo.bmiHeader.biHeight = info->nHeight;
2245 bminfo.bmiHeader.biPlanes = info->bPlanes;
2246 bminfo.bmiHeader.biBitCount = info->bBitsPerPixel;
2247 bminfo.bmiHeader.biCompression = BI_RGB;
2248 bminfo.bmiHeader.biSizeImage = info->nHeight * dib_width;
2249 bminfo.bmiHeader.biXPelsPerMeter = 0;
2250 bminfo.bmiHeader.biYPelsPerMeter = 0;
2251 bminfo.bmiHeader.biClrUsed = 0;
2252 bminfo.bmiHeader.biClrImportant = 0;
2254 /* swap lines for dib sections */
2255 if (xor_objsize == sizeof(DIBSECTION))
2256 bminfo.bmiHeader.biHeight = -bminfo.bmiHeader.biHeight;
2258 if (dib_width != bitmap_width) /* need to fixup alignment */
2260 char *src_bits = HeapAlloc( GetProcessHeap(), 0, bminfo.bmiHeader.biSizeImage );
2262 if (src_bits && GetDIBits( screen_dc, iconinfo->hbmColor, 0, info->nHeight,
2263 src_bits, &bminfo, DIB_RGB_COLORS ))
2266 for (y = 0; y < info->nHeight; y++)
2267 memcpy( dst_bits + y * bitmap_width, src_bits + y * dib_width, bitmap_width );
2269 HeapFree( GetProcessHeap(), 0, src_bits );
2272 GetDIBits( screen_dc, iconinfo->hbmColor, 0, info->nHeight,
2273 dst_bits, &bminfo, DIB_RGB_COLORS );
2276 GlobalUnlock16( hObj );
2278 return HICON_32(hObj);
2281 /******************************************************************************
2282 * DrawIconEx (USER32.@) Draws an icon or cursor on device context
2285 * Why is this using SM_CXICON instead of SM_CXCURSOR?
2288 * hdc [I] Handle to device context
2289 * x0 [I] X coordinate of upper left corner
2290 * y0 [I] Y coordinate of upper left corner
2291 * hIcon [I] Handle to icon to draw
2292 * cxWidth [I] Width of icon
2293 * cyWidth [I] Height of icon
2294 * istep [I] Index of frame in animated cursor
2295 * hbr [I] Handle to background brush
2296 * flags [I] Icon-drawing flags
2302 BOOL WINAPI DrawIconEx( HDC hdc, INT x0, INT y0, HICON hIcon,
2303 INT cxWidth, INT cyWidth, UINT istep,
2304 HBRUSH hbr, UINT flags )
2306 CURSORICONINFO *ptr;
2307 HDC hDC_off = 0, hMemDC;
2308 BOOL result = FALSE, DoOffscreen;
2309 HBITMAP hB_off = 0, hOld = 0;
2310 unsigned char *xorBitmapBits;
2311 unsigned int xorLength;
2312 BOOL has_alpha = FALSE;
2314 TRACE_(icon)("(hdc=%p,pos=%d.%d,hicon=%p,extend=%d.%d,istep=%d,br=%p,flags=0x%08x)\n",
2315 hdc,x0,y0,hIcon,cxWidth,cyWidth,istep,hbr,flags );
2317 if (!(ptr = GlobalLock16(HICON_16(hIcon)))) return FALSE;
2318 if (!(hMemDC = CreateCompatibleDC( hdc ))) return FALSE;
2321 FIXME_(icon)("Ignoring istep=%d\n", istep);
2322 if (flags & DI_NOMIRROR)
2323 FIXME_(icon)("Ignoring flag DI_NOMIRROR\n");
2325 xorLength = ptr->nHeight * get_bitmap_width_bytes(
2326 ptr->nWidth, ptr->bBitsPerPixel);
2327 xorBitmapBits = (unsigned char *)(ptr + 1) + ptr->nHeight *
2328 get_bitmap_width_bytes(ptr->nWidth, 1);
2330 if (flags & DI_IMAGE)
2331 has_alpha = bitmap_has_alpha_channel(
2332 ptr->bBitsPerPixel, xorBitmapBits, xorLength);
2334 /* Calculate the size of the destination image. */
2337 if (flags & DI_DEFAULTSIZE)
2338 cxWidth = GetSystemMetrics (SM_CXICON);
2340 cxWidth = ptr->nWidth;
2344 if (flags & DI_DEFAULTSIZE)
2345 cyWidth = GetSystemMetrics (SM_CYICON);
2347 cyWidth = ptr->nHeight;
2350 DoOffscreen = (GetObjectType( hbr ) == OBJ_BRUSH);
2360 hDC_off = CreateCompatibleDC(hdc);
2361 hB_off = CreateCompatibleBitmap(hdc, cxWidth, cyWidth);
2362 if (hDC_off && hB_off) {
2363 hOld = SelectObject(hDC_off, hB_off);
2364 FillRect(hDC_off, &r, hbr);
2368 if (hMemDC && (!DoOffscreen || (hDC_off && hB_off)))
2371 HBITMAP hXorBits = NULL, hAndBits = NULL;
2372 COLORREF oldFg, oldBg;
2375 nStretchMode = SetStretchBltMode (hdc, STRETCH_DELETESCANS);
2377 oldFg = SetTextColor( hdc, RGB(0,0,0) );
2378 oldBg = SetBkColor( hdc, RGB(255,255,255) );
2380 if (((flags & DI_MASK) && !(flags & DI_IMAGE)) ||
2381 ((flags & DI_MASK) && !has_alpha))
2383 hAndBits = CreateBitmap ( ptr->nWidth, ptr->nHeight, 1, 1, ptr + 1 );
2386 hBitTemp = SelectObject( hMemDC, hAndBits );
2388 StretchBlt (hDC_off, 0, 0, cxWidth, cyWidth,
2389 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCAND);
2391 StretchBlt (hdc, x0, y0, cxWidth, cyWidth,
2392 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCAND);
2393 SelectObject( hMemDC, hBitTemp );
2397 if (flags & DI_IMAGE)
2399 BITMAPINFOHEADER bmih;
2400 unsigned char *dibBits;
2402 memset(&bmih, 0, sizeof(BITMAPINFOHEADER));
2403 bmih.biSize = sizeof(BITMAPINFOHEADER);
2404 bmih.biWidth = ptr->nWidth;
2405 bmih.biHeight = -ptr->nHeight;
2406 bmih.biPlanes = ptr->bPlanes;
2407 bmih.biBitCount = ptr->bBitsPerPixel;
2408 bmih.biCompression = BI_RGB;
2410 hXorBits = CreateDIBSection(hdc, (BITMAPINFO*)&bmih, DIB_RGB_COLORS,
2411 (void*)&dibBits, NULL, 0);
2413 if (hXorBits && dibBits)
2417 BLENDFUNCTION pixelblend = { AC_SRC_OVER, 0, 255, AC_SRC_ALPHA };
2419 /* Do the alpha blending render */
2420 premultiply_alpha_channel(dibBits, xorBitmapBits, xorLength);
2421 hBitTemp = SelectObject( hMemDC, hXorBits );
2424 GdiAlphaBlend(hDC_off, 0, 0, cxWidth, cyWidth, hMemDC,
2425 0, 0, ptr->nWidth, ptr->nHeight, pixelblend);
2427 GdiAlphaBlend(hdc, x0, y0, cxWidth, cyWidth, hMemDC,
2428 0, 0, ptr->nWidth, ptr->nHeight, pixelblend);
2430 SelectObject( hMemDC, hBitTemp );
2434 memcpy(dibBits, xorBitmapBits, xorLength);
2435 hBitTemp = SelectObject( hMemDC, hXorBits );
2437 StretchBlt (hDC_off, 0, 0, cxWidth, cyWidth,
2438 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCPAINT);
2440 StretchBlt (hdc, x0, y0, cxWidth, cyWidth,
2441 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCPAINT);
2442 SelectObject( hMemDC, hBitTemp );
2445 DeleteObject( hXorBits );
2451 SetTextColor( hdc, oldFg );
2452 SetBkColor( hdc, oldBg );
2454 if (hAndBits) DeleteObject( hAndBits );
2455 SetStretchBltMode (hdc, nStretchMode);
2457 BitBlt(hdc, x0, y0, cxWidth, cyWidth, hDC_off, 0, 0, SRCCOPY);
2458 SelectObject(hDC_off, hOld);
2461 if (hMemDC) DeleteDC( hMemDC );
2462 if (hDC_off) DeleteDC(hDC_off);
2463 if (hB_off) DeleteObject(hB_off);
2464 GlobalUnlock16(HICON_16(hIcon));
2468 /***********************************************************************
2469 * DIB_FixColorsToLoadflags
2471 * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
2474 static void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT loadflags, BYTE pix)
2477 COLORREF c_W, c_S, c_F, c_L, c_C;
2486 if (((bitmap_type = DIB_GetBitmapInfo((BITMAPINFOHEADER*) bmi, &width, &height, &bpp, &compr)) == -1))
2488 WARN_(resource)("Invalid bitmap\n");
2492 if (bpp > 8) return;
2494 if (bitmap_type == 0) /* BITMAPCOREHEADER */
2502 colors = bmi->bmiHeader.biClrUsed;
2503 if (colors > 256) colors = 256;
2504 if (!colors && (bpp <= 8)) colors = 1 << bpp;
2507 c_W = GetSysColor(COLOR_WINDOW);
2508 c_S = GetSysColor(COLOR_3DSHADOW);
2509 c_F = GetSysColor(COLOR_3DFACE);
2510 c_L = GetSysColor(COLOR_3DLIGHT);
2512 if (loadflags & LR_LOADTRANSPARENT) {
2514 case 1: pix = pix >> 7; break;
2515 case 4: pix = pix >> 4; break;
2518 WARN_(resource)("(%d): Unsupported depth\n", bpp);
2521 if (pix >= colors) {
2522 WARN_(resource)("pixel has color index greater than biClrUsed!\n");
2525 if (loadflags & LR_LOADMAP3DCOLORS) c_W = c_F;
2526 ptr = (RGBQUAD*)((char*)bmi->bmiColors+pix*incr);
2527 ptr->rgbBlue = GetBValue(c_W);
2528 ptr->rgbGreen = GetGValue(c_W);
2529 ptr->rgbRed = GetRValue(c_W);
2531 if (loadflags & LR_LOADMAP3DCOLORS)
2532 for (i=0; i<colors; i++) {
2533 ptr = (RGBQUAD*)((char*)bmi->bmiColors+i*incr);
2534 c_C = RGB(ptr->rgbRed, ptr->rgbGreen, ptr->rgbBlue);
2535 if (c_C == RGB(128, 128, 128)) {
2536 ptr->rgbRed = GetRValue(c_S);
2537 ptr->rgbGreen = GetGValue(c_S);
2538 ptr->rgbBlue = GetBValue(c_S);
2539 } else if (c_C == RGB(192, 192, 192)) {
2540 ptr->rgbRed = GetRValue(c_F);
2541 ptr->rgbGreen = GetGValue(c_F);
2542 ptr->rgbBlue = GetBValue(c_F);
2543 } else if (c_C == RGB(223, 223, 223)) {
2544 ptr->rgbRed = GetRValue(c_L);
2545 ptr->rgbGreen = GetGValue(c_L);
2546 ptr->rgbBlue = GetBValue(c_L);
2552 /**********************************************************************
2555 static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
2556 INT desiredx, INT desiredy, UINT loadflags )
2558 HBITMAP hbitmap = 0, orig_bm;
2562 BITMAPINFO *info, *fix_info = NULL, *scaled_info = NULL;
2566 LONG width, height, new_width, new_height;
2570 HDC screen_mem_dc = NULL;
2572 if (!(loadflags & LR_LOADFROMFILE))
2576 /* OEM bitmap: try to load the resource from user32.dll */
2577 instance = user32_module;
2580 if (!(hRsrc = FindResourceW( instance, name, (LPWSTR)RT_BITMAP ))) return 0;
2581 if (!(handle = LoadResource( instance, hRsrc ))) return 0;
2583 if ((info = LockResource( handle )) == NULL) return 0;
2587 BITMAPFILEHEADER * bmfh;
2589 if (!(ptr = map_fileW( name, NULL ))) return 0;
2590 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
2591 bmfh = (BITMAPFILEHEADER *)ptr;
2592 if (!( bmfh->bfType == 0x4d42 /* 'BM' */ &&
2593 bmfh->bfReserved1 == 0 &&
2594 bmfh->bfReserved2 == 0))
2596 WARN("Invalid/unsupported bitmap format!\n");
2597 UnmapViewOfFile( ptr );
2602 size = bitmap_info_size(info, DIB_RGB_COLORS);
2603 fix_info = HeapAlloc(GetProcessHeap(), 0, size);
2604 scaled_info = HeapAlloc(GetProcessHeap(), 0, size);
2606 if (!fix_info || !scaled_info) goto end;
2607 memcpy(fix_info, info, size);
2609 pix = *((LPBYTE)info + size);
2610 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
2612 memcpy(scaled_info, fix_info, size);
2613 bm_type = DIB_GetBitmapInfo( &fix_info->bmiHeader, &width, &height,
2614 &bpp_dummy, &compr_dummy);
2616 new_width = desiredx;
2621 new_height = height > 0 ? desiredy : -desiredy;
2623 new_height = height;
2627 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)&scaled_info->bmiHeader;
2628 core->bcWidth = new_width;
2629 core->bcHeight = new_height;
2633 scaled_info->bmiHeader.biWidth = new_width;
2634 scaled_info->bmiHeader.biHeight = new_height;
2637 if (new_height < 0) new_height = -new_height;
2639 if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
2640 if (!(screen_mem_dc = CreateCompatibleDC( screen_dc ))) goto end;
2642 bits = (char *)info + size;
2644 if (loadflags & LR_CREATEDIBSECTION)
2646 scaled_info->bmiHeader.biCompression = 0; /* DIBSection can't be compressed */
2647 hbitmap = CreateDIBSection(screen_dc, scaled_info, DIB_RGB_COLORS, NULL, 0, 0);
2651 if (is_dib_monochrome(fix_info))
2652 hbitmap = CreateBitmap(new_width, new_height, 1, 1, NULL);
2654 hbitmap = CreateCompatibleBitmap(screen_dc, new_width, new_height);
2657 orig_bm = SelectObject(screen_mem_dc, hbitmap);
2658 StretchDIBits(screen_mem_dc, 0, 0, new_width, new_height, 0, 0, width, height, bits, fix_info, DIB_RGB_COLORS, SRCCOPY);
2659 SelectObject(screen_mem_dc, orig_bm);
2662 if (screen_mem_dc) DeleteDC(screen_mem_dc);
2663 HeapFree(GetProcessHeap(), 0, scaled_info);
2664 HeapFree(GetProcessHeap(), 0, fix_info);
2665 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
2670 /**********************************************************************
2671 * LoadImageA (USER32.@)
2675 HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
2676 INT desiredx, INT desiredy, UINT loadflags)
2682 return LoadImageW(hinst, (LPCWSTR)name, type, desiredx, desiredy, loadflags);
2685 DWORD len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
2686 u_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2687 MultiByteToWideChar( CP_ACP, 0, name, -1, u_name, len );
2689 __EXCEPT_PAGE_FAULT {
2690 SetLastError( ERROR_INVALID_PARAMETER );
2694 res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
2695 HeapFree(GetProcessHeap(), 0, u_name);
2700 /******************************************************************************
2701 * LoadImageW (USER32.@) Loads an icon, cursor, or bitmap
2704 * hinst [I] Handle of instance that contains image
2705 * name [I] Name of image
2706 * type [I] Type of image
2707 * desiredx [I] Desired width
2708 * desiredy [I] Desired height
2709 * loadflags [I] Load flags
2712 * Success: Handle to newly loaded image
2715 * FIXME: Implementation lacks some features, see LR_ defines in winuser.h
2717 HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
2718 INT desiredx, INT desiredy, UINT loadflags )
2720 TRACE_(resource)("(%p,%s,%d,%d,%d,0x%08x)\n",
2721 hinst,debugstr_w(name),type,desiredx,desiredy,loadflags);
2723 if (loadflags & LR_DEFAULTSIZE) {
2724 if (type == IMAGE_ICON) {
2725 if (!desiredx) desiredx = GetSystemMetrics(SM_CXICON);
2726 if (!desiredy) desiredy = GetSystemMetrics(SM_CYICON);
2727 } else if (type == IMAGE_CURSOR) {
2728 if (!desiredx) desiredx = GetSystemMetrics(SM_CXCURSOR);
2729 if (!desiredy) desiredy = GetSystemMetrics(SM_CYCURSOR);
2732 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
2735 return BITMAP_Load( hinst, name, desiredx, desiredy, loadflags );
2738 if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
2741 UINT palEnts = GetSystemPaletteEntries(screen_dc, 0, 0, NULL);
2742 if (palEnts == 0) palEnts = 256;
2743 return CURSORICON_Load(hinst, name, desiredx, desiredy,
2744 palEnts, FALSE, loadflags);
2749 return CURSORICON_Load(hinst, name, desiredx, desiredy,
2750 1, TRUE, loadflags);
2755 /******************************************************************************
2756 * CopyImage (USER32.@) Creates new image and copies attributes to it
2759 * hnd [I] Handle to image to copy
2760 * type [I] Type of image to copy
2761 * desiredx [I] Desired width of new image
2762 * desiredy [I] Desired height of new image
2763 * flags [I] Copy flags
2766 * Success: Handle to newly created image
2770 * Only Windows NT 4.0 supports the LR_COPYRETURNORG flag for bitmaps,
2771 * all other versions (95/2000/XP have been tested) ignore it.
2774 * If LR_CREATEDIBSECTION is absent, the copy will be monochrome for
2775 * a monochrome source bitmap or if LR_MONOCHROME is present, otherwise
2776 * the copy will have the same depth as the screen.
2777 * The content of the image will only be copied if the bit depth of the
2778 * original image is compatible with the bit depth of the screen, or
2779 * if the source is a DIB section.
2780 * The LR_MONOCHROME flag is ignored if LR_CREATEDIBSECTION is present.
2782 HANDLE WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
2783 INT desiredy, UINT flags )
2785 TRACE("hnd=%p, type=%u, desiredx=%d, desiredy=%d, flags=%x\n",
2786 hnd, type, desiredx, desiredy, flags);
2797 objSize = GetObjectW( hnd, sizeof(ds), &ds );
2798 if (!objSize) return 0;
2799 if ((desiredx < 0) || (desiredy < 0)) return 0;
2801 if (flags & LR_COPYFROMRESOURCE)
2803 FIXME("The flag LR_COPYFROMRESOURCE is not implemented for bitmaps\n");
2806 if (desiredx == 0) desiredx = ds.dsBm.bmWidth;
2807 if (desiredy == 0) desiredy = ds.dsBm.bmHeight;
2809 /* Allocate memory for a BITMAPINFOHEADER structure and a
2810 color table. The maximum number of colors in a color table
2811 is 256 which corresponds to a bitmap with depth 8.
2812 Bitmaps with higher depths don't have color tables. */
2813 bi = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(BITMAPINFOHEADER) + 256 * sizeof(RGBQUAD));
2816 bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
2817 bi->bmiHeader.biPlanes = ds.dsBm.bmPlanes;
2818 bi->bmiHeader.biBitCount = ds.dsBm.bmBitsPixel;
2819 bi->bmiHeader.biCompression = BI_RGB;
2821 if (flags & LR_CREATEDIBSECTION)
2823 /* Create a DIB section. LR_MONOCHROME is ignored */
2825 HDC dc = CreateCompatibleDC(NULL);
2827 if (objSize == sizeof(DIBSECTION))
2829 /* The source bitmap is a DIB.
2830 Get its attributes to create an exact copy */
2831 memcpy(bi, &ds.dsBmih, sizeof(BITMAPINFOHEADER));
2834 /* Get the color table or the color masks */
2835 GetDIBits(dc, hnd, 0, ds.dsBm.bmHeight, NULL, bi, DIB_RGB_COLORS);
2837 bi->bmiHeader.biWidth = desiredx;
2838 bi->bmiHeader.biHeight = desiredy;
2839 bi->bmiHeader.biSizeImage = 0;
2841 res = CreateDIBSection(dc, bi, DIB_RGB_COLORS, &bits, NULL, 0);
2846 /* Create a device-dependent bitmap */
2848 BOOL monochrome = (flags & LR_MONOCHROME);
2850 if (objSize == sizeof(DIBSECTION))
2852 /* The source bitmap is a DIB section.
2853 Get its attributes */
2854 HDC dc = CreateCompatibleDC(NULL);
2855 bi->bmiHeader.biSize = sizeof(bi->bmiHeader);
2856 bi->bmiHeader.biBitCount = ds.dsBm.bmBitsPixel;
2857 GetDIBits(dc, hnd, 0, ds.dsBm.bmHeight, NULL, bi, DIB_RGB_COLORS);
2860 if (!monochrome && ds.dsBm.bmBitsPixel == 1)
2862 /* Look if the colors of the DIB are black and white */
2865 (bi->bmiColors[0].rgbRed == 0xff
2866 && bi->bmiColors[0].rgbGreen == 0xff
2867 && bi->bmiColors[0].rgbBlue == 0xff
2868 && bi->bmiColors[0].rgbReserved == 0
2869 && bi->bmiColors[1].rgbRed == 0
2870 && bi->bmiColors[1].rgbGreen == 0
2871 && bi->bmiColors[1].rgbBlue == 0
2872 && bi->bmiColors[1].rgbReserved == 0)
2874 (bi->bmiColors[0].rgbRed == 0
2875 && bi->bmiColors[0].rgbGreen == 0
2876 && bi->bmiColors[0].rgbBlue == 0
2877 && bi->bmiColors[0].rgbReserved == 0
2878 && bi->bmiColors[1].rgbRed == 0xff
2879 && bi->bmiColors[1].rgbGreen == 0xff
2880 && bi->bmiColors[1].rgbBlue == 0xff
2881 && bi->bmiColors[1].rgbReserved == 0);
2884 else if (!monochrome)
2886 monochrome = ds.dsBm.bmBitsPixel == 1;
2891 res = CreateBitmap(desiredx, desiredy, 1, 1, NULL);
2895 HDC screenDC = GetDC(NULL);
2896 res = CreateCompatibleBitmap(screenDC, desiredx, desiredy);
2897 ReleaseDC(NULL, screenDC);
2903 /* Only copy the bitmap if it's a DIB section or if it's
2904 compatible to the screen */
2907 if (objSize == sizeof(DIBSECTION))
2909 copyContents = TRUE;
2913 HDC screenDC = GetDC(NULL);
2914 int screen_depth = GetDeviceCaps(screenDC, BITSPIXEL);
2915 ReleaseDC(NULL, screenDC);
2917 copyContents = (ds.dsBm.bmBitsPixel == 1 || ds.dsBm.bmBitsPixel == screen_depth);
2922 /* The source bitmap may already be selected in a device context,
2923 use GetDIBits/StretchDIBits and not StretchBlt */
2928 dc = CreateCompatibleDC(NULL);
2930 bi->bmiHeader.biWidth = ds.dsBm.bmWidth;
2931 bi->bmiHeader.biHeight = ds.dsBm.bmHeight;
2932 bi->bmiHeader.biSizeImage = 0;
2933 bi->bmiHeader.biClrUsed = 0;
2934 bi->bmiHeader.biClrImportant = 0;
2936 /* Fill in biSizeImage */
2937 GetDIBits(dc, hnd, 0, ds.dsBm.bmHeight, NULL, bi, DIB_RGB_COLORS);
2938 bits = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, bi->bmiHeader.biSizeImage);
2944 /* Get the image bits of the source bitmap */
2945 GetDIBits(dc, hnd, 0, ds.dsBm.bmHeight, bits, bi, DIB_RGB_COLORS);
2947 /* Copy it to the destination bitmap */
2948 oldBmp = SelectObject(dc, res);
2949 StretchDIBits(dc, 0, 0, desiredx, desiredy,
2950 0, 0, ds.dsBm.bmWidth, ds.dsBm.bmHeight,
2951 bits, bi, DIB_RGB_COLORS, SRCCOPY);
2952 SelectObject(dc, oldBmp);
2954 HeapFree(GetProcessHeap(), 0, bits);
2960 if (flags & LR_COPYDELETEORG)
2965 HeapFree(GetProcessHeap(), 0, bi);
2969 return CURSORICON_ExtCopy(hnd,type, desiredx, desiredy, flags);
2971 /* Should call CURSORICON_ExtCopy but more testing
2972 * needs to be done before we change this
2974 if (flags) FIXME("Flags are ignored\n");
2975 return CopyCursor(hnd);
2981 /******************************************************************************
2982 * LoadBitmapW (USER32.@) Loads bitmap from the executable file
2985 * Success: Handle to specified bitmap
2988 HBITMAP WINAPI LoadBitmapW(
2989 HINSTANCE instance, /* [in] Handle to application instance */
2990 LPCWSTR name) /* [in] Address of bitmap resource name */
2992 return LoadImageW( instance, name, IMAGE_BITMAP, 0, 0, 0 );
2995 /**********************************************************************
2996 * LoadBitmapA (USER32.@)
3000 HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
3002 return LoadImageA( instance, name, IMAGE_BITMAP, 0, 0, 0 );