2 * Cursor and icon support
4 * Copyright 1995 Alexandre Julliard
5 * 1996 Martin Von Loewis
7 * 1998 Turchanov Sergey
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 * http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwui/html/msdn_icons.asp
29 * Cursors and icons are stored in a global heap block, with the
32 * CURSORICONINFO info;
36 * The bits structures are in the format of a device-dependent bitmap.
38 * This layout is very sub-optimal, as the bitmap bits are stored in
39 * the X client instead of in the server like other bitmaps; however,
40 * some programs (notably Paint Brush) expect to be able to manipulate
41 * the bits directly :-(
43 * FIXME: what are we going to do with animation and color (bpp > 1) cursors ?!
47 #include "wine/port.h"
60 #include "wine/winbase16.h"
61 #include "wine/winuser16.h"
62 #include "wine/exception.h"
63 #include "wine/debug.h"
64 #include "user_private.h"
66 WINE_DEFAULT_DEBUG_CHANNEL(cursor);
67 WINE_DECLARE_DEBUG_CHANNEL(icon);
68 WINE_DECLARE_DEBUG_CHANNEL(resource);
81 } CURSORICONFILEDIRENTRY;
88 CURSORICONFILEDIRENTRY idEntries[1];
93 #define CID_RESOURCE 0x0001
94 #define CID_WIN32 0x0004
95 #define CID_NONSHARED 0x0008
97 static RECT CURSOR_ClipRect; /* Cursor clipping rect */
101 static const WCHAR DISPLAYW[] = {'D','I','S','P','L','A','Y',0};
103 /**********************************************************************
104 * ICONCACHE for cursors/icons loaded with LR_SHARED.
106 * FIXME: This should not be allocated on the system heap, but on a
107 * subsystem-global heap (i.e. one for all Win16 processes,
108 * and one for each Win32 process).
110 typedef struct tagICONCACHE
112 struct tagICONCACHE *next;
123 static ICONCACHE *IconAnchor = NULL;
125 static CRITICAL_SECTION IconCrst;
126 static CRITICAL_SECTION_DEBUG critsect_debug =
129 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
130 0, 0, { (DWORD_PTR)(__FILE__ ": IconCrst") }
132 static CRITICAL_SECTION IconCrst = { &critsect_debug, -1, 0, 0, 0, 0 };
134 static WORD ICON_HOTSPOT = 0x4242;
137 /***********************************************************************
140 * Helper function to map a file to memory:
142 * [RETURN] ptr - pointer to mapped file
143 * [RETURN] filesize - pointer size of file to be stored if not NULL
145 static void *map_fileW( LPCWSTR name, LPDWORD filesize )
147 HANDLE hFile, hMapping;
150 hFile = CreateFileW( name, GENERIC_READ, FILE_SHARE_READ, NULL,
151 OPEN_EXISTING, FILE_FLAG_RANDOM_ACCESS, 0 );
152 if (hFile != INVALID_HANDLE_VALUE)
154 hMapping = CreateFileMappingW( hFile, NULL, PAGE_READONLY, 0, 0, NULL );
157 ptr = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 );
158 CloseHandle( hMapping );
160 *filesize = GetFileSize( hFile, NULL );
162 CloseHandle( hFile );
168 /***********************************************************************
169 * get_bitmap_width_bytes
171 * Return number of bytes taken by a scanline of 16-bit aligned Windows DDB
174 static int get_bitmap_width_bytes( int width, int bpp )
179 return 2 * ((width+15) / 16);
181 return 2 * ((width+3) / 4);
186 return width + (width & 1);
193 WARN("Unknown depth %d, please report.\n", bpp );
199 /***********************************************************************
200 * get_dib_width_bytes
202 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
204 static int get_dib_width_bytes( int width, int depth )
210 case 1: words = (width + 31) / 32; break;
211 case 4: words = (width + 7) / 8; break;
212 case 8: words = (width + 3) / 4; break;
214 case 16: words = (width + 1) / 2; break;
215 case 24: words = (width * 3 + 3)/4; break;
217 WARN("(%d): Unsupported depth\n", depth );
226 /***********************************************************************
229 * Return the size of the bitmap info structure including color table.
231 static int bitmap_info_size( const BITMAPINFO * info, WORD coloruse )
235 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
237 const BITMAPCOREHEADER *core = (const BITMAPCOREHEADER *)info;
238 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
239 return sizeof(BITMAPCOREHEADER) + colors *
240 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
242 else /* assume BITMAPINFOHEADER */
244 colors = info->bmiHeader.biClrUsed;
245 if (colors > 256) /* buffer overflow otherwise */
247 if (!colors && (info->bmiHeader.biBitCount <= 8))
248 colors = 1 << info->bmiHeader.biBitCount;
249 return sizeof(BITMAPINFOHEADER) + colors *
250 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
255 /***********************************************************************
258 * Returns whether a DIB can be converted to a monochrome DDB.
260 * A DIB can be converted if its color table contains only black and
261 * white. Black must be the first color in the color table.
263 * Note : If the first color in the color table is white followed by
264 * black, we can't convert it to a monochrome DDB with
265 * SetDIBits, because black and white would be inverted.
267 static BOOL is_dib_monochrome( const BITMAPINFO* info )
269 if (info->bmiHeader.biBitCount != 1) return FALSE;
271 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
273 RGBTRIPLE *rgb = ((BITMAPCOREINFO *) info)->bmciColors;
275 /* Check if the first color is black */
276 if ((rgb->rgbtRed == 0) && (rgb->rgbtGreen == 0) && (rgb->rgbtBlue == 0))
280 /* Check if the second color is white */
281 return ((rgb->rgbtRed == 0xff) && (rgb->rgbtGreen == 0xff)
282 && (rgb->rgbtBlue == 0xff));
286 else /* assume BITMAPINFOHEADER */
288 RGBQUAD *rgb = info->bmiColors;
290 /* Check if the first color is black */
291 if ((rgb->rgbRed == 0) && (rgb->rgbGreen == 0) &&
292 (rgb->rgbBlue == 0) && (rgb->rgbReserved == 0))
296 /* Check if the second color is white */
297 return ((rgb->rgbRed == 0xff) && (rgb->rgbGreen == 0xff)
298 && (rgb->rgbBlue == 0xff) && (rgb->rgbReserved == 0));
304 /***********************************************************************
307 * Get the info from a bitmap header.
308 * Return 1 for INFOHEADER, 0 for COREHEADER,
309 * 4 for V4HEADER, 5 for V5HEADER, -1 for error.
311 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
312 LONG *height, WORD *bpp, DWORD *compr )
314 if (header->biSize == sizeof(BITMAPINFOHEADER))
316 *width = header->biWidth;
317 *height = header->biHeight;
318 *bpp = header->biBitCount;
319 *compr = header->biCompression;
322 if (header->biSize == sizeof(BITMAPCOREHEADER))
324 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)header;
325 *width = core->bcWidth;
326 *height = core->bcHeight;
327 *bpp = core->bcBitCount;
331 if (header->biSize == sizeof(BITMAPV4HEADER))
333 BITMAPV4HEADER *v4hdr = (BITMAPV4HEADER *)header;
334 *width = v4hdr->bV4Width;
335 *height = v4hdr->bV4Height;
336 *bpp = v4hdr->bV4BitCount;
337 *compr = v4hdr->bV4V4Compression;
340 if (header->biSize == sizeof(BITMAPV5HEADER))
342 BITMAPV5HEADER *v5hdr = (BITMAPV5HEADER *)header;
343 *width = v5hdr->bV5Width;
344 *height = v5hdr->bV5Height;
345 *bpp = v5hdr->bV5BitCount;
346 *compr = v5hdr->bV5Compression;
349 ERR("(%ld): unknown/wrong size for header\n", header->biSize );
353 /**********************************************************************
354 * CURSORICON_FindSharedIcon
356 static HICON CURSORICON_FindSharedIcon( HMODULE hModule, HRSRC hRsrc )
361 EnterCriticalSection( &IconCrst );
363 for ( ptr = IconAnchor; ptr; ptr = ptr->next )
364 if ( ptr->hModule == hModule && ptr->hRsrc == hRsrc )
371 LeaveCriticalSection( &IconCrst );
376 /*************************************************************************
377 * CURSORICON_FindCache
379 * Given a handle, find the corresponding cache element
382 * Handle [I] handle to an Image
385 * Success: The cache entry
389 static ICONCACHE* CURSORICON_FindCache(HICON hIcon)
392 ICONCACHE *pRet=NULL;
393 BOOL IsFound = FALSE;
396 EnterCriticalSection( &IconCrst );
398 for (count = 0, ptr = IconAnchor; ptr != NULL && !IsFound; ptr = ptr->next, count++ )
400 if ( hIcon == ptr->hIcon )
407 LeaveCriticalSection( &IconCrst );
412 /**********************************************************************
413 * CURSORICON_AddSharedIcon
415 static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HICON hIcon )
417 ICONCACHE *ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(ICONCACHE) );
420 ptr->hModule = hModule;
423 ptr->hGroupRsrc = hGroupRsrc;
426 EnterCriticalSection( &IconCrst );
427 ptr->next = IconAnchor;
429 LeaveCriticalSection( &IconCrst );
432 /**********************************************************************
433 * CURSORICON_DelSharedIcon
435 static INT CURSORICON_DelSharedIcon( HICON hIcon )
440 EnterCriticalSection( &IconCrst );
442 for ( ptr = IconAnchor; ptr; ptr = ptr->next )
443 if ( ptr->hIcon == hIcon )
445 if ( ptr->count > 0 ) ptr->count--;
450 LeaveCriticalSection( &IconCrst );
455 /**********************************************************************
456 * CURSORICON_FreeModuleIcons
458 void CURSORICON_FreeModuleIcons( HMODULE16 hMod16 )
460 ICONCACHE **ptr = &IconAnchor;
461 HMODULE hModule = HMODULE_32(GetExePtr( hMod16 ));
463 EnterCriticalSection( &IconCrst );
467 if ( (*ptr)->hModule == hModule )
469 ICONCACHE *freePtr = *ptr;
470 *ptr = freePtr->next;
472 GlobalFree16(HICON_16(freePtr->hIcon));
473 HeapFree( GetProcessHeap(), 0, freePtr );
479 LeaveCriticalSection( &IconCrst );
483 * The following macro functions account for the irregularities of
484 * accessing cursor and icon resources in files and resource entries.
486 typedef BOOL (*fnGetCIEntry)( LPVOID dir, int n,
487 int *width, int *height, int *bits );
489 /**********************************************************************
490 * CURSORICON_FindBestIcon
492 * Find the icon closest to the requested size and number of colors.
494 static int CURSORICON_FindBestIcon( LPVOID dir, fnGetCIEntry get_entry,
495 int width, int height, int colors )
497 int i, cx, cy, bits, bestEntry = -1;
498 UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
499 UINT iTempXDiff, iTempYDiff, iTempColorDiff;
502 iTotalDiff = 0xFFFFFFFF;
503 iColorDiff = 0xFFFFFFFF;
504 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
506 iTempXDiff = abs(width - cx);
507 iTempYDiff = abs(height - cy);
509 if(iTotalDiff > (iTempXDiff + iTempYDiff))
513 iTotalDiff = iXDiff + iYDiff;
517 /* Find Best Colors for Best Fit */
518 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
520 if(abs(width - cx) == iXDiff && abs(height - cy) == iYDiff)
522 iTempColorDiff = abs(colors - (1<<bits));
523 if(iColorDiff > iTempColorDiff)
526 iColorDiff = iTempColorDiff;
534 static BOOL CURSORICON_GetResIconEntry( LPVOID dir, int n,
535 int *width, int *height, int *bits )
537 CURSORICONDIR *resdir = dir;
540 if ( resdir->idCount <= n )
542 icon = &resdir->idEntries[n].ResInfo.icon;
543 *width = icon->bWidth;
544 *height = icon->bWidth;
545 *bits = resdir->idEntries[n].wBitCount;
549 /**********************************************************************
550 * CURSORICON_FindBestCursor
552 * Find the cursor closest to the requested size.
553 * FIXME: parameter 'color' ignored and entries with more than 1 bpp
556 static int CURSORICON_FindBestCursor( LPVOID dir, fnGetCIEntry get_entry,
557 int width, int height, int color )
559 int i, maxwidth, maxheight, cx, cy, bits, bestEntry = -1;
561 /* Double height to account for AND and XOR masks */
565 /* First find the largest one smaller than or equal to the requested size*/
567 maxwidth = maxheight = 0;
568 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
570 if ((cx <= width) && (cy <= height) &&
571 (cx > maxwidth) && (cy > maxheight) &&
579 if (bestEntry != -1) return bestEntry;
581 /* Now find the smallest one larger than the requested size */
583 maxwidth = maxheight = 255;
584 for ( i = 0; get_entry( dir, i, &cx, &cy, &bits ); i++ )
586 if (((cx < maxwidth) && (cy < maxheight) && (bits == 1)) ||
598 static BOOL CURSORICON_GetResCursorEntry( LPVOID dir, int n,
599 int *width, int *height, int *bits )
601 CURSORICONDIR *resdir = dir;
604 if ( resdir->idCount <= n )
606 cursor = &resdir->idEntries[n].ResInfo.cursor;
607 *width = cursor->wWidth;
608 *height = cursor->wHeight;
609 *bits = resdir->idEntries[n].wBitCount;
613 static CURSORICONDIRENTRY *CURSORICON_FindBestIconRes( CURSORICONDIR * dir,
614 int width, int height, int colors )
618 n = CURSORICON_FindBestIcon( dir, CURSORICON_GetResIconEntry,
619 width, height, colors );
622 return &dir->idEntries[n];
625 static CURSORICONDIRENTRY *CURSORICON_FindBestCursorRes( CURSORICONDIR *dir,
626 int width, int height, int color )
628 int n = CURSORICON_FindBestCursor( dir, CURSORICON_GetResCursorEntry,
629 width, height, color );
632 return &dir->idEntries[n];
635 static BOOL CURSORICON_GetFileEntry( LPVOID dir, int n,
636 int *width, int *height, int *bits )
638 CURSORICONFILEDIR *filedir = dir;
639 CURSORICONFILEDIRENTRY *entry;
641 if ( filedir->idCount <= n )
643 entry = &filedir->idEntries[n];
644 *width = entry->bWidth;
645 *height = entry->bHeight;
646 *bits = entry->bColorCount;
650 static CURSORICONFILEDIRENTRY *CURSORICON_FindBestCursorFile( CURSORICONFILEDIR *dir,
651 int width, int height, int color )
653 int n = CURSORICON_FindBestCursor( dir, CURSORICON_GetFileEntry,
654 width, height, color );
657 return &dir->idEntries[n];
660 static CURSORICONFILEDIRENTRY *CURSORICON_FindBestIconFile( CURSORICONFILEDIR *dir,
661 int width, int height, int color )
663 int n = CURSORICON_FindBestIcon( dir, CURSORICON_GetFileEntry,
664 width, height, color );
667 return &dir->idEntries[n];
670 /**********************************************************************
671 * CreateIconFromResourceEx (USER32.@)
673 * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
674 * with cbSize parameter as well.
676 HICON WINAPI CreateIconFromResourceEx( LPBYTE bits, UINT cbSize,
677 BOOL bIcon, DWORD dwVersion,
678 INT width, INT height,
683 int sizeAnd, sizeXor;
684 HBITMAP hAndBits = 0, hXorBits = 0; /* error condition for later */
685 BITMAP bmpXor, bmpAnd;
691 hotspot.x = ICON_HOTSPOT;
692 hotspot.y = ICON_HOTSPOT;
694 TRACE_(cursor)("%p (%u bytes), ver %08x, %ix%i %s %s\n",
695 bits, cbSize, (unsigned)dwVersion, width, height,
696 bIcon ? "icon" : "cursor", (cFlag & LR_MONOCHROME) ? "mono" : "" );
697 if (dwVersion == 0x00020000)
699 FIXME_(cursor)("\t2.xx resources are not supported\n");
704 bmi = (BITMAPINFO *)bits;
705 else /* get the hotspot */
707 POINT16 *pt = (POINT16 *)bits;
709 bmi = (BITMAPINFO *)(pt + 1);
711 size = bitmap_info_size( bmi, DIB_RGB_COLORS );
713 if (!width) width = bmi->bmiHeader.biWidth;
714 if (!height) height = bmi->bmiHeader.biHeight/2;
715 DoStretch = (bmi->bmiHeader.biHeight/2 != height) ||
716 (bmi->bmiHeader.biWidth != width);
718 /* Check bitmap header */
720 if ( (bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
721 (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) ||
722 bmi->bmiHeader.biCompression != BI_RGB) )
724 WARN_(cursor)("\tinvalid resource bitmap header.\n");
728 if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
733 /* Make sure we have room for the monochrome bitmap later on.
734 * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
735 * up to and including the biBitCount. In-memory icon resource
736 * format is as follows:
738 * BITMAPINFOHEADER icHeader // DIB header
739 * RGBQUAD icColors[] // Color table
740 * BYTE icXOR[] // DIB bits for XOR mask
741 * BYTE icAND[] // DIB bits for AND mask
744 if ((pInfo = HeapAlloc( GetProcessHeap(), 0,
745 max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))))
747 memcpy( pInfo, bmi, size );
748 pInfo->bmiHeader.biHeight /= 2;
750 /* Create the XOR bitmap */
755 hXorBits = CreateCompatibleBitmap(screen_dc, width, height);
759 hXorBits = CreateBitmap(width, height, 1, 1, NULL);
766 if (!hdcMem) hdcMem = CreateCompatibleDC(screen_dc);
768 hOld = SelectObject(hdcMem, hXorBits);
769 res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
770 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2,
771 (char*)bmi + size, pInfo, DIB_RGB_COLORS, SRCCOPY);
772 SelectObject(hdcMem, hOld);
774 if (!res) { DeleteObject(hXorBits); hXorBits = 0; }
777 if (is_dib_monochrome(bmi)) {
778 hXorBits = CreateBitmap(width, height, 1, 1, NULL);
779 SetDIBits(screen_dc, hXorBits, 0, height,
780 (char*)bmi + size, pInfo, DIB_RGB_COLORS);
783 hXorBits = CreateDIBitmap(screen_dc, &pInfo->bmiHeader,
784 CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS);
789 char* xbits = (char *)bmi + size +
790 get_dib_width_bytes( bmi->bmiHeader.biWidth,
791 bmi->bmiHeader.biBitCount ) * abs( bmi->bmiHeader.biHeight ) / 2;
793 pInfo->bmiHeader.biBitCount = 1;
794 if (pInfo->bmiHeader.biSize != sizeof(BITMAPCOREHEADER))
796 RGBQUAD *rgb = pInfo->bmiColors;
798 pInfo->bmiHeader.biClrUsed = pInfo->bmiHeader.biClrImportant = 2;
799 rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
800 rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
801 rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
805 RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)pInfo) + 1);
807 rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
808 rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
811 /* Create the AND bitmap */
814 if ((hAndBits = CreateBitmap(width, height, 1, 1, NULL))) {
818 if (!hdcMem) hdcMem = CreateCompatibleDC(screen_dc);
820 hOld = SelectObject(hdcMem, hAndBits);
821 res = StretchDIBits(hdcMem, 0, 0, width, height, 0, 0,
822 pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight,
823 xbits, pInfo, DIB_RGB_COLORS, SRCCOPY);
824 SelectObject(hdcMem, hOld);
826 if (!res) { DeleteObject(hAndBits); hAndBits = 0; }
829 hAndBits = CreateBitmap(width, height, 1, 1, NULL);
831 if (hAndBits) SetDIBits(screen_dc, hAndBits, 0, height,
832 xbits, pInfo, DIB_RGB_COLORS);
835 if( !hAndBits ) DeleteObject( hXorBits );
837 HeapFree( GetProcessHeap(), 0, pInfo );
841 if( !hXorBits || !hAndBits )
843 WARN_(cursor)("\tunable to create an icon bitmap.\n");
847 /* Now create the CURSORICONINFO structure */
848 GetObjectA( hXorBits, sizeof(bmpXor), &bmpXor );
849 GetObjectA( hAndBits, sizeof(bmpAnd), &bmpAnd );
850 sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
851 sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
853 hObj = GlobalAlloc16( GMEM_MOVEABLE,
854 sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
857 CURSORICONINFO *info;
859 info = (CURSORICONINFO *)GlobalLock16( hObj );
860 info->ptHotSpot.x = hotspot.x;
861 info->ptHotSpot.y = hotspot.y;
862 info->nWidth = bmpXor.bmWidth;
863 info->nHeight = bmpXor.bmHeight;
864 info->nWidthBytes = bmpXor.bmWidthBytes;
865 info->bPlanes = bmpXor.bmPlanes;
866 info->bBitsPerPixel = bmpXor.bmBitsPixel;
868 /* Transfer the bitmap bits to the CURSORICONINFO structure */
870 GetBitmapBits( hAndBits, sizeAnd, (char *)(info + 1) );
871 GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd );
872 GlobalUnlock16( hObj );
875 DeleteObject( hAndBits );
876 DeleteObject( hXorBits );
877 return HICON_32((HICON16)hObj);
881 /**********************************************************************
882 * CreateIconFromResource (USER32.@)
884 HICON WINAPI CreateIconFromResource( LPBYTE bits, UINT cbSize,
885 BOOL bIcon, DWORD dwVersion)
887 return CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, 0,0,0);
891 static HICON CURSORICON_LoadFromFile( LPCWSTR filename,
892 INT width, INT height, INT colors,
893 BOOL fCursor, UINT loadflags)
895 CURSORICONFILEDIRENTRY *entry;
896 CURSORICONFILEDIR *dir;
901 TRACE("loading %s\n", debugstr_w( filename ));
903 bits = map_fileW( filename, &filesize );
907 dir = (CURSORICONFILEDIR*) bits;
908 if ( filesize < sizeof(*dir) )
911 if ( filesize < (sizeof(*dir) + sizeof(dir->idEntries[0])*(dir->idCount-1)) )
915 entry = CURSORICON_FindBestCursorFile( dir, width, height, 1 );
917 entry = CURSORICON_FindBestIconFile( dir, width, height, colors );
922 /* check that we don't run off the end of the file */
923 if ( entry->dwDIBOffset > filesize )
925 if ( entry->dwDIBOffset + entry->dwDIBSize > filesize )
928 hIcon = CreateIconFromResourceEx( &bits[entry->dwDIBOffset], entry->dwDIBSize,
929 !fCursor, 0x00030000, width, height, loadflags );
931 TRACE("loaded %s -> %p\n", debugstr_w( filename ), hIcon );
932 UnmapViewOfFile( bits );
936 /**********************************************************************
939 * Load a cursor or icon from resource or file.
941 static HICON CURSORICON_Load(HINSTANCE hInstance, LPCWSTR name,
942 INT width, INT height, INT colors,
943 BOOL fCursor, UINT loadflags)
947 HRSRC hRsrc, hGroupRsrc;
949 CURSORICONDIRENTRY *dirEntry;
954 if ( loadflags & LR_LOADFROMFILE ) /* Load from file */
955 return CURSORICON_LoadFromFile( name, width, height, colors, fCursor, loadflags );
957 if (!hInstance) hInstance = user32_module; /* Load OEM cursor/icon */
959 /* Normalize hInstance (must be uniquely represented for icon cache) */
961 if (!HIWORD( hInstance ))
962 hInstance = HINSTANCE_32(GetExePtr( HINSTANCE_16(hInstance) ));
964 /* Get directory resource ID */
966 if (!(hRsrc = FindResourceW( hInstance, name,
967 (LPWSTR)(fCursor ? RT_GROUP_CURSOR : RT_GROUP_ICON) )))
971 /* Find the best entry in the directory */
973 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
974 if (!(dir = (CURSORICONDIR*)LockResource( handle ))) return 0;
976 dirEntry = CURSORICON_FindBestCursorRes( dir, width, height, 1);
978 dirEntry = CURSORICON_FindBestIconRes( dir, width, height, colors );
979 if (!dirEntry) return 0;
980 wResId = dirEntry->wResId;
981 dwBytesInRes = dirEntry->dwBytesInRes;
982 FreeResource( handle );
984 /* Load the resource */
986 if (!(hRsrc = FindResourceW(hInstance,MAKEINTRESOURCEW(wResId),
987 (LPWSTR)(fCursor ? RT_CURSOR : RT_ICON) ))) return 0;
989 /* If shared icon, check whether it was already loaded */
990 if ( (loadflags & LR_SHARED)
991 && (hIcon = CURSORICON_FindSharedIcon( hInstance, hRsrc ) ) != 0 )
994 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
995 bits = (LPBYTE)LockResource( handle );
996 hIcon = CreateIconFromResourceEx( bits, dwBytesInRes,
997 !fCursor, 0x00030000, width, height, loadflags);
998 FreeResource( handle );
1000 /* If shared icon, add to icon cache */
1002 if ( hIcon && (loadflags & LR_SHARED) )
1003 CURSORICON_AddSharedIcon( hInstance, hRsrc, hGroupRsrc, hIcon );
1008 /***********************************************************************
1011 * Make a copy of a cursor or icon.
1013 static HICON CURSORICON_Copy( HINSTANCE16 hInst16, HICON hIcon )
1015 char *ptrOld, *ptrNew;
1017 HICON16 hOld = HICON_16(hIcon);
1020 if (!(ptrOld = (char *)GlobalLock16( hOld ))) return 0;
1021 if (hInst16 && !(hInst16 = GetExePtr( hInst16 ))) return 0;
1022 size = GlobalSize16( hOld );
1023 hNew = GlobalAlloc16( GMEM_MOVEABLE, size );
1024 FarSetOwner16( hNew, hInst16 );
1025 ptrNew = (char *)GlobalLock16( hNew );
1026 memcpy( ptrNew, ptrOld, size );
1027 GlobalUnlock16( hOld );
1028 GlobalUnlock16( hNew );
1029 return HICON_32(hNew);
1032 /*************************************************************************
1033 * CURSORICON_ExtCopy
1035 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified
1038 * Handle [I] handle to an Image
1039 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON)
1040 * iDesiredCX [I] The Desired width of the Image
1041 * iDesiredCY [I] The desired height of the Image
1042 * nFlags [I] The flags from CopyImage
1045 * Success: The new handle of the Image
1048 * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented.
1049 * LR_MONOCHROME should be implemented by CreateIconFromResourceEx.
1050 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache.
1055 static HICON CURSORICON_ExtCopy(HICON hIcon, UINT nType,
1056 INT iDesiredCX, INT iDesiredCY,
1061 TRACE_(icon)("hIcon %p, nType %u, iDesiredCX %i, iDesiredCY %i, nFlags %u\n",
1062 hIcon, nType, iDesiredCX, iDesiredCY, nFlags);
1069 /* Best Fit or Monochrome */
1070 if( (nFlags & LR_COPYFROMRESOURCE
1071 && (iDesiredCX > 0 || iDesiredCY > 0))
1072 || nFlags & LR_MONOCHROME)
1074 ICONCACHE* pIconCache = CURSORICON_FindCache(hIcon);
1076 /* Not Found in Cache, then do a straight copy
1078 if(pIconCache == NULL)
1080 hNew = CURSORICON_Copy(0, hIcon);
1081 if(nFlags & LR_COPYFROMRESOURCE)
1083 TRACE_(icon)("LR_COPYFROMRESOURCE: Failed to load from cache\n");
1088 int iTargetCY = iDesiredCY, iTargetCX = iDesiredCX;
1094 CURSORICONDIR *pDir;
1095 CURSORICONDIRENTRY *pDirEntry;
1096 BOOL bIsIcon = (nType == IMAGE_ICON);
1098 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
1100 if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE))
1101 || (iDesiredCX == 0 && iDesiredCY == 0))
1103 iDesiredCY = GetSystemMetrics(bIsIcon ?
1104 SM_CYICON : SM_CYCURSOR);
1105 iDesiredCX = GetSystemMetrics(bIsIcon ?
1106 SM_CXICON : SM_CXCURSOR);
1109 /* Retrieve the CURSORICONDIRENTRY
1111 if (!(hMem = LoadResource( pIconCache->hModule ,
1112 pIconCache->hGroupRsrc)))
1116 if (!(pDir = (CURSORICONDIR*)LockResource( hMem )))
1125 pDirEntry = CURSORICON_FindBestIconRes(
1126 pDir, iDesiredCX, iDesiredCY, 256 );
1130 pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursorRes(
1131 pDir, iDesiredCX, iDesiredCY, 1);
1134 wResId = pDirEntry->wResId;
1135 dwBytesInRes = pDirEntry->dwBytesInRes;
1138 TRACE_(icon)("ResID %u, BytesInRes %lu, Width %d, Height %d DX %d, DY %d\n",
1139 wResId, dwBytesInRes, pDirEntry->ResInfo.icon.bWidth,
1140 pDirEntry->ResInfo.icon.bHeight, iDesiredCX, iDesiredCY);
1144 if (!(hRsrc = FindResourceW(pIconCache->hModule ,
1145 MAKEINTRESOURCEW(wResId), (LPWSTR)(bIsIcon ? RT_ICON : RT_CURSOR))))
1149 if (!(hMem = LoadResource( pIconCache->hModule , hRsrc )))
1154 pBits = (LPBYTE)LockResource( hMem );
1156 if(nFlags & LR_DEFAULTSIZE)
1158 iTargetCY = GetSystemMetrics(SM_CYICON);
1159 iTargetCX = GetSystemMetrics(SM_CXICON);
1162 /* Create a New Icon with the proper dimension
1164 hNew = CreateIconFromResourceEx( pBits, dwBytesInRes,
1165 bIsIcon, 0x00030000, iTargetCX, iTargetCY, nFlags);
1169 else hNew = CURSORICON_Copy(0, hIcon);
1174 /***********************************************************************
1175 * CreateCursor (USER32.@)
1177 HCURSOR WINAPI CreateCursor( HINSTANCE hInstance,
1178 INT xHotSpot, INT yHotSpot,
1179 INT nWidth, INT nHeight,
1180 LPCVOID lpANDbits, LPCVOID lpXORbits )
1182 CURSORICONINFO info;
1184 TRACE_(cursor)("%dx%d spot=%d,%d xor=%p and=%p\n",
1185 nWidth, nHeight, xHotSpot, yHotSpot, lpXORbits, lpANDbits);
1187 info.ptHotSpot.x = xHotSpot;
1188 info.ptHotSpot.y = yHotSpot;
1189 info.nWidth = nWidth;
1190 info.nHeight = nHeight;
1191 info.nWidthBytes = 0;
1193 info.bBitsPerPixel = 1;
1195 return HICON_32(CreateCursorIconIndirect16(0, &info, lpANDbits, lpXORbits));
1199 /***********************************************************************
1200 * CreateIcon (USER.407)
1202 HICON16 WINAPI CreateIcon16( HINSTANCE16 hInstance, INT16 nWidth,
1203 INT16 nHeight, BYTE bPlanes, BYTE bBitsPixel,
1204 LPCVOID lpANDbits, LPCVOID lpXORbits )
1206 CURSORICONINFO info;
1208 TRACE_(icon)("%dx%dx%d, xor=%p, and=%p\n",
1209 nWidth, nHeight, bPlanes * bBitsPixel, lpXORbits, lpANDbits);
1211 info.ptHotSpot.x = ICON_HOTSPOT;
1212 info.ptHotSpot.y = ICON_HOTSPOT;
1213 info.nWidth = nWidth;
1214 info.nHeight = nHeight;
1215 info.nWidthBytes = 0;
1216 info.bPlanes = bPlanes;
1217 info.bBitsPerPixel = bBitsPixel;
1219 return CreateCursorIconIndirect16( hInstance, &info, lpANDbits, lpXORbits );
1223 /***********************************************************************
1224 * CreateIcon (USER32.@)
1226 * Creates an icon based on the specified bitmaps. The bitmaps must be
1227 * provided in a device dependent format and will be resized to
1228 * (SM_CXICON,SM_CYICON) and depth converted to match the screen's color
1229 * depth. The provided bitmaps must be top-down bitmaps.
1230 * Although Windows does not support 15bpp(*) this API must support it
1231 * for Winelib applications.
1233 * (*) Windows does not support 15bpp but it supports the 555 RGB 16bpp
1238 * - The provided bitmaps are not resized!
1239 * - The documentation says the lpXORbits bitmap must be in a device
1240 * dependent format. But we must still resize it and perform depth
1241 * conversions if necessary.
1242 * - I'm a bit unsure about the how the 'device dependent format' thing works.
1243 * I did some tests on windows and found that if you provide a 16bpp bitmap
1244 * in lpXORbits, then its format but be 565 RGB if the screen's bit depth
1245 * is 16bpp but it must be 555 RGB if the screen's bit depth is anything
1246 * else. I don't know if this is part of the GDI specs or if this is a
1247 * quirk of the graphics card driver.
1248 * - You may think that we check whether the bit depths match or not
1249 * as an optimization. But the truth is that the conversion using
1250 * CreateDIBitmap does not work for some bit depth (e.g. 8bpp) and I have
1252 * - I'm pretty sure that all the things we do in CreateIcon should
1253 * also be done in CreateIconIndirect...
1255 HICON WINAPI CreateIcon(
1256 HINSTANCE hInstance, /* [in] the application's hInstance */
1257 INT nWidth, /* [in] the width of the provided bitmaps */
1258 INT nHeight, /* [in] the height of the provided bitmaps */
1259 BYTE bPlanes, /* [in] the number of planes in the provided bitmaps */
1260 BYTE bBitsPixel, /* [in] the number of bits per pixel of the lpXORbits bitmap */
1261 LPCVOID lpANDbits, /* [in] a monochrome bitmap representing the icon's mask */
1262 LPCVOID lpXORbits) /* [in] the icon's 'color' bitmap */
1267 TRACE_(icon)("%dx%dx%d, xor=%p, and=%p\n",
1268 nWidth, nHeight, bPlanes * bBitsPixel, lpXORbits, lpANDbits);
1274 if (GetDeviceCaps(hdc,BITSPIXEL)==bBitsPixel) {
1275 CURSORICONINFO info;
1277 info.ptHotSpot.x = ICON_HOTSPOT;
1278 info.ptHotSpot.y = ICON_HOTSPOT;
1279 info.nWidth = nWidth;
1280 info.nHeight = nHeight;
1281 info.nWidthBytes = 0;
1282 info.bPlanes = bPlanes;
1283 info.bBitsPerPixel = bBitsPixel;
1285 hIcon=HICON_32(CreateCursorIconIndirect16(0, &info, lpANDbits, lpXORbits));
1291 iinfo.xHotspot=ICON_HOTSPOT;
1292 iinfo.yHotspot=ICON_HOTSPOT;
1293 iinfo.hbmMask=CreateBitmap(nWidth,nHeight,1,1,lpANDbits);
1295 bmi.bmiHeader.biSize=sizeof(bmi.bmiHeader);
1296 bmi.bmiHeader.biWidth=nWidth;
1297 bmi.bmiHeader.biHeight=-nHeight;
1298 bmi.bmiHeader.biPlanes=bPlanes;
1299 bmi.bmiHeader.biBitCount=bBitsPixel;
1300 bmi.bmiHeader.biCompression=BI_RGB;
1301 bmi.bmiHeader.biSizeImage=0;
1302 bmi.bmiHeader.biXPelsPerMeter=0;
1303 bmi.bmiHeader.biYPelsPerMeter=0;
1304 bmi.bmiHeader.biClrUsed=0;
1305 bmi.bmiHeader.biClrImportant=0;
1307 iinfo.hbmColor = CreateDIBitmap( hdc, &bmi.bmiHeader,
1308 CBM_INIT, lpXORbits,
1309 &bmi, DIB_RGB_COLORS );
1311 hIcon=CreateIconIndirect(&iinfo);
1312 DeleteObject(iinfo.hbmMask);
1313 DeleteObject(iinfo.hbmColor);
1320 /***********************************************************************
1321 * CreateCursorIconIndirect (USER.408)
1323 HGLOBAL16 WINAPI CreateCursorIconIndirect16( HINSTANCE16 hInstance,
1324 CURSORICONINFO *info,
1330 int sizeAnd, sizeXor;
1332 hInstance = GetExePtr( hInstance ); /* Make it a module handle */
1333 if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
1334 info->nWidthBytes = get_bitmap_width_bytes(info->nWidth,info->bBitsPerPixel);
1335 sizeXor = info->nHeight * info->nWidthBytes;
1336 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
1337 if (!(handle = GlobalAlloc16( GMEM_MOVEABLE,
1338 sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
1340 FarSetOwner16( handle, hInstance );
1341 ptr = (char *)GlobalLock16( handle );
1342 memcpy( ptr, info, sizeof(*info) );
1343 memcpy( ptr + sizeof(CURSORICONINFO), lpANDbits, sizeAnd );
1344 memcpy( ptr + sizeof(CURSORICONINFO) + sizeAnd, lpXORbits, sizeXor );
1345 GlobalUnlock16( handle );
1350 /***********************************************************************
1351 * CopyIcon (USER.368)
1353 HICON16 WINAPI CopyIcon16( HINSTANCE16 hInstance, HICON16 hIcon )
1355 TRACE_(icon)("%04x %04x\n", hInstance, hIcon );
1356 return HICON_16(CURSORICON_Copy(hInstance, HICON_32(hIcon)));
1360 /***********************************************************************
1361 * CopyIcon (USER32.@)
1363 HICON WINAPI CopyIcon( HICON hIcon )
1365 TRACE_(icon)("%p\n", hIcon );
1366 return CURSORICON_Copy( 0, hIcon );
1370 /***********************************************************************
1371 * CopyCursor (USER.369)
1373 HCURSOR16 WINAPI CopyCursor16( HINSTANCE16 hInstance, HCURSOR16 hCursor )
1375 TRACE_(cursor)("%04x %04x\n", hInstance, hCursor );
1376 return HICON_16(CURSORICON_Copy(hInstance, HCURSOR_32(hCursor)));
1379 /**********************************************************************
1380 * DestroyIcon32 (USER.610)
1382 * This routine is actually exported from Win95 USER under the name
1383 * DestroyIcon32 ... The behaviour implemented here should mimic
1384 * the Win95 one exactly, especially the return values, which
1385 * depend on the setting of various flags.
1387 WORD WINAPI DestroyIcon32( HGLOBAL16 handle, UINT16 flags )
1391 TRACE_(icon)("(%04x, %04x)\n", handle, flags );
1393 /* Check whether destroying active cursor */
1395 if ( get_user_thread_info()->cursor == HICON_32(handle) )
1397 WARN_(cursor)("Destroying active cursor!\n" );
1401 /* Try shared cursor/icon first */
1403 if ( !(flags & CID_NONSHARED) )
1405 INT count = CURSORICON_DelSharedIcon(HICON_32(handle));
1408 return (flags & CID_WIN32)? TRUE : (count == 0);
1410 /* FIXME: OEM cursors/icons should be recognized */
1413 /* Now assume non-shared cursor/icon */
1415 retv = GlobalFree16( handle );
1416 return (flags & CID_RESOURCE)? retv : TRUE;
1419 /***********************************************************************
1420 * DestroyIcon (USER32.@)
1422 BOOL WINAPI DestroyIcon( HICON hIcon )
1424 return DestroyIcon32(HICON_16(hIcon), CID_WIN32);
1428 /***********************************************************************
1429 * DestroyCursor (USER32.@)
1431 BOOL WINAPI DestroyCursor( HCURSOR hCursor )
1433 return DestroyIcon32(HCURSOR_16(hCursor), CID_WIN32);
1437 /***********************************************************************
1438 * DrawIcon (USER32.@)
1440 BOOL WINAPI DrawIcon( HDC hdc, INT x, INT y, HICON hIcon )
1442 CURSORICONINFO *ptr;
1444 HBITMAP hXorBits, hAndBits;
1445 COLORREF oldFg, oldBg;
1447 if (!(ptr = (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon)))) return FALSE;
1448 if (!(hMemDC = CreateCompatibleDC( hdc ))) return FALSE;
1449 hAndBits = CreateBitmap( ptr->nWidth, ptr->nHeight, 1, 1,
1451 hXorBits = CreateBitmap( ptr->nWidth, ptr->nHeight, ptr->bPlanes,
1452 ptr->bBitsPerPixel, (char *)(ptr + 1)
1453 + ptr->nHeight * get_bitmap_width_bytes(ptr->nWidth,1) );
1454 oldFg = SetTextColor( hdc, RGB(0,0,0) );
1455 oldBg = SetBkColor( hdc, RGB(255,255,255) );
1457 if (hXorBits && hAndBits)
1459 HBITMAP hBitTemp = SelectObject( hMemDC, hAndBits );
1460 BitBlt( hdc, x, y, ptr->nWidth, ptr->nHeight, hMemDC, 0, 0, SRCAND );
1461 SelectObject( hMemDC, hXorBits );
1462 BitBlt(hdc, x, y, ptr->nWidth, ptr->nHeight, hMemDC, 0, 0,SRCINVERT);
1463 SelectObject( hMemDC, hBitTemp );
1466 if (hXorBits) DeleteObject( hXorBits );
1467 if (hAndBits) DeleteObject( hAndBits );
1468 GlobalUnlock16(HICON_16(hIcon));
1469 SetTextColor( hdc, oldFg );
1470 SetBkColor( hdc, oldBg );
1474 /***********************************************************************
1475 * DumpIcon (USER.459)
1477 DWORD WINAPI DumpIcon16( SEGPTR pInfo, WORD *lpLen,
1478 SEGPTR *lpXorBits, SEGPTR *lpAndBits )
1480 CURSORICONINFO *info = MapSL( pInfo );
1481 int sizeAnd, sizeXor;
1483 if (!info) return 0;
1484 sizeXor = info->nHeight * info->nWidthBytes;
1485 sizeAnd = info->nHeight * get_bitmap_width_bytes( info->nWidth, 1 );
1486 if (lpAndBits) *lpAndBits = pInfo + sizeof(CURSORICONINFO);
1487 if (lpXorBits) *lpXorBits = pInfo + sizeof(CURSORICONINFO) + sizeAnd;
1488 if (lpLen) *lpLen = sizeof(CURSORICONINFO) + sizeAnd + sizeXor;
1489 return MAKELONG( sizeXor, sizeXor );
1493 /***********************************************************************
1494 * SetCursor (USER32.@)
1496 * A handle to the previous cursor shape.
1498 HCURSOR WINAPI SetCursor( HCURSOR hCursor /* [in] Handle of cursor to show */ )
1500 struct user_thread_info *thread_info = get_user_thread_info();
1503 if (hCursor == thread_info->cursor) return hCursor; /* No change */
1504 TRACE_(cursor)("%p\n", hCursor );
1505 hOldCursor = thread_info->cursor;
1506 thread_info->cursor = hCursor;
1507 /* Change the cursor shape only if it is visible */
1508 if (thread_info->cursor_count >= 0)
1510 USER_Driver->pSetCursor( (CURSORICONINFO*)GlobalLock16(HCURSOR_16(hCursor)) );
1511 GlobalUnlock16(HCURSOR_16(hCursor));
1516 /***********************************************************************
1517 * ShowCursor (USER32.@)
1519 INT WINAPI ShowCursor( BOOL bShow )
1521 struct user_thread_info *thread_info = get_user_thread_info();
1523 TRACE_(cursor)("%d, count=%d\n", bShow, thread_info->cursor_count );
1527 if (++thread_info->cursor_count == 0) /* Show it */
1529 USER_Driver->pSetCursor((CURSORICONINFO*)GlobalLock16(HCURSOR_16(thread_info->cursor)));
1530 GlobalUnlock16(HCURSOR_16(thread_info->cursor));
1535 if (--thread_info->cursor_count == -1) /* Hide it */
1536 USER_Driver->pSetCursor( NULL );
1538 return thread_info->cursor_count;
1541 /***********************************************************************
1542 * GetCursor (USER32.@)
1544 HCURSOR WINAPI GetCursor(void)
1546 return get_user_thread_info()->cursor;
1550 /***********************************************************************
1551 * ClipCursor (USER32.@)
1553 BOOL WINAPI ClipCursor( const RECT *rect )
1555 if (!rect) SetRectEmpty( &CURSOR_ClipRect );
1556 else CopyRect( &CURSOR_ClipRect, rect );
1561 /***********************************************************************
1562 * GetClipCursor (USER32.@)
1564 BOOL WINAPI GetClipCursor( RECT *rect )
1568 CopyRect( rect, &CURSOR_ClipRect );
1575 /***********************************************************************
1576 * SetSystemCursor (USER32.@)
1578 BOOL WINAPI SetSystemCursor(HCURSOR hcur, DWORD id)
1580 FIXME("(%p,%08lx),stub!\n", hcur, id);
1585 /**********************************************************************
1586 * LookupIconIdFromDirectoryEx (USER.364)
1588 * FIXME: exact parameter sizes
1590 INT16 WINAPI LookupIconIdFromDirectoryEx16( LPBYTE dir, BOOL16 bIcon,
1591 INT16 width, INT16 height, UINT16 cFlag )
1593 return LookupIconIdFromDirectoryEx( dir, bIcon, width, height, cFlag );
1596 /**********************************************************************
1597 * LookupIconIdFromDirectoryEx (USER32.@)
1599 INT WINAPI LookupIconIdFromDirectoryEx( LPBYTE xdir, BOOL bIcon,
1600 INT width, INT height, UINT cFlag )
1602 CURSORICONDIR *dir = (CURSORICONDIR*)xdir;
1604 if( dir && !dir->idReserved && (dir->idType & 3) )
1606 CURSORICONDIRENTRY* entry;
1611 palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
1614 colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts;
1619 entry = CURSORICON_FindBestIconRes( dir, width, height, colors );
1621 entry = CURSORICON_FindBestCursorRes( dir, width, height, 1);
1623 if( entry ) retVal = entry->wResId;
1625 else WARN_(cursor)("invalid resource directory\n");
1629 /**********************************************************************
1630 * LookupIconIdFromDirectory (USER.?)
1632 INT16 WINAPI LookupIconIdFromDirectory16( LPBYTE dir, BOOL16 bIcon )
1634 return LookupIconIdFromDirectoryEx16( dir, bIcon,
1635 bIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
1636 bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME );
1639 /**********************************************************************
1640 * LookupIconIdFromDirectory (USER32.@)
1642 INT WINAPI LookupIconIdFromDirectory( LPBYTE dir, BOOL bIcon )
1644 return LookupIconIdFromDirectoryEx( dir, bIcon,
1645 bIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
1646 bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME );
1649 /**********************************************************************
1650 * GetIconID (USER.455)
1652 WORD WINAPI GetIconID16( HGLOBAL16 hResource, DWORD resType )
1654 LPBYTE lpDir = (LPBYTE)GlobalLock16(hResource);
1656 TRACE_(cursor)("hRes=%04x, entries=%i\n",
1657 hResource, lpDir ? ((CURSORICONDIR*)lpDir)->idCount : 0);
1662 return (WORD)LookupIconIdFromDirectoryEx16( lpDir, FALSE,
1663 GetSystemMetrics(SM_CXCURSOR), GetSystemMetrics(SM_CYCURSOR), LR_MONOCHROME );
1665 return (WORD)LookupIconIdFromDirectoryEx16( lpDir, TRUE,
1666 GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON), 0 );
1668 WARN_(cursor)("invalid res type %ld\n", resType );
1673 /**********************************************************************
1674 * LoadCursorIconHandler (USER.336)
1676 * Supposed to load resources of Windows 2.x applications.
1678 HGLOBAL16 WINAPI LoadCursorIconHandler16( HGLOBAL16 hResource, HMODULE16 hModule, HRSRC16 hRsrc )
1680 FIXME_(cursor)("(%04x,%04x,%04x): old 2.x resources are not supported!\n",
1681 hResource, hModule, hRsrc);
1682 return (HGLOBAL16)0;
1685 /**********************************************************************
1686 * LoadIconHandler (USER.456)
1688 HICON16 WINAPI LoadIconHandler16( HGLOBAL16 hResource, BOOL16 bNew )
1690 LPBYTE bits = (LPBYTE)LockResource16( hResource );
1692 TRACE_(cursor)("hRes=%04x\n",hResource);
1694 return HICON_16(CreateIconFromResourceEx( bits, 0, TRUE,
1695 bNew ? 0x00030000 : 0x00020000, 0, 0, LR_DEFAULTCOLOR));
1698 /***********************************************************************
1699 * LoadCursorW (USER32.@)
1701 HCURSOR WINAPI LoadCursorW(HINSTANCE hInstance, LPCWSTR name)
1703 return LoadImageW( hInstance, name, IMAGE_CURSOR, 0, 0,
1704 LR_SHARED | LR_DEFAULTSIZE );
1707 /***********************************************************************
1708 * LoadCursorA (USER32.@)
1710 HCURSOR WINAPI LoadCursorA(HINSTANCE hInstance, LPCSTR name)
1712 return LoadImageA( hInstance, name, IMAGE_CURSOR, 0, 0,
1713 LR_SHARED | LR_DEFAULTSIZE );
1716 /***********************************************************************
1717 * LoadCursorFromFileW (USER32.@)
1719 HCURSOR WINAPI LoadCursorFromFileW (LPCWSTR name)
1721 return LoadImageW( 0, name, IMAGE_CURSOR, 0, 0,
1722 LR_LOADFROMFILE | LR_DEFAULTSIZE );
1725 /***********************************************************************
1726 * LoadCursorFromFileA (USER32.@)
1728 HCURSOR WINAPI LoadCursorFromFileA (LPCSTR name)
1730 return LoadImageA( 0, name, IMAGE_CURSOR, 0, 0,
1731 LR_LOADFROMFILE | LR_DEFAULTSIZE );
1734 /***********************************************************************
1735 * LoadIconW (USER32.@)
1737 HICON WINAPI LoadIconW(HINSTANCE hInstance, LPCWSTR name)
1739 return LoadImageW( hInstance, name, IMAGE_ICON, 0, 0,
1740 LR_SHARED | LR_DEFAULTSIZE );
1743 /***********************************************************************
1744 * LoadIconA (USER32.@)
1746 HICON WINAPI LoadIconA(HINSTANCE hInstance, LPCSTR name)
1748 return LoadImageA( hInstance, name, IMAGE_ICON, 0, 0,
1749 LR_SHARED | LR_DEFAULTSIZE );
1752 /**********************************************************************
1753 * GetIconInfo (USER32.@)
1755 BOOL WINAPI GetIconInfo(HICON hIcon, PICONINFO iconinfo)
1757 CURSORICONINFO *ciconinfo;
1760 ciconinfo = GlobalLock16(HICON_16(hIcon));
1764 if ( (ciconinfo->ptHotSpot.x == ICON_HOTSPOT) &&
1765 (ciconinfo->ptHotSpot.y == ICON_HOTSPOT) )
1767 iconinfo->fIcon = TRUE;
1768 iconinfo->xHotspot = ciconinfo->nWidth / 2;
1769 iconinfo->yHotspot = ciconinfo->nHeight / 2;
1773 iconinfo->fIcon = FALSE;
1774 iconinfo->xHotspot = ciconinfo->ptHotSpot.x;
1775 iconinfo->yHotspot = ciconinfo->ptHotSpot.y;
1778 if (ciconinfo->bBitsPerPixel > 1)
1780 iconinfo->hbmColor = CreateBitmap( ciconinfo->nWidth, ciconinfo->nHeight,
1781 ciconinfo->bPlanes, ciconinfo->bBitsPerPixel,
1782 (char *)(ciconinfo + 1)
1783 + ciconinfo->nHeight *
1784 get_bitmap_width_bytes (ciconinfo->nWidth,1) );
1785 height = ciconinfo->nHeight;
1789 iconinfo->hbmColor = 0;
1790 height = ciconinfo->nHeight * 2;
1793 iconinfo->hbmMask = CreateBitmap ( ciconinfo->nWidth, height,
1794 1, 1, (char *)(ciconinfo + 1));
1796 GlobalUnlock16(HICON_16(hIcon));
1801 /**********************************************************************
1802 * CreateIconIndirect (USER32.@)
1804 HICON WINAPI CreateIconIndirect(PICONINFO iconinfo)
1806 BITMAP bmpXor,bmpAnd;
1808 int sizeXor,sizeAnd;
1810 if (iconinfo->hbmColor) GetObjectA( iconinfo->hbmColor, sizeof(bmpXor), &bmpXor );
1811 GetObjectA( iconinfo->hbmMask, sizeof(bmpAnd), &bmpAnd );
1813 sizeXor = iconinfo->hbmColor ? (bmpXor.bmHeight * bmpXor.bmWidthBytes) : 0;
1814 sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
1816 hObj = GlobalAlloc16( GMEM_MOVEABLE,
1817 sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
1820 CURSORICONINFO *info;
1822 info = (CURSORICONINFO *)GlobalLock16( hObj );
1824 /* If we are creating an icon, the hotspot is unused */
1825 if (iconinfo->fIcon)
1827 info->ptHotSpot.x = ICON_HOTSPOT;
1828 info->ptHotSpot.y = ICON_HOTSPOT;
1832 info->ptHotSpot.x = iconinfo->xHotspot;
1833 info->ptHotSpot.y = iconinfo->yHotspot;
1836 info->nWidth = bmpAnd.bmWidth;
1837 info->nHeight = iconinfo->hbmColor ? bmpAnd.bmHeight : (bmpAnd.bmHeight / 2);
1838 info->nWidthBytes = bmpAnd.bmWidthBytes;
1839 info->bPlanes = bmpAnd.bmPlanes;
1840 info->bBitsPerPixel = bmpAnd.bmBitsPixel;
1842 /* Transfer the bitmap bits to the CURSORICONINFO structure */
1844 GetBitmapBits( iconinfo->hbmMask, sizeAnd, (char*)(info + 1) );
1845 if (iconinfo->hbmColor) GetBitmapBits( iconinfo->hbmColor, sizeXor, (char*)(info + 1) + sizeAnd );
1846 GlobalUnlock16( hObj );
1848 return HICON_32(hObj);
1851 /******************************************************************************
1852 * DrawIconEx (USER32.@) Draws an icon or cursor on device context
1855 * Why is this using SM_CXICON instead of SM_CXCURSOR?
1858 * hdc [I] Handle to device context
1859 * x0 [I] X coordinate of upper left corner
1860 * y0 [I] Y coordinate of upper left corner
1861 * hIcon [I] Handle to icon to draw
1862 * cxWidth [I] Width of icon
1863 * cyWidth [I] Height of icon
1864 * istep [I] Index of frame in animated cursor
1865 * hbr [I] Handle to background brush
1866 * flags [I] Icon-drawing flags
1872 BOOL WINAPI DrawIconEx( HDC hdc, INT x0, INT y0, HICON hIcon,
1873 INT cxWidth, INT cyWidth, UINT istep,
1874 HBRUSH hbr, UINT flags )
1876 CURSORICONINFO *ptr = (CURSORICONINFO *)GlobalLock16(HICON_16(hIcon));
1877 HDC hDC_off = 0, hMemDC;
1878 BOOL result = FALSE, DoOffscreen;
1879 HBITMAP hB_off = 0, hOld = 0;
1881 if (!ptr) return FALSE;
1882 TRACE_(icon)("(hdc=%p,pos=%d.%d,hicon=%p,extend=%d.%d,istep=%d,br=%p,flags=0x%08x)\n",
1883 hdc,x0,y0,hIcon,cxWidth,cyWidth,istep,hbr,flags );
1885 hMemDC = CreateCompatibleDC (hdc);
1887 FIXME_(icon)("Ignoring istep=%d\n", istep);
1888 if (flags & DI_COMPAT)
1889 FIXME_(icon)("Ignoring flag DI_COMPAT\n");
1892 FIXME_(icon)("no flags set? setting to DI_NORMAL\n");
1896 /* Calculate the size of the destination image. */
1899 if (flags & DI_DEFAULTSIZE)
1900 cxWidth = GetSystemMetrics (SM_CXICON);
1902 cxWidth = ptr->nWidth;
1906 if (flags & DI_DEFAULTSIZE)
1907 cyWidth = GetSystemMetrics (SM_CYICON);
1909 cyWidth = ptr->nHeight;
1912 DoOffscreen = (GetObjectType( hbr ) == OBJ_BRUSH);
1922 hDC_off = CreateCompatibleDC(hdc);
1923 hB_off = CreateCompatibleBitmap(hdc, cxWidth, cyWidth);
1924 if (hDC_off && hB_off) {
1925 hOld = SelectObject(hDC_off, hB_off);
1926 FillRect(hDC_off, &r, hbr);
1930 if (hMemDC && (!DoOffscreen || (hDC_off && hB_off)))
1932 HBITMAP hXorBits, hAndBits;
1933 COLORREF oldFg, oldBg;
1936 nStretchMode = SetStretchBltMode (hdc, STRETCH_DELETESCANS);
1938 hXorBits = CreateBitmap ( ptr->nWidth, ptr->nHeight,
1939 ptr->bPlanes, ptr->bBitsPerPixel,
1942 get_bitmap_width_bytes(ptr->nWidth,1) );
1943 hAndBits = CreateBitmap ( ptr->nWidth, ptr->nHeight,
1944 1, 1, (char *)(ptr+1) );
1945 oldFg = SetTextColor( hdc, RGB(0,0,0) );
1946 oldBg = SetBkColor( hdc, RGB(255,255,255) );
1948 if (hXorBits && hAndBits)
1950 HBITMAP hBitTemp = SelectObject( hMemDC, hAndBits );
1951 if (flags & DI_MASK)
1954 StretchBlt (hDC_off, 0, 0, cxWidth, cyWidth,
1955 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCAND);
1957 StretchBlt (hdc, x0, y0, cxWidth, cyWidth,
1958 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCAND);
1960 SelectObject( hMemDC, hXorBits );
1961 if (flags & DI_IMAGE)
1964 StretchBlt (hDC_off, 0, 0, cxWidth, cyWidth,
1965 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCPAINT);
1967 StretchBlt (hdc, x0, y0, cxWidth, cyWidth,
1968 hMemDC, 0, 0, ptr->nWidth, ptr->nHeight, SRCPAINT);
1970 SelectObject( hMemDC, hBitTemp );
1974 SetTextColor( hdc, oldFg );
1975 SetBkColor( hdc, oldBg );
1976 if (hXorBits) DeleteObject( hXorBits );
1977 if (hAndBits) DeleteObject( hAndBits );
1978 SetStretchBltMode (hdc, nStretchMode);
1980 BitBlt(hdc, x0, y0, cxWidth, cyWidth, hDC_off, 0, 0, SRCCOPY);
1981 SelectObject(hDC_off, hOld);
1984 if (hMemDC) DeleteDC( hMemDC );
1985 if (hDC_off) DeleteDC(hDC_off);
1986 if (hB_off) DeleteObject(hB_off);
1987 GlobalUnlock16(HICON_16(hIcon));
1991 /***********************************************************************
1992 * DIB_FixColorsToLoadflags
1994 * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
1997 static void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT loadflags, BYTE pix)
2000 COLORREF c_W, c_S, c_F, c_L, c_C;
2009 if (((bitmap_type = DIB_GetBitmapInfo((BITMAPINFOHEADER*) bmi, &width, &height, &bpp, &compr)) == -1))
2011 WARN_(resource)("Invalid bitmap\n");
2015 if (bpp > 8) return;
2017 if (bitmap_type == 0) /* BITMAPCOREHEADER */
2025 colors = bmi->bmiHeader.biClrUsed;
2026 if (colors > 256) colors = 256;
2027 if (!colors && (bpp <= 8)) colors = 1 << bpp;
2030 c_W = GetSysColor(COLOR_WINDOW);
2031 c_S = GetSysColor(COLOR_3DSHADOW);
2032 c_F = GetSysColor(COLOR_3DFACE);
2033 c_L = GetSysColor(COLOR_3DLIGHT);
2035 if (loadflags & LR_LOADTRANSPARENT) {
2037 case 1: pix = pix >> 7; break;
2038 case 4: pix = pix >> 4; break;
2041 WARN_(resource)("(%d): Unsupported depth\n", bpp);
2044 if (pix >= colors) {
2045 WARN_(resource)("pixel has color index greater than biClrUsed!\n");
2048 if (loadflags & LR_LOADMAP3DCOLORS) c_W = c_F;
2049 ptr = (RGBQUAD*)((char*)bmi->bmiColors+pix*incr);
2050 ptr->rgbBlue = GetBValue(c_W);
2051 ptr->rgbGreen = GetGValue(c_W);
2052 ptr->rgbRed = GetRValue(c_W);
2054 if (loadflags & LR_LOADMAP3DCOLORS)
2055 for (i=0; i<colors; i++) {
2056 ptr = (RGBQUAD*)((char*)bmi->bmiColors+i*incr);
2057 c_C = RGB(ptr->rgbRed, ptr->rgbGreen, ptr->rgbBlue);
2058 if (c_C == RGB(128, 128, 128)) {
2059 ptr->rgbRed = GetRValue(c_S);
2060 ptr->rgbGreen = GetGValue(c_S);
2061 ptr->rgbBlue = GetBValue(c_S);
2062 } else if (c_C == RGB(192, 192, 192)) {
2063 ptr->rgbRed = GetRValue(c_F);
2064 ptr->rgbGreen = GetGValue(c_F);
2065 ptr->rgbBlue = GetBValue(c_F);
2066 } else if (c_C == RGB(223, 223, 223)) {
2067 ptr->rgbRed = GetRValue(c_L);
2068 ptr->rgbGreen = GetGValue(c_L);
2069 ptr->rgbBlue = GetBValue(c_L);
2075 /**********************************************************************
2078 static HBITMAP BITMAP_Load( HINSTANCE instance, LPCWSTR name,
2079 INT desiredx, INT desiredy, UINT loadflags )
2081 HBITMAP hbitmap = 0, orig_bm;
2085 BITMAPINFO *info, *fix_info = NULL, *scaled_info = NULL;
2089 LONG width, height, new_width, new_height;
2093 HDC screen_mem_dc = NULL;
2095 if (!(loadflags & LR_LOADFROMFILE))
2099 /* OEM bitmap: try to load the resource from user32.dll */
2100 if (HIWORD(name)) return 0;
2101 instance = user32_module;
2104 if (!(hRsrc = FindResourceW( instance, name, (LPWSTR)RT_BITMAP ))) return 0;
2105 if (!(handle = LoadResource( instance, hRsrc ))) return 0;
2107 if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
2111 if (!(ptr = map_fileW( name, NULL ))) return 0;
2112 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
2115 size = bitmap_info_size(info, DIB_RGB_COLORS);
2116 fix_info = HeapAlloc(GetProcessHeap(), 0, size);
2117 scaled_info = HeapAlloc(GetProcessHeap(), 0, size);
2119 if (!fix_info || !scaled_info) goto end;
2120 memcpy(fix_info, info, size);
2122 pix = *((LPBYTE)info + size);
2123 DIB_FixColorsToLoadflags(fix_info, loadflags, pix);
2125 memcpy(scaled_info, fix_info, size);
2126 bm_type = DIB_GetBitmapInfo( &fix_info->bmiHeader, &width, &height,
2127 &bpp_dummy, &compr_dummy);
2129 new_width = desiredx;
2134 new_height = height > 0 ? desiredy : -desiredy;
2136 new_height = height;
2140 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)&scaled_info->bmiHeader;
2141 core->bcWidth = new_width;
2142 core->bcHeight = new_height;
2146 scaled_info->bmiHeader.biWidth = new_width;
2147 scaled_info->bmiHeader.biHeight = new_height;
2150 if (new_height < 0) new_height = -new_height;
2152 if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
2153 if (!(screen_mem_dc = CreateCompatibleDC( screen_dc ))) goto end;
2155 bits = (char *)info + size;
2157 if (loadflags & LR_CREATEDIBSECTION)
2159 scaled_info->bmiHeader.biCompression = 0; /* DIBSection can't be compressed */
2160 hbitmap = CreateDIBSection(screen_dc, scaled_info, DIB_RGB_COLORS, NULL, 0, 0);
2164 if (is_dib_monochrome(fix_info))
2165 hbitmap = CreateBitmap(new_width, new_height, 1, 1, NULL);
2167 hbitmap = CreateCompatibleBitmap(screen_dc, new_width, new_height);
2170 orig_bm = SelectObject(screen_mem_dc, hbitmap);
2171 StretchDIBits(screen_mem_dc, 0, 0, new_width, new_height, 0, 0, width, height, bits, fix_info, DIB_RGB_COLORS, SRCCOPY);
2172 SelectObject(screen_mem_dc, orig_bm);
2175 if (screen_mem_dc) DeleteDC(screen_mem_dc);
2176 HeapFree(GetProcessHeap(), 0, scaled_info);
2177 HeapFree(GetProcessHeap(), 0, fix_info);
2178 if (loadflags & LR_LOADFROMFILE) UnmapViewOfFile( ptr );
2183 /**********************************************************************
2184 * LoadImageA (USER32.@)
2186 * FIXME: implementation lacks some features, see LR_ defines in winuser.h
2189 /* filter for page-fault exceptions */
2190 static WINE_EXCEPTION_FILTER(page_fault)
2192 if (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)
2193 return EXCEPTION_EXECUTE_HANDLER;
2194 return EXCEPTION_CONTINUE_SEARCH;
2197 /*********************************************************************/
2199 HANDLE WINAPI LoadImageA( HINSTANCE hinst, LPCSTR name, UINT type,
2200 INT desiredx, INT desiredy, UINT loadflags)
2206 return LoadImageW(hinst, (LPCWSTR)name, type, desiredx, desiredy, loadflags);
2209 DWORD len = MultiByteToWideChar( CP_ACP, 0, name, -1, NULL, 0 );
2210 u_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
2211 MultiByteToWideChar( CP_ACP, 0, name, -1, u_name, len );
2213 __EXCEPT(page_fault) {
2214 SetLastError( ERROR_INVALID_PARAMETER );
2218 res = LoadImageW(hinst, u_name, type, desiredx, desiredy, loadflags);
2219 HeapFree(GetProcessHeap(), 0, u_name);
2224 /******************************************************************************
2225 * LoadImageW (USER32.@) Loads an icon, cursor, or bitmap
2228 * hinst [I] Handle of instance that contains image
2229 * name [I] Name of image
2230 * type [I] Type of image
2231 * desiredx [I] Desired width
2232 * desiredy [I] Desired height
2233 * loadflags [I] Load flags
2236 * Success: Handle to newly loaded image
2239 * FIXME: Implementation lacks some features, see LR_ defines in winuser.h
2241 HANDLE WINAPI LoadImageW( HINSTANCE hinst, LPCWSTR name, UINT type,
2242 INT desiredx, INT desiredy, UINT loadflags )
2244 TRACE_(resource)("(%p,%s,%d,%d,%d,0x%08x)\n",
2245 hinst,debugstr_w(name),type,desiredx,desiredy,loadflags);
2247 if (loadflags & LR_DEFAULTSIZE) {
2248 if (type == IMAGE_ICON) {
2249 if (!desiredx) desiredx = GetSystemMetrics(SM_CXICON);
2250 if (!desiredy) desiredy = GetSystemMetrics(SM_CYICON);
2251 } else if (type == IMAGE_CURSOR) {
2252 if (!desiredx) desiredx = GetSystemMetrics(SM_CXCURSOR);
2253 if (!desiredy) desiredy = GetSystemMetrics(SM_CYCURSOR);
2256 if (loadflags & LR_LOADFROMFILE) loadflags &= ~LR_SHARED;
2259 return BITMAP_Load( hinst, name, desiredx, desiredy, loadflags );
2262 if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
2265 UINT palEnts = GetSystemPaletteEntries(screen_dc, 0, 0, NULL);
2266 if (palEnts == 0) palEnts = 256;
2267 return CURSORICON_Load(hinst, name, desiredx, desiredy,
2268 palEnts, FALSE, loadflags);
2273 return CURSORICON_Load(hinst, name, desiredx, desiredy,
2274 1, TRUE, loadflags);
2279 /******************************************************************************
2280 * CopyImage (USER32.@) Creates new image and copies attributes to it
2283 * hnd [I] Handle to image to copy
2284 * type [I] Type of image to copy
2285 * desiredx [I] Desired width of new image
2286 * desiredy [I] Desired height of new image
2287 * flags [I] Copy flags
2290 * Success: Handle to newly created image
2293 * FIXME: implementation still lacks nearly all features, see LR_*
2294 * defines in winuser.h
2296 HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
2297 INT desiredy, UINT flags )
2306 if (!GetObjectW( hnd, sizeof(bm), &bm )) return 0;
2308 if ((res = CreateBitmapIndirect(&bm)))
2310 char *buf = HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes * bm.bmHeight );
2311 GetBitmapBits( hnd, bm.bmWidthBytes * bm.bmHeight, buf );
2312 SetBitmapBits( res, bm.bmWidthBytes * bm.bmHeight, buf );
2313 HeapFree( GetProcessHeap(), 0, buf );
2318 return CURSORICON_ExtCopy(hnd,type, desiredx, desiredy, flags);
2320 /* Should call CURSORICON_ExtCopy but more testing
2321 * needs to be done before we change this
2323 return CopyCursor(hnd);
2329 /******************************************************************************
2330 * LoadBitmapW (USER32.@) Loads bitmap from the executable file
2333 * Success: Handle to specified bitmap
2336 HBITMAP WINAPI LoadBitmapW(
2337 HINSTANCE instance, /* [in] Handle to application instance */
2338 LPCWSTR name) /* [in] Address of bitmap resource name */
2340 return LoadImageW( instance, name, IMAGE_BITMAP, 0, 0, 0 );
2343 /**********************************************************************
2344 * LoadBitmapA (USER32.@)
2346 HBITMAP WINAPI LoadBitmapA( HINSTANCE instance, LPCSTR name )
2348 return LoadImageA( instance, name, IMAGE_BITMAP, 0, 0, 0 );