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.
547 * FIXME: parameter 'color' ignored and entries with more than 1 bpp
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
) &&
573 if (bestEntry
!= -1) return bestEntry
;
575 /* Now find the smallest one larger than the requested size */
577 maxwidth
= maxheight
= 255;
578 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
580 if (((cx
< maxwidth
) && (cy
< maxheight
) && (bits
== 1)) ||
592 static BOOL
CURSORICON_GetResCursorEntry( LPVOID dir
, int n
,
593 int *width
, int *height
, int *bits
)
595 CURSORICONDIR
*resdir
= dir
;
598 if ( resdir
->idCount
<= n
)
600 cursor
= &resdir
->idEntries
[n
].ResInfo
.cursor
;
601 *width
= cursor
->wWidth
;
602 *height
= cursor
->wHeight
;
603 *bits
= resdir
->idEntries
[n
].wBitCount
;
607 static CURSORICONDIRENTRY
*CURSORICON_FindBestIconRes( CURSORICONDIR
* dir
,
608 int width
, int height
, int colors
)
612 n
= CURSORICON_FindBestIcon( dir
, CURSORICON_GetResIconEntry
,
613 width
, height
, colors
);
616 return &dir
->idEntries
[n
];
619 static CURSORICONDIRENTRY
*CURSORICON_FindBestCursorRes( CURSORICONDIR
*dir
,
620 int width
, int height
, int color
)
622 int n
= CURSORICON_FindBestCursor( dir
, CURSORICON_GetResCursorEntry
,
623 width
, height
, color
);
626 return &dir
->idEntries
[n
];
629 static BOOL
CURSORICON_GetFileEntry( LPVOID dir
, int n
,
630 int *width
, int *height
, int *bits
)
632 CURSORICONFILEDIR
*filedir
= dir
;
633 CURSORICONFILEDIRENTRY
*entry
;
635 if ( filedir
->idCount
<= n
)
637 entry
= &filedir
->idEntries
[n
];
638 *width
= entry
->bWidth
;
639 *height
= entry
->bHeight
;
640 *bits
= entry
->bColorCount
;
644 static CURSORICONFILEDIRENTRY
*CURSORICON_FindBestCursorFile( CURSORICONFILEDIR
*dir
,
645 int width
, int height
, int color
)
647 int n
= CURSORICON_FindBestCursor( dir
, CURSORICON_GetFileEntry
,
648 width
, height
, color
);
651 return &dir
->idEntries
[n
];
654 static CURSORICONFILEDIRENTRY
*CURSORICON_FindBestIconFile( CURSORICONFILEDIR
*dir
,
655 int width
, int height
, int color
)
657 int n
= CURSORICON_FindBestIcon( dir
, CURSORICON_GetFileEntry
,
658 width
, height
, color
);
661 return &dir
->idEntries
[n
];
664 static HICON
CURSORICON_CreateIconFromBMI( BITMAPINFO
*bmi
,
665 POINT16 hotspot
, BOOL bIcon
,
667 INT width
, INT height
,
672 int sizeAnd
, sizeXor
;
673 HBITMAP hAndBits
= 0, hXorBits
= 0; /* error condition for later */
674 BITMAP bmpXor
, bmpAnd
;
678 if (dwVersion
== 0x00020000)
680 FIXME_(cursor
)("\t2.xx resources are not supported\n");
684 /* Check bitmap header */
686 if ( (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) &&
687 (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) ||
688 bmi
->bmiHeader
.biCompression
!= BI_RGB
) )
690 WARN_(cursor
)("\tinvalid resource bitmap header.\n");
694 size
= bitmap_info_size( bmi
, DIB_RGB_COLORS
);
696 if (!width
) width
= bmi
->bmiHeader
.biWidth
;
697 if (!height
) height
= bmi
->bmiHeader
.biHeight
/2;
698 DoStretch
= (bmi
->bmiHeader
.biHeight
/2 != height
) ||
699 (bmi
->bmiHeader
.biWidth
!= width
);
701 /* Scale the hotspot */
702 if (DoStretch
&& hotspot
.x
!= ICON_HOTSPOT
&& hotspot
.y
!= ICON_HOTSPOT
)
704 hotspot
.x
= (hotspot
.x
* width
) / bmi
->bmiHeader
.biWidth
;
705 hotspot
.y
= (hotspot
.y
* height
) / (bmi
->bmiHeader
.biHeight
/ 2);
708 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
713 /* Make sure we have room for the monochrome bitmap later on.
714 * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
715 * up to and including the biBitCount. In-memory icon resource
716 * format is as follows:
718 * BITMAPINFOHEADER icHeader // DIB header
719 * RGBQUAD icColors[] // Color table
720 * BYTE icXOR[] // DIB bits for XOR mask
721 * BYTE icAND[] // DIB bits for AND mask
724 if ((pInfo
= HeapAlloc( GetProcessHeap(), 0,
725 max(size
, sizeof(BITMAPINFOHEADER
) + 2*sizeof(RGBQUAD
)))))
727 memcpy( pInfo
, bmi
, size
);
728 pInfo
->bmiHeader
.biHeight
/= 2;
730 /* Create the XOR bitmap */
733 hXorBits
= CreateCompatibleBitmap(screen_dc
, width
, height
);
739 if (!hdcMem
) hdcMem
= CreateCompatibleDC(screen_dc
);
741 hOld
= SelectObject(hdcMem
, hXorBits
);
742 res
= StretchDIBits(hdcMem
, 0, 0, width
, height
, 0, 0,
743 bmi
->bmiHeader
.biWidth
, bmi
->bmiHeader
.biHeight
/2,
744 (char*)bmi
+ size
, pInfo
, DIB_RGB_COLORS
, SRCCOPY
);
745 SelectObject(hdcMem
, hOld
);
747 if (!res
) { DeleteObject(hXorBits
); hXorBits
= 0; }
750 if (is_dib_monochrome(bmi
)) {
751 hXorBits
= CreateBitmap(width
, height
, 1, 1, NULL
);
752 SetDIBits(screen_dc
, hXorBits
, 0, height
,
753 (char*)bmi
+ size
, pInfo
, DIB_RGB_COLORS
);
756 hXorBits
= CreateDIBitmap(screen_dc
, &pInfo
->bmiHeader
,
757 CBM_INIT
, (char*)bmi
+ size
, pInfo
, DIB_RGB_COLORS
);
762 char* xbits
= (char *)bmi
+ size
+
763 get_dib_width_bytes( bmi
->bmiHeader
.biWidth
,
764 bmi
->bmiHeader
.biBitCount
) * abs( bmi
->bmiHeader
.biHeight
) / 2;
766 pInfo
->bmiHeader
.biBitCount
= 1;
767 if (pInfo
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
))
769 RGBQUAD
*rgb
= pInfo
->bmiColors
;
771 pInfo
->bmiHeader
.biClrUsed
= pInfo
->bmiHeader
.biClrImportant
= 2;
772 rgb
[0].rgbBlue
= rgb
[0].rgbGreen
= rgb
[0].rgbRed
= 0x00;
773 rgb
[1].rgbBlue
= rgb
[1].rgbGreen
= rgb
[1].rgbRed
= 0xff;
774 rgb
[0].rgbReserved
= rgb
[1].rgbReserved
= 0;
778 RGBTRIPLE
*rgb
= (RGBTRIPLE
*)(((BITMAPCOREHEADER
*)pInfo
) + 1);
780 rgb
[0].rgbtBlue
= rgb
[0].rgbtGreen
= rgb
[0].rgbtRed
= 0x00;
781 rgb
[1].rgbtBlue
= rgb
[1].rgbtGreen
= rgb
[1].rgbtRed
= 0xff;
784 /* Create the AND bitmap */
787 if ((hAndBits
= CreateBitmap(width
, height
, 1, 1, NULL
))) {
791 if (!hdcMem
) hdcMem
= CreateCompatibleDC(screen_dc
);
793 hOld
= SelectObject(hdcMem
, hAndBits
);
794 res
= StretchDIBits(hdcMem
, 0, 0, width
, height
, 0, 0,
795 pInfo
->bmiHeader
.biWidth
, pInfo
->bmiHeader
.biHeight
,
796 xbits
, pInfo
, DIB_RGB_COLORS
, SRCCOPY
);
797 SelectObject(hdcMem
, hOld
);
799 if (!res
) { DeleteObject(hAndBits
); hAndBits
= 0; }
802 hAndBits
= CreateBitmap(width
, height
, 1, 1, NULL
);
804 if (hAndBits
) SetDIBits(screen_dc
, hAndBits
, 0, height
,
805 xbits
, pInfo
, DIB_RGB_COLORS
);
808 if( !hAndBits
) DeleteObject( hXorBits
);
810 HeapFree( GetProcessHeap(), 0, pInfo
);
814 if( !hXorBits
|| !hAndBits
)
816 WARN_(cursor
)("\tunable to create an icon bitmap.\n");
820 /* Now create the CURSORICONINFO structure */
821 GetObjectA( hXorBits
, sizeof(bmpXor
), &bmpXor
);
822 GetObjectA( hAndBits
, sizeof(bmpAnd
), &bmpAnd
);
823 sizeXor
= bmpXor
.bmHeight
* bmpXor
.bmWidthBytes
;
824 sizeAnd
= bmpAnd
.bmHeight
* bmpAnd
.bmWidthBytes
;
826 hObj
= GlobalAlloc16( GMEM_MOVEABLE
,
827 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
);
830 CURSORICONINFO
*info
;
832 info
= GlobalLock16( hObj
);
833 info
->ptHotSpot
.x
= hotspot
.x
;
834 info
->ptHotSpot
.y
= hotspot
.y
;
835 info
->nWidth
= bmpXor
.bmWidth
;
836 info
->nHeight
= bmpXor
.bmHeight
;
837 info
->nWidthBytes
= bmpXor
.bmWidthBytes
;
838 info
->bPlanes
= bmpXor
.bmPlanes
;
839 info
->bBitsPerPixel
= bmpXor
.bmBitsPixel
;
841 /* Transfer the bitmap bits to the CURSORICONINFO structure */
843 GetBitmapBits( hAndBits
, sizeAnd
, (char *)(info
+ 1) );
844 GetBitmapBits( hXorBits
, sizeXor
, (char *)(info
+ 1) + sizeAnd
);
845 GlobalUnlock16( hObj
);
848 DeleteObject( hAndBits
);
849 DeleteObject( hXorBits
);
850 return HICON_32(hObj
);
854 /**********************************************************************
855 * .ANI cursor support
857 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
858 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
859 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
861 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
862 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
863 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
864 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
865 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
866 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
868 #define ANI_FLAG_ICON 0x1
869 #define ANI_FLAG_SEQUENCE 0x2
885 const unsigned char *data
;
888 static void dump_ani_header( const ani_header
*header
)
890 TRACE(" header size: %d\n", header
->header_size
);
891 TRACE(" frames: %d\n", header
->num_frames
);
892 TRACE(" steps: %d\n", header
->num_steps
);
893 TRACE(" width: %d\n", header
->width
);
894 TRACE(" height: %d\n", header
->height
);
895 TRACE(" bpp: %d\n", header
->bpp
);
896 TRACE(" planes: %d\n", header
->num_planes
);
897 TRACE(" display rate: %d\n", header
->display_rate
);
898 TRACE(" flags: 0x%08x\n", header
->flags
);
920 static void riff_find_chunk( DWORD chunk_id
, DWORD chunk_type
, const riff_chunk_t
*parent_chunk
, riff_chunk_t
*chunk
)
922 const unsigned char *ptr
= parent_chunk
->data
;
923 const unsigned char *end
= parent_chunk
->data
+ (parent_chunk
->data_size
- (2 * sizeof(DWORD
)));
925 if (chunk_type
== ANI_LIST_ID
|| chunk_type
== ANI_RIFF_ID
) end
-= sizeof(DWORD
);
929 if ((!chunk_type
&& *(DWORD
*)ptr
== chunk_id
)
930 || (chunk_type
&& *(DWORD
*)ptr
== chunk_type
&& *((DWORD
*)ptr
+ 2) == chunk_id
))
932 ptr
+= sizeof(DWORD
);
933 chunk
->data_size
= *(DWORD
*)ptr
;
934 ptr
+= sizeof(DWORD
);
935 if (chunk_type
== ANI_LIST_ID
|| chunk_type
== ANI_RIFF_ID
) ptr
+= sizeof(DWORD
);
941 ptr
+= sizeof(DWORD
);
942 ptr
+= *(DWORD
*)ptr
;
943 ptr
+= sizeof(DWORD
);
951 * RIFF:'ACON' RIFF chunk
952 * |- CHUNK:'anih' Header
953 * |- CHUNK:'seq ' Sequence information (optional)
954 * \- LIST:'fram' Frame list
955 * |- CHUNK:icon Cursor frames
960 static HCURSOR
CURSORICON_CreateIconFromANI( const LPBYTE bits
, DWORD bits_size
,
961 INT width
, INT height
)
964 ani_header header
= {0};
965 LPBYTE frame_bits
= 0;
967 CURSORICONFILEDIRENTRY
*entry
;
969 riff_chunk_t root_chunk
= { bits_size
, bits
};
970 riff_chunk_t ACON_chunk
= {0};
971 riff_chunk_t anih_chunk
= {0};
972 riff_chunk_t fram_chunk
= {0};
973 const unsigned char *icon_data
;
975 TRACE("bits %p, bits_size %d\n", bits
, bits_size
);
979 riff_find_chunk( ANI_ACON_ID
, ANI_RIFF_ID
, &root_chunk
, &ACON_chunk
);
980 if (!ACON_chunk
.data
)
982 ERR("Failed to get root chunk.\n");
986 riff_find_chunk( ANI_anih_ID
, 0, &ACON_chunk
, &anih_chunk
);
987 if (!anih_chunk
.data
)
989 ERR("Failed to get 'anih' chunk.\n");
992 memcpy( &header
, anih_chunk
.data
, sizeof(header
) );
993 dump_ani_header( &header
);
995 riff_find_chunk( ANI_fram_ID
, ANI_LIST_ID
, &ACON_chunk
, &fram_chunk
);
996 if (!fram_chunk
.data
)
998 ERR("Failed to get icon list.\n");
1002 /* FIXME: For now, just load the first frame. Before we can load all the
1003 * frames, we need to write the needed code in wineserver, etc. to handle
1004 * cursors. Once this code is written, we can extend it to support .ani
1005 * cursors and then update user32 and winex11.drv to load all frames.
1007 * Hopefully this will at least make some games (C&C3, etc.) more playable
1010 FIXME("Loading all frames for .ani cursors not implemented.\n");
1011 icon_data
= fram_chunk
.data
+ (2 * sizeof(DWORD
));
1013 entry
= CURSORICON_FindBestCursorFile( (CURSORICONFILEDIR
*) icon_data
,
1016 frame_bits
= HeapAlloc( GetProcessHeap(), 0, entry
->dwDIBSize
);
1017 memcpy( frame_bits
, icon_data
+ entry
->dwDIBOffset
, entry
->dwDIBSize
);
1019 if (!header
.width
|| !header
.height
)
1021 header
.width
= entry
->bWidth
;
1022 header
.height
= entry
->bHeight
;
1025 hotspot
.x
= entry
->xHotspot
;
1026 hotspot
.y
= entry
->yHotspot
;
1028 cursor
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*) frame_bits
, hotspot
,
1029 FALSE
, 0x00030000, header
.width
, header
.height
, 0 );
1031 HeapFree( GetProcessHeap(), 0, frame_bits
);
1037 /**********************************************************************
1038 * CreateIconFromResourceEx (USER32.@)
1040 * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
1041 * with cbSize parameter as well.
1043 HICON WINAPI
CreateIconFromResourceEx( LPBYTE bits
, UINT cbSize
,
1044 BOOL bIcon
, DWORD dwVersion
,
1045 INT width
, INT height
,
1051 hotspot
.x
= ICON_HOTSPOT
;
1052 hotspot
.y
= ICON_HOTSPOT
;
1054 TRACE_(cursor
)("%p (%u bytes), ver %08x, %ix%i %s %s\n",
1055 bits
, cbSize
, dwVersion
, width
, height
,
1056 bIcon
? "icon" : "cursor", (cFlag
& LR_MONOCHROME
) ? "mono" : "" );
1059 bmi
= (BITMAPINFO
*)bits
;
1060 else /* get the hotspot */
1062 POINT16
*pt
= (POINT16
*)bits
;
1064 bmi
= (BITMAPINFO
*)(pt
+ 1);
1067 return CURSORICON_CreateIconFromBMI( bmi
, hotspot
, bIcon
, dwVersion
,
1068 width
, height
, cFlag
);
1072 /**********************************************************************
1073 * CreateIconFromResource (USER32.@)
1075 HICON WINAPI
CreateIconFromResource( LPBYTE bits
, UINT cbSize
,
1076 BOOL bIcon
, DWORD dwVersion
)
1078 return CreateIconFromResourceEx( bits
, cbSize
, bIcon
, dwVersion
, 0,0,0);
1082 static HICON
CURSORICON_LoadFromFile( LPCWSTR filename
,
1083 INT width
, INT height
, INT colors
,
1084 BOOL fCursor
, UINT loadflags
)
1086 CURSORICONFILEDIRENTRY
*entry
;
1087 CURSORICONFILEDIR
*dir
;
1093 TRACE("loading %s\n", debugstr_w( filename
));
1095 bits
= map_fileW( filename
, &filesize
);
1099 /* Check for .ani. */
1100 if (memcmp( bits
, "RIFF", 4 ) == 0)
1102 hIcon
= CURSORICON_CreateIconFromANI( bits
, filesize
, width
, height
);
1106 dir
= (CURSORICONFILEDIR
*) bits
;
1107 if ( filesize
< sizeof(*dir
) )
1110 if ( filesize
< (sizeof(*dir
) + sizeof(dir
->idEntries
[0])*(dir
->idCount
-1)) )
1114 entry
= CURSORICON_FindBestCursorFile( dir
, width
, height
, colors
);
1116 entry
= CURSORICON_FindBestIconFile( dir
, width
, height
, colors
);
1121 /* check that we don't run off the end of the file */
1122 if ( entry
->dwDIBOffset
> filesize
)
1124 if ( entry
->dwDIBOffset
+ entry
->dwDIBSize
> filesize
)
1127 hotspot
.x
= entry
->xHotspot
;
1128 hotspot
.y
= entry
->yHotspot
;
1129 hIcon
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*)&bits
[entry
->dwDIBOffset
],
1130 hotspot
, !fCursor
, 0x00030000,
1131 width
, height
, loadflags
);
1133 TRACE("loaded %s -> %p\n", debugstr_w( filename
), hIcon
);
1134 UnmapViewOfFile( bits
);
1138 /**********************************************************************
1141 * Load a cursor or icon from resource or file.
1143 static HICON
CURSORICON_Load(HINSTANCE hInstance
, LPCWSTR name
,
1144 INT width
, INT height
, INT colors
,
1145 BOOL fCursor
, UINT loadflags
)
1149 HRSRC hRsrc
, hGroupRsrc
;
1151 CURSORICONDIRENTRY
*dirEntry
;
1156 TRACE("%p, %s, %dx%d, colors %d, fCursor %d, flags 0x%04x\n",
1157 hInstance
, debugstr_w(name
), width
, height
, colors
, fCursor
, loadflags
);
1159 if ( loadflags
& LR_LOADFROMFILE
) /* Load from file */
1160 return CURSORICON_LoadFromFile( name
, width
, height
, colors
, fCursor
, loadflags
);
1162 if (!hInstance
) hInstance
= user32_module
; /* Load OEM cursor/icon */
1164 /* Normalize hInstance (must be uniquely represented for icon cache) */
1166 if (!HIWORD( hInstance
))
1167 hInstance
= HINSTANCE_32(GetExePtr( HINSTANCE_16(hInstance
) ));
1169 /* Get directory resource ID */
1171 if (!(hRsrc
= FindResourceW( hInstance
, name
,
1172 (LPWSTR
)(fCursor
? RT_GROUP_CURSOR
: RT_GROUP_ICON
) )))
1176 /* Find the best entry in the directory */
1178 if (!(handle
= LoadResource( hInstance
, hRsrc
))) return 0;
1179 if (!(dir
= LockResource( handle
))) return 0;
1181 dirEntry
= CURSORICON_FindBestCursorRes( dir
, width
, height
, 1);
1183 dirEntry
= CURSORICON_FindBestIconRes( dir
, width
, height
, colors
);
1184 if (!dirEntry
) return 0;
1185 wResId
= dirEntry
->wResId
;
1186 dwBytesInRes
= dirEntry
->dwBytesInRes
;
1187 FreeResource( handle
);
1189 /* Load the resource */
1191 if (!(hRsrc
= FindResourceW(hInstance
,MAKEINTRESOURCEW(wResId
),
1192 (LPWSTR
)(fCursor
? RT_CURSOR
: RT_ICON
) ))) return 0;
1194 /* If shared icon, check whether it was already loaded */
1195 if ( (loadflags
& LR_SHARED
)
1196 && (hIcon
= CURSORICON_FindSharedIcon( hInstance
, hRsrc
) ) != 0 )
1199 if (!(handle
= LoadResource( hInstance
, hRsrc
))) return 0;
1200 bits
= LockResource( handle
);
1201 hIcon
= CreateIconFromResourceEx( bits
, dwBytesInRes
,
1202 !fCursor
, 0x00030000, width
, height
, loadflags
);
1203 FreeResource( handle
);
1205 /* If shared icon, add to icon cache */
1207 if ( hIcon
&& (loadflags
& LR_SHARED
) )
1208 CURSORICON_AddSharedIcon( hInstance
, hRsrc
, hGroupRsrc
, hIcon
);
1213 /***********************************************************************
1216 * Make a copy of a cursor or icon.
1218 static HICON
CURSORICON_Copy( HINSTANCE16 hInst16
, HICON hIcon
)
1220 char *ptrOld
, *ptrNew
;
1222 HICON16 hOld
= HICON_16(hIcon
);
1225 if (!(ptrOld
= GlobalLock16( hOld
))) return 0;
1226 if (hInst16
&& !(hInst16
= GetExePtr( hInst16
))) return 0;
1227 size
= GlobalSize16( hOld
);
1228 hNew
= GlobalAlloc16( GMEM_MOVEABLE
, size
);
1229 FarSetOwner16( hNew
, hInst16
);
1230 ptrNew
= GlobalLock16( hNew
);
1231 memcpy( ptrNew
, ptrOld
, size
);
1232 GlobalUnlock16( hOld
);
1233 GlobalUnlock16( hNew
);
1234 return HICON_32(hNew
);
1237 /*************************************************************************
1238 * CURSORICON_ExtCopy
1240 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified
1243 * Handle [I] handle to an Image
1244 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON)
1245 * iDesiredCX [I] The Desired width of the Image
1246 * iDesiredCY [I] The desired height of the Image
1247 * nFlags [I] The flags from CopyImage
1250 * Success: The new handle of the Image
1253 * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented.
1254 * LR_MONOCHROME should be implemented by CreateIconFromResourceEx.
1255 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache.
1260 static HICON
CURSORICON_ExtCopy(HICON hIcon
, UINT nType
,
1261 INT iDesiredCX
, INT iDesiredCY
,
1266 TRACE_(icon
)("hIcon %p, nType %u, iDesiredCX %i, iDesiredCY %i, nFlags %u\n",
1267 hIcon
, nType
, iDesiredCX
, iDesiredCY
, nFlags
);
1274 /* Best Fit or Monochrome */
1275 if( (nFlags
& LR_COPYFROMRESOURCE
1276 && (iDesiredCX
> 0 || iDesiredCY
> 0))
1277 || nFlags
& LR_MONOCHROME
)
1279 ICONCACHE
* pIconCache
= CURSORICON_FindCache(hIcon
);
1281 /* Not Found in Cache, then do a straight copy
1283 if(pIconCache
== NULL
)
1285 hNew
= CURSORICON_Copy(0, hIcon
);
1286 if(nFlags
& LR_COPYFROMRESOURCE
)
1288 TRACE_(icon
)("LR_COPYFROMRESOURCE: Failed to load from cache\n");
1293 int iTargetCY
= iDesiredCY
, iTargetCX
= iDesiredCX
;
1299 CURSORICONDIR
*pDir
;
1300 CURSORICONDIRENTRY
*pDirEntry
;
1301 BOOL bIsIcon
= (nType
== IMAGE_ICON
);
1303 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
1305 if(((nFlags
& LR_MONOCHROME
) && !(nFlags
& LR_COPYFROMRESOURCE
))
1306 || (iDesiredCX
== 0 && iDesiredCY
== 0))
1308 iDesiredCY
= GetSystemMetrics(bIsIcon
?
1309 SM_CYICON
: SM_CYCURSOR
);
1310 iDesiredCX
= GetSystemMetrics(bIsIcon
?
1311 SM_CXICON
: SM_CXCURSOR
);
1314 /* Retrieve the CURSORICONDIRENTRY
1316 if (!(hMem
= LoadResource( pIconCache
->hModule
,
1317 pIconCache
->hGroupRsrc
)))
1321 if (!(pDir
= LockResource( hMem
)))
1330 pDirEntry
= CURSORICON_FindBestIconRes(
1331 pDir
, iDesiredCX
, iDesiredCY
, 256 );
1335 pDirEntry
= CURSORICON_FindBestCursorRes(
1336 pDir
, iDesiredCX
, iDesiredCY
, 1);
1339 wResId
= pDirEntry
->wResId
;
1340 dwBytesInRes
= pDirEntry
->dwBytesInRes
;
1343 TRACE_(icon
)("ResID %u, BytesInRes %u, Width %d, Height %d DX %d, DY %d\n",
1344 wResId
, dwBytesInRes
, pDirEntry
->ResInfo
.icon
.bWidth
,
1345 pDirEntry
->ResInfo
.icon
.bHeight
, iDesiredCX
, iDesiredCY
);
1349 if (!(hRsrc
= FindResourceW(pIconCache
->hModule
,
1350 MAKEINTRESOURCEW(wResId
), (LPWSTR
)(bIsIcon
? RT_ICON
: RT_CURSOR
))))
1354 if (!(hMem
= LoadResource( pIconCache
->hModule
, hRsrc
)))
1359 pBits
= LockResource( hMem
);
1361 if(nFlags
& LR_DEFAULTSIZE
)
1363 iTargetCY
= GetSystemMetrics(SM_CYICON
);
1364 iTargetCX
= GetSystemMetrics(SM_CXICON
);
1367 /* Create a New Icon with the proper dimension
1369 hNew
= CreateIconFromResourceEx( pBits
, dwBytesInRes
,
1370 bIsIcon
, 0x00030000, iTargetCX
, iTargetCY
, nFlags
);
1374 else hNew
= CURSORICON_Copy(0, hIcon
);
1379 /***********************************************************************
1380 * CreateCursor (USER32.@)
1382 HCURSOR WINAPI
CreateCursor( HINSTANCE hInstance
,
1383 INT xHotSpot
, INT yHotSpot
,
1384 INT nWidth
, INT nHeight
,
1385 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
1387 CURSORICONINFO info
;
1389 TRACE_(cursor
)("%dx%d spot=%d,%d xor=%p and=%p\n",
1390 nWidth
, nHeight
, xHotSpot
, yHotSpot
, lpXORbits
, lpANDbits
);
1392 info
.ptHotSpot
.x
= xHotSpot
;
1393 info
.ptHotSpot
.y
= yHotSpot
;
1394 info
.nWidth
= nWidth
;
1395 info
.nHeight
= nHeight
;
1396 info
.nWidthBytes
= 0;
1398 info
.bBitsPerPixel
= 1;
1400 return HICON_32(CreateCursorIconIndirect16(0, &info
, lpANDbits
, lpXORbits
));
1404 /***********************************************************************
1405 * CreateIcon (USER.407)
1407 HICON16 WINAPI
CreateIcon16( HINSTANCE16 hInstance
, INT16 nWidth
,
1408 INT16 nHeight
, BYTE bPlanes
, BYTE bBitsPixel
,
1409 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
1411 CURSORICONINFO info
;
1413 TRACE_(icon
)("%dx%dx%d, xor=%p, and=%p\n",
1414 nWidth
, nHeight
, bPlanes
* bBitsPixel
, lpXORbits
, lpANDbits
);
1416 info
.ptHotSpot
.x
= ICON_HOTSPOT
;
1417 info
.ptHotSpot
.y
= ICON_HOTSPOT
;
1418 info
.nWidth
= nWidth
;
1419 info
.nHeight
= nHeight
;
1420 info
.nWidthBytes
= 0;
1421 info
.bPlanes
= bPlanes
;
1422 info
.bBitsPerPixel
= bBitsPixel
;
1424 return CreateCursorIconIndirect16( hInstance
, &info
, lpANDbits
, lpXORbits
);
1428 /***********************************************************************
1429 * CreateIcon (USER32.@)
1431 * Creates an icon based on the specified bitmaps. The bitmaps must be
1432 * provided in a device dependent format and will be resized to
1433 * (SM_CXICON,SM_CYICON) and depth converted to match the screen's color
1434 * depth. The provided bitmaps must be top-down bitmaps.
1435 * Although Windows does not support 15bpp(*) this API must support it
1436 * for Winelib applications.
1438 * (*) Windows does not support 15bpp but it supports the 555 RGB 16bpp
1442 * Success: handle to an icon
1445 * FIXME: Do we need to resize the bitmaps?
1447 HICON WINAPI
CreateIcon(
1448 HINSTANCE hInstance
, /* [in] the application's hInstance */
1449 INT nWidth
, /* [in] the width of the provided bitmaps */
1450 INT nHeight
, /* [in] the height of the provided bitmaps */
1451 BYTE bPlanes
, /* [in] the number of planes in the provided bitmaps */
1452 BYTE bBitsPixel
, /* [in] the number of bits per pixel of the lpXORbits bitmap */
1453 LPCVOID lpANDbits
, /* [in] a monochrome bitmap representing the icon's mask */
1454 LPCVOID lpXORbits
) /* [in] the icon's 'color' bitmap */
1459 TRACE_(icon
)("%dx%d, planes %d, bpp %d, xor %p, and %p\n",
1460 nWidth
, nHeight
, bPlanes
, bBitsPixel
, lpXORbits
, lpANDbits
);
1463 iinfo
.xHotspot
= ICON_HOTSPOT
;
1464 iinfo
.yHotspot
= ICON_HOTSPOT
;
1465 iinfo
.hbmMask
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpANDbits
);
1466 iinfo
.hbmColor
= CreateBitmap( nWidth
, nHeight
, bPlanes
, bBitsPixel
, lpXORbits
);
1468 hIcon
= CreateIconIndirect( &iinfo
);
1470 DeleteObject( iinfo
.hbmMask
);
1471 DeleteObject( iinfo
.hbmColor
);
1477 /***********************************************************************
1478 * CreateCursorIconIndirect (USER.408)
1480 HGLOBAL16 WINAPI
CreateCursorIconIndirect16( HINSTANCE16 hInstance
,
1481 CURSORICONINFO
*info
,
1487 int sizeAnd
, sizeXor
;
1489 hInstance
= GetExePtr( hInstance
); /* Make it a module handle */
1490 if (!lpXORbits
|| !lpANDbits
|| info
->bPlanes
!= 1) return 0;
1491 info
->nWidthBytes
= get_bitmap_width_bytes(info
->nWidth
,info
->bBitsPerPixel
);
1492 sizeXor
= info
->nHeight
* info
->nWidthBytes
;
1493 sizeAnd
= info
->nHeight
* get_bitmap_width_bytes( info
->nWidth
, 1 );
1494 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
,
1495 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
1497 FarSetOwner16( handle
, hInstance
);
1498 ptr
= GlobalLock16( handle
);
1499 memcpy( ptr
, info
, sizeof(*info
) );
1500 memcpy( ptr
+ sizeof(CURSORICONINFO
), lpANDbits
, sizeAnd
);
1501 memcpy( ptr
+ sizeof(CURSORICONINFO
) + sizeAnd
, lpXORbits
, sizeXor
);
1502 GlobalUnlock16( handle
);
1507 /***********************************************************************
1508 * CopyIcon (USER.368)
1510 HICON16 WINAPI
CopyIcon16( HINSTANCE16 hInstance
, HICON16 hIcon
)
1512 TRACE_(icon
)("%04x %04x\n", hInstance
, hIcon
);
1513 return HICON_16(CURSORICON_Copy(hInstance
, HICON_32(hIcon
)));
1517 /***********************************************************************
1518 * CopyIcon (USER32.@)
1520 HICON WINAPI
CopyIcon( HICON hIcon
)
1522 TRACE_(icon
)("%p\n", hIcon
);
1523 return CURSORICON_Copy( 0, hIcon
);
1527 /***********************************************************************
1528 * CopyCursor (USER.369)
1530 HCURSOR16 WINAPI
CopyCursor16( HINSTANCE16 hInstance
, HCURSOR16 hCursor
)
1532 TRACE_(cursor
)("%04x %04x\n", hInstance
, hCursor
);
1533 return HICON_16(CURSORICON_Copy(hInstance
, HCURSOR_32(hCursor
)));
1536 /**********************************************************************
1537 * DestroyIcon32 (USER.610)
1539 * This routine is actually exported from Win95 USER under the name
1540 * DestroyIcon32 ... The behaviour implemented here should mimic
1541 * the Win95 one exactly, especially the return values, which
1542 * depend on the setting of various flags.
1544 WORD WINAPI
DestroyIcon32( HGLOBAL16 handle
, UINT16 flags
)
1548 TRACE_(icon
)("(%04x, %04x)\n", handle
, flags
);
1550 /* Check whether destroying active cursor */
1552 if ( get_user_thread_info()->cursor
== HICON_32(handle
) )
1554 WARN_(cursor
)("Destroying active cursor!\n" );
1558 /* Try shared cursor/icon first */
1560 if ( !(flags
& CID_NONSHARED
) )
1562 INT count
= CURSORICON_DelSharedIcon(HICON_32(handle
));
1565 return (flags
& CID_WIN32
)? TRUE
: (count
== 0);
1567 /* FIXME: OEM cursors/icons should be recognized */
1570 /* Now assume non-shared cursor/icon */
1572 retv
= GlobalFree16( handle
);
1573 return (flags
& CID_RESOURCE
)? retv
: TRUE
;
1576 /***********************************************************************
1577 * DestroyIcon (USER32.@)
1579 BOOL WINAPI
DestroyIcon( HICON hIcon
)
1581 return DestroyIcon32(HICON_16(hIcon
), CID_WIN32
);
1585 /***********************************************************************
1586 * DestroyCursor (USER32.@)
1588 BOOL WINAPI
DestroyCursor( HCURSOR hCursor
)
1590 return DestroyIcon32(HCURSOR_16(hCursor
), CID_WIN32
);
1594 /***********************************************************************
1595 * DrawIcon (USER32.@)
1597 BOOL WINAPI
DrawIcon( HDC hdc
, INT x
, INT y
, HICON hIcon
)
1599 CURSORICONINFO
*ptr
;
1601 HBITMAP hXorBits
, hAndBits
;
1602 COLORREF oldFg
, oldBg
;
1604 TRACE("%p, (%d,%d), %p\n", hdc
, x
, y
, hIcon
);
1606 if (!(ptr
= GlobalLock16(HICON_16(hIcon
)))) return FALSE
;
1607 if (!(hMemDC
= CreateCompatibleDC( hdc
))) return FALSE
;
1608 hAndBits
= CreateBitmap( ptr
->nWidth
, ptr
->nHeight
, 1, 1,
1610 hXorBits
= CreateBitmap( ptr
->nWidth
, ptr
->nHeight
, ptr
->bPlanes
,
1611 ptr
->bBitsPerPixel
, (char *)(ptr
+ 1)
1612 + ptr
->nHeight
* get_bitmap_width_bytes(ptr
->nWidth
,1) );
1613 oldFg
= SetTextColor( hdc
, RGB(0,0,0) );
1614 oldBg
= SetBkColor( hdc
, RGB(255,255,255) );
1616 if (hXorBits
&& hAndBits
)
1618 HBITMAP hBitTemp
= SelectObject( hMemDC
, hAndBits
);
1619 BitBlt( hdc
, x
, y
, ptr
->nWidth
, ptr
->nHeight
, hMemDC
, 0, 0, SRCAND
);
1620 SelectObject( hMemDC
, hXorBits
);
1621 BitBlt(hdc
, x
, y
, ptr
->nWidth
, ptr
->nHeight
, hMemDC
, 0, 0,SRCINVERT
);
1622 SelectObject( hMemDC
, hBitTemp
);
1625 if (hXorBits
) DeleteObject( hXorBits
);
1626 if (hAndBits
) DeleteObject( hAndBits
);
1627 GlobalUnlock16(HICON_16(hIcon
));
1628 SetTextColor( hdc
, oldFg
);
1629 SetBkColor( hdc
, oldBg
);
1633 /***********************************************************************
1634 * DumpIcon (USER.459)
1636 DWORD WINAPI
DumpIcon16( SEGPTR pInfo
, WORD
*lpLen
,
1637 SEGPTR
*lpXorBits
, SEGPTR
*lpAndBits
)
1639 CURSORICONINFO
*info
= MapSL( pInfo
);
1640 int sizeAnd
, sizeXor
;
1642 if (!info
) return 0;
1643 sizeXor
= info
->nHeight
* info
->nWidthBytes
;
1644 sizeAnd
= info
->nHeight
* get_bitmap_width_bytes( info
->nWidth
, 1 );
1645 if (lpAndBits
) *lpAndBits
= pInfo
+ sizeof(CURSORICONINFO
);
1646 if (lpXorBits
) *lpXorBits
= pInfo
+ sizeof(CURSORICONINFO
) + sizeAnd
;
1647 if (lpLen
) *lpLen
= sizeof(CURSORICONINFO
) + sizeAnd
+ sizeXor
;
1648 return MAKELONG( sizeXor
, sizeXor
);
1652 /***********************************************************************
1653 * SetCursor (USER32.@)
1655 * Set the cursor shape.
1658 * A handle to the previous cursor shape.
1660 HCURSOR WINAPI
SetCursor( HCURSOR hCursor
/* [in] Handle of cursor to show */ )
1662 struct user_thread_info
*thread_info
= get_user_thread_info();
1665 if (hCursor
== thread_info
->cursor
) return hCursor
; /* No change */
1666 TRACE("%p\n", hCursor
);
1667 hOldCursor
= thread_info
->cursor
;
1668 thread_info
->cursor
= hCursor
;
1669 /* Change the cursor shape only if it is visible */
1670 if (thread_info
->cursor_count
>= 0)
1672 USER_Driver
->pSetCursor( (CURSORICONINFO
*)GlobalLock16(HCURSOR_16(hCursor
)) );
1673 GlobalUnlock16(HCURSOR_16(hCursor
));
1678 /***********************************************************************
1679 * ShowCursor (USER32.@)
1681 INT WINAPI
ShowCursor( BOOL bShow
)
1683 struct user_thread_info
*thread_info
= get_user_thread_info();
1685 TRACE("%d, count=%d\n", bShow
, thread_info
->cursor_count
);
1689 if (++thread_info
->cursor_count
== 0) /* Show it */
1691 USER_Driver
->pSetCursor((CURSORICONINFO
*)GlobalLock16(HCURSOR_16(thread_info
->cursor
)));
1692 GlobalUnlock16(HCURSOR_16(thread_info
->cursor
));
1697 if (--thread_info
->cursor_count
== -1) /* Hide it */
1698 USER_Driver
->pSetCursor( NULL
);
1700 return thread_info
->cursor_count
;
1703 /***********************************************************************
1704 * GetCursor (USER32.@)
1706 HCURSOR WINAPI
GetCursor(void)
1708 return get_user_thread_info()->cursor
;
1712 /***********************************************************************
1713 * ClipCursor (USER32.@)
1715 BOOL WINAPI
ClipCursor( const RECT
*rect
)
1719 SetRect( &virt
, 0, 0, GetSystemMetrics( SM_CXVIRTUALSCREEN
),
1720 GetSystemMetrics( SM_CYVIRTUALSCREEN
) );
1721 OffsetRect( &virt
, GetSystemMetrics( SM_XVIRTUALSCREEN
),
1722 GetSystemMetrics( SM_YVIRTUALSCREEN
) );
1724 TRACE( "Clipping to: %s was: %s screen: %s\n", wine_dbgstr_rect(rect
),
1725 wine_dbgstr_rect(&CURSOR_ClipRect
), wine_dbgstr_rect(&virt
) );
1727 if (!IntersectRect( &CURSOR_ClipRect
, &virt
, rect
))
1728 CURSOR_ClipRect
= virt
;
1730 USER_Driver
->pClipCursor( rect
);
1735 /***********************************************************************
1736 * GetClipCursor (USER32.@)
1738 BOOL WINAPI
GetClipCursor( RECT
*rect
)
1740 /* If this is first time - initialize the rect */
1741 if (IsRectEmpty( &CURSOR_ClipRect
)) ClipCursor( NULL
);
1743 return CopyRect( rect
, &CURSOR_ClipRect
);
1747 /***********************************************************************
1748 * SetSystemCursor (USER32.@)
1750 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
1752 FIXME("(%p,%08x),stub!\n", hcur
, id
);
1757 /**********************************************************************
1758 * LookupIconIdFromDirectoryEx (USER.364)
1760 * FIXME: exact parameter sizes
1762 INT16 WINAPI
LookupIconIdFromDirectoryEx16( LPBYTE dir
, BOOL16 bIcon
,
1763 INT16 width
, INT16 height
, UINT16 cFlag
)
1765 return LookupIconIdFromDirectoryEx( dir
, bIcon
, width
, height
, cFlag
);
1768 /**********************************************************************
1769 * LookupIconIdFromDirectoryEx (USER32.@)
1771 INT WINAPI
LookupIconIdFromDirectoryEx( LPBYTE xdir
, BOOL bIcon
,
1772 INT width
, INT height
, UINT cFlag
)
1774 CURSORICONDIR
*dir
= (CURSORICONDIR
*)xdir
;
1776 if( dir
&& !dir
->idReserved
&& (dir
->idType
& 3) )
1778 CURSORICONDIRENTRY
* entry
;
1783 palEnts
= GetSystemPaletteEntries(hdc
, 0, 0, NULL
);
1786 colors
= (cFlag
& LR_MONOCHROME
) ? 2 : palEnts
;
1791 entry
= CURSORICON_FindBestIconRes( dir
, width
, height
, colors
);
1793 entry
= CURSORICON_FindBestCursorRes( dir
, width
, height
, 1);
1795 if( entry
) retVal
= entry
->wResId
;
1797 else WARN_(cursor
)("invalid resource directory\n");
1801 /**********************************************************************
1802 * LookupIconIdFromDirectory (USER.?)
1804 INT16 WINAPI
LookupIconIdFromDirectory16( LPBYTE dir
, BOOL16 bIcon
)
1806 return LookupIconIdFromDirectoryEx16( dir
, bIcon
,
1807 bIcon
? GetSystemMetrics(SM_CXICON
) : GetSystemMetrics(SM_CXCURSOR
),
1808 bIcon
? GetSystemMetrics(SM_CYICON
) : GetSystemMetrics(SM_CYCURSOR
), bIcon
? 0 : LR_MONOCHROME
);
1811 /**********************************************************************
1812 * LookupIconIdFromDirectory (USER32.@)
1814 INT WINAPI
LookupIconIdFromDirectory( LPBYTE dir
, BOOL bIcon
)
1816 return LookupIconIdFromDirectoryEx( dir
, bIcon
,
1817 bIcon
? GetSystemMetrics(SM_CXICON
) : GetSystemMetrics(SM_CXCURSOR
),
1818 bIcon
? GetSystemMetrics(SM_CYICON
) : GetSystemMetrics(SM_CYCURSOR
), bIcon
? 0 : LR_MONOCHROME
);
1821 /**********************************************************************
1822 * GetIconID (USER.455)
1824 WORD WINAPI
GetIconID16( HGLOBAL16 hResource
, DWORD resType
)
1826 LPBYTE lpDir
= GlobalLock16(hResource
);
1828 TRACE_(cursor
)("hRes=%04x, entries=%i\n",
1829 hResource
, lpDir
? ((CURSORICONDIR
*)lpDir
)->idCount
: 0);
1834 return (WORD
)LookupIconIdFromDirectoryEx16( lpDir
, FALSE
,
1835 GetSystemMetrics(SM_CXCURSOR
), GetSystemMetrics(SM_CYCURSOR
), LR_MONOCHROME
);
1837 return (WORD
)LookupIconIdFromDirectoryEx16( lpDir
, TRUE
,
1838 GetSystemMetrics(SM_CXICON
), GetSystemMetrics(SM_CYICON
), 0 );
1840 WARN_(cursor
)("invalid res type %d\n", resType
);
1845 /**********************************************************************
1846 * LoadCursorIconHandler (USER.336)
1848 * Supposed to load resources of Windows 2.x applications.
1850 HGLOBAL16 WINAPI
LoadCursorIconHandler16( HGLOBAL16 hResource
, HMODULE16 hModule
, HRSRC16 hRsrc
)
1852 FIXME_(cursor
)("(%04x,%04x,%04x): old 2.x resources are not supported!\n",
1853 hResource
, hModule
, hRsrc
);
1857 /**********************************************************************
1858 * LoadIconHandler (USER.456)
1860 HICON16 WINAPI
LoadIconHandler16( HGLOBAL16 hResource
, BOOL16 bNew
)
1862 LPBYTE bits
= LockResource16( hResource
);
1864 TRACE_(cursor
)("hRes=%04x\n",hResource
);
1866 return HICON_16(CreateIconFromResourceEx( bits
, 0, TRUE
,
1867 bNew
? 0x00030000 : 0x00020000, 0, 0, LR_DEFAULTCOLOR
));
1870 /***********************************************************************
1871 * LoadCursorW (USER32.@)
1873 HCURSOR WINAPI
LoadCursorW(HINSTANCE hInstance
, LPCWSTR name
)
1875 TRACE("%p, %s\n", hInstance
, debugstr_w(name
));
1877 return LoadImageW( hInstance
, name
, IMAGE_CURSOR
, 0, 0,
1878 LR_SHARED
| LR_DEFAULTSIZE
);
1881 /***********************************************************************
1882 * LoadCursorA (USER32.@)
1884 HCURSOR WINAPI
LoadCursorA(HINSTANCE hInstance
, LPCSTR name
)
1886 TRACE("%p, %s\n", hInstance
, debugstr_a(name
));
1888 return LoadImageA( hInstance
, name
, IMAGE_CURSOR
, 0, 0,
1889 LR_SHARED
| LR_DEFAULTSIZE
);
1892 /***********************************************************************
1893 * LoadCursorFromFileW (USER32.@)
1895 HCURSOR WINAPI
LoadCursorFromFileW (LPCWSTR name
)
1897 TRACE("%s\n", debugstr_w(name
));
1899 return LoadImageW( 0, name
, IMAGE_CURSOR
, 0, 0,
1900 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
1903 /***********************************************************************
1904 * LoadCursorFromFileA (USER32.@)
1906 HCURSOR WINAPI
LoadCursorFromFileA (LPCSTR name
)
1908 TRACE("%s\n", debugstr_a(name
));
1910 return LoadImageA( 0, name
, IMAGE_CURSOR
, 0, 0,
1911 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
1914 /***********************************************************************
1915 * LoadIconW (USER32.@)
1917 HICON WINAPI
LoadIconW(HINSTANCE hInstance
, LPCWSTR name
)
1919 TRACE("%p, %s\n", hInstance
, debugstr_w(name
));
1921 return LoadImageW( hInstance
, name
, IMAGE_ICON
, 0, 0,
1922 LR_SHARED
| LR_DEFAULTSIZE
);
1925 /***********************************************************************
1926 * LoadIconA (USER32.@)
1928 HICON WINAPI
LoadIconA(HINSTANCE hInstance
, LPCSTR name
)
1930 TRACE("%p, %s\n", hInstance
, debugstr_a(name
));
1932 return LoadImageA( hInstance
, name
, IMAGE_ICON
, 0, 0,
1933 LR_SHARED
| LR_DEFAULTSIZE
);
1936 /**********************************************************************
1937 * GetIconInfo (USER32.@)
1939 BOOL WINAPI
GetIconInfo(HICON hIcon
, PICONINFO iconinfo
)
1941 CURSORICONINFO
*ciconinfo
;
1944 ciconinfo
= GlobalLock16(HICON_16(hIcon
));
1948 TRACE("%p => %dx%d, %d bpp\n", hIcon
,
1949 ciconinfo
->nWidth
, ciconinfo
->nHeight
, ciconinfo
->bBitsPerPixel
);
1951 if ( (ciconinfo
->ptHotSpot
.x
== ICON_HOTSPOT
) &&
1952 (ciconinfo
->ptHotSpot
.y
== ICON_HOTSPOT
) )
1954 iconinfo
->fIcon
= TRUE
;
1955 iconinfo
->xHotspot
= ciconinfo
->nWidth
/ 2;
1956 iconinfo
->yHotspot
= ciconinfo
->nHeight
/ 2;
1960 iconinfo
->fIcon
= FALSE
;
1961 iconinfo
->xHotspot
= ciconinfo
->ptHotSpot
.x
;
1962 iconinfo
->yHotspot
= ciconinfo
->ptHotSpot
.y
;
1965 height
= ciconinfo
->nHeight
;
1967 if (ciconinfo
->bBitsPerPixel
> 1)
1969 iconinfo
->hbmColor
= CreateBitmap( ciconinfo
->nWidth
, ciconinfo
->nHeight
,
1970 ciconinfo
->bPlanes
, ciconinfo
->bBitsPerPixel
,
1971 (char *)(ciconinfo
+ 1)
1972 + ciconinfo
->nHeight
*
1973 get_bitmap_width_bytes (ciconinfo
->nWidth
,1) );
1977 iconinfo
->hbmColor
= 0;
1981 iconinfo
->hbmMask
= CreateBitmap ( ciconinfo
->nWidth
, height
,
1982 1, 1, (char *)(ciconinfo
+ 1));
1984 GlobalUnlock16(HICON_16(hIcon
));
1989 /**********************************************************************
1990 * CreateIconIndirect (USER32.@)
1992 HICON WINAPI
CreateIconIndirect(PICONINFO iconinfo
)
1997 int xor_objsize
= 0, sizeXor
= 0, sizeAnd
, planes
, bpp
;
1999 TRACE("color %p, mask %p, hotspot %ux%u, fIcon %d\n",
2000 iconinfo
->hbmColor
, iconinfo
->hbmMask
,
2001 iconinfo
->xHotspot
, iconinfo
->yHotspot
, iconinfo
->fIcon
);
2003 if (!iconinfo
->hbmMask
) return 0;
2005 planes
= GetDeviceCaps( screen_dc
, PLANES
);
2006 bpp
= GetDeviceCaps( screen_dc
, BITSPIXEL
);
2008 if (iconinfo
->hbmColor
)
2010 xor_objsize
= GetObjectW( iconinfo
->hbmColor
, sizeof(bmpXor
), &bmpXor
);
2011 TRACE("color: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
2012 bmpXor
.dsBm
.bmWidth
, bmpXor
.dsBm
.bmHeight
, bmpXor
.dsBm
.bmWidthBytes
,
2013 bmpXor
.dsBm
.bmPlanes
, bmpXor
.dsBm
.bmBitsPixel
);
2014 /* we can use either depth 1 or screen depth for xor bitmap */
2015 if (bmpXor
.dsBm
.bmPlanes
== 1 && bmpXor
.dsBm
.bmBitsPixel
== 1) planes
= bpp
= 1;
2016 sizeXor
= bmpXor
.dsBm
.bmHeight
* planes
* get_bitmap_width_bytes( bmpXor
.dsBm
.bmWidth
, bpp
);
2018 GetObjectW( iconinfo
->hbmMask
, sizeof(bmpAnd
), &bmpAnd
);
2019 TRACE("mask: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
2020 bmpAnd
.bmWidth
, bmpAnd
.bmHeight
, bmpAnd
.bmWidthBytes
,
2021 bmpAnd
.bmPlanes
, bmpAnd
.bmBitsPixel
);
2023 sizeAnd
= bmpAnd
.bmHeight
* get_bitmap_width_bytes(bmpAnd
.bmWidth
, 1);
2025 hObj
= GlobalAlloc16( GMEM_MOVEABLE
,
2026 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
);
2029 CURSORICONINFO
*info
;
2031 info
= GlobalLock16( hObj
);
2033 /* If we are creating an icon, the hotspot is unused */
2034 if (iconinfo
->fIcon
)
2036 info
->ptHotSpot
.x
= ICON_HOTSPOT
;
2037 info
->ptHotSpot
.y
= ICON_HOTSPOT
;
2041 info
->ptHotSpot
.x
= iconinfo
->xHotspot
;
2042 info
->ptHotSpot
.y
= iconinfo
->yHotspot
;
2045 if (iconinfo
->hbmColor
)
2047 info
->nWidth
= bmpXor
.dsBm
.bmWidth
;
2048 info
->nHeight
= bmpXor
.dsBm
.bmHeight
;
2049 info
->nWidthBytes
= bmpXor
.dsBm
.bmWidthBytes
;
2050 info
->bPlanes
= planes
;
2051 info
->bBitsPerPixel
= bpp
;
2055 info
->nWidth
= bmpAnd
.bmWidth
;
2056 info
->nHeight
= bmpAnd
.bmHeight
/ 2;
2057 info
->nWidthBytes
= get_bitmap_width_bytes(bmpAnd
.bmWidth
, 1);
2059 info
->bBitsPerPixel
= 1;
2062 /* Transfer the bitmap bits to the CURSORICONINFO structure */
2064 /* Some apps pass a color bitmap as a mask, convert it to b/w */
2065 if (bmpAnd
.bmBitsPixel
== 1)
2067 GetBitmapBits( iconinfo
->hbmMask
, sizeAnd
, (char*)(info
+ 1) );
2072 HBITMAP hbmp_old
, hbmp_mem_old
, hbmp_mono
;
2075 hdc_mem
= CreateCompatibleDC( hdc
);
2077 hbmp_mono
= CreateBitmap( bmpAnd
.bmWidth
, bmpAnd
.bmHeight
, 1, 1, NULL
);
2079 hbmp_old
= SelectObject( hdc
, iconinfo
->hbmMask
);
2080 hbmp_mem_old
= SelectObject( hdc_mem
, hbmp_mono
);
2082 BitBlt( hdc_mem
, 0, 0, bmpAnd
.bmWidth
, bmpAnd
.bmHeight
, hdc
, 0, 0, SRCCOPY
);
2084 SelectObject( hdc
, hbmp_old
);
2085 SelectObject( hdc_mem
, hbmp_mem_old
);
2087 DeleteDC( hdc_mem
);
2088 ReleaseDC( 0, hdc
);
2090 GetBitmapBits( hbmp_mono
, sizeAnd
, (char*)(info
+ 1) );
2091 DeleteObject( hbmp_mono
);
2094 if (iconinfo
->hbmColor
)
2096 char *dst_bits
= (char*)(info
+ 1) + sizeAnd
;
2098 if (bmpXor
.dsBm
.bmPlanes
== planes
&& bmpXor
.dsBm
.bmBitsPixel
== bpp
)
2099 GetBitmapBits( iconinfo
->hbmColor
, sizeXor
, dst_bits
);
2103 int dib_width
= get_dib_width_bytes( info
->nWidth
, info
->bBitsPerPixel
);
2104 int bitmap_width
= get_bitmap_width_bytes( info
->nWidth
, info
->bBitsPerPixel
);
2106 bminfo
.bmiHeader
.biSize
= sizeof(bminfo
);
2107 bminfo
.bmiHeader
.biWidth
= info
->nWidth
;
2108 bminfo
.bmiHeader
.biHeight
= info
->nHeight
;
2109 bminfo
.bmiHeader
.biPlanes
= info
->bPlanes
;
2110 bminfo
.bmiHeader
.biBitCount
= info
->bBitsPerPixel
;
2111 bminfo
.bmiHeader
.biCompression
= BI_RGB
;
2112 bminfo
.bmiHeader
.biSizeImage
= info
->nHeight
* dib_width
;
2113 bminfo
.bmiHeader
.biXPelsPerMeter
= 0;
2114 bminfo
.bmiHeader
.biYPelsPerMeter
= 0;
2115 bminfo
.bmiHeader
.biClrUsed
= 0;
2116 bminfo
.bmiHeader
.biClrImportant
= 0;
2118 /* swap lines for dib sections */
2119 if (xor_objsize
== sizeof(DIBSECTION
))
2120 bminfo
.bmiHeader
.biHeight
= -bminfo
.bmiHeader
.biHeight
;
2122 if (dib_width
!= bitmap_width
) /* need to fixup alignment */
2124 char *src_bits
= HeapAlloc( GetProcessHeap(), 0, bminfo
.bmiHeader
.biSizeImage
);
2126 if (src_bits
&& GetDIBits( screen_dc
, iconinfo
->hbmColor
, 0, info
->nHeight
,
2127 src_bits
, &bminfo
, DIB_RGB_COLORS
))
2130 for (y
= 0; y
< info
->nHeight
; y
++)
2131 memcpy( dst_bits
+ y
* bitmap_width
, src_bits
+ y
* dib_width
, bitmap_width
);
2133 HeapFree( GetProcessHeap(), 0, src_bits
);
2136 GetDIBits( screen_dc
, iconinfo
->hbmColor
, 0, info
->nHeight
,
2137 dst_bits
, &bminfo
, DIB_RGB_COLORS
);
2140 GlobalUnlock16( hObj
);
2142 return HICON_32(hObj
);
2145 /******************************************************************************
2146 * DrawIconEx (USER32.@) Draws an icon or cursor on device context
2149 * Why is this using SM_CXICON instead of SM_CXCURSOR?
2152 * hdc [I] Handle to device context
2153 * x0 [I] X coordinate of upper left corner
2154 * y0 [I] Y coordinate of upper left corner
2155 * hIcon [I] Handle to icon to draw
2156 * cxWidth [I] Width of icon
2157 * cyWidth [I] Height of icon
2158 * istep [I] Index of frame in animated cursor
2159 * hbr [I] Handle to background brush
2160 * flags [I] Icon-drawing flags
2166 BOOL WINAPI
DrawIconEx( HDC hdc
, INT x0
, INT y0
, HICON hIcon
,
2167 INT cxWidth
, INT cyWidth
, UINT istep
,
2168 HBRUSH hbr
, UINT flags
)
2170 CURSORICONINFO
*ptr
= GlobalLock16(HICON_16(hIcon
));
2171 HDC hDC_off
= 0, hMemDC
;
2172 BOOL result
= FALSE
, DoOffscreen
;
2173 HBITMAP hB_off
= 0, hOld
= 0;
2175 if (!ptr
) return FALSE
;
2176 TRACE_(icon
)("(hdc=%p,pos=%d.%d,hicon=%p,extend=%d.%d,istep=%d,br=%p,flags=0x%08x)\n",
2177 hdc
,x0
,y0
,hIcon
,cxWidth
,cyWidth
,istep
,hbr
,flags
);
2179 hMemDC
= CreateCompatibleDC (hdc
);
2181 FIXME_(icon
)("Ignoring istep=%d\n", istep
);
2182 if (flags
& DI_NOMIRROR
)
2183 FIXME_(icon
)("Ignoring flag DI_NOMIRROR\n");
2186 FIXME_(icon
)("no flags set? setting to DI_NORMAL\n");
2190 /* Calculate the size of the destination image. */
2193 if (flags
& DI_DEFAULTSIZE
)
2194 cxWidth
= GetSystemMetrics (SM_CXICON
);
2196 cxWidth
= ptr
->nWidth
;
2200 if (flags
& DI_DEFAULTSIZE
)
2201 cyWidth
= GetSystemMetrics (SM_CYICON
);
2203 cyWidth
= ptr
->nHeight
;
2206 DoOffscreen
= (GetObjectType( hbr
) == OBJ_BRUSH
);
2216 hDC_off
= CreateCompatibleDC(hdc
);
2217 hB_off
= CreateCompatibleBitmap(hdc
, cxWidth
, cyWidth
);
2218 if (hDC_off
&& hB_off
) {
2219 hOld
= SelectObject(hDC_off
, hB_off
);
2220 FillRect(hDC_off
, &r
, hbr
);
2224 if (hMemDC
&& (!DoOffscreen
|| (hDC_off
&& hB_off
)))
2226 HBITMAP hXorBits
, hAndBits
;
2227 COLORREF oldFg
, oldBg
;
2230 nStretchMode
= SetStretchBltMode (hdc
, STRETCH_DELETESCANS
);
2232 hXorBits
= CreateBitmap ( ptr
->nWidth
, ptr
->nHeight
,
2233 ptr
->bPlanes
, ptr
->bBitsPerPixel
,
2236 get_bitmap_width_bytes(ptr
->nWidth
,1) );
2237 hAndBits
= CreateBitmap ( ptr
->nWidth
, ptr
->nHeight
,
2238 1, 1, (char *)(ptr
+1) );
2239 oldFg
= SetTextColor( hdc
, RGB(0,0,0) );
2240 oldBg
= SetBkColor( hdc
, RGB(255,255,255) );
2242 if (hXorBits
&& hAndBits
)
2244 HBITMAP hBitTemp
= SelectObject( hMemDC
, hAndBits
);
2245 if (flags
& DI_MASK
)
2248 StretchBlt (hDC_off
, 0, 0, cxWidth
, cyWidth
,
2249 hMemDC
, 0, 0, ptr
->nWidth
, ptr
->nHeight
, SRCAND
);
2251 StretchBlt (hdc
, x0
, y0
, cxWidth
, cyWidth
,
2252 hMemDC
, 0, 0, ptr
->nWidth
, ptr
->nHeight
, SRCAND
);
2254 SelectObject( hMemDC
, hXorBits
);
2255 if (flags
& DI_IMAGE
)
2258 StretchBlt (hDC_off
, 0, 0, cxWidth
, cyWidth
,
2259 hMemDC
, 0, 0, ptr
->nWidth
, ptr
->nHeight
, SRCPAINT
);
2261 StretchBlt (hdc
, x0
, y0
, cxWidth
, cyWidth
,
2262 hMemDC
, 0, 0, ptr
->nWidth
, ptr
->nHeight
, SRCPAINT
);
2264 SelectObject( hMemDC
, hBitTemp
);
2268 SetTextColor( hdc
, oldFg
);
2269 SetBkColor( hdc
, oldBg
);
2270 if (hXorBits
) DeleteObject( hXorBits
);
2271 if (hAndBits
) DeleteObject( hAndBits
);
2272 SetStretchBltMode (hdc
, nStretchMode
);
2274 BitBlt(hdc
, x0
, y0
, cxWidth
, cyWidth
, hDC_off
, 0, 0, SRCCOPY
);
2275 SelectObject(hDC_off
, hOld
);
2278 if (hMemDC
) DeleteDC( hMemDC
);
2279 if (hDC_off
) DeleteDC(hDC_off
);
2280 if (hB_off
) DeleteObject(hB_off
);
2281 GlobalUnlock16(HICON_16(hIcon
));
2285 /***********************************************************************
2286 * DIB_FixColorsToLoadflags
2288 * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
2291 static void DIB_FixColorsToLoadflags(BITMAPINFO
* bmi
, UINT loadflags
, BYTE pix
)
2294 COLORREF c_W
, c_S
, c_F
, c_L
, c_C
;
2303 if (((bitmap_type
= DIB_GetBitmapInfo((BITMAPINFOHEADER
*) bmi
, &width
, &height
, &bpp
, &compr
)) == -1))
2305 WARN_(resource
)("Invalid bitmap\n");
2309 if (bpp
> 8) return;
2311 if (bitmap_type
== 0) /* BITMAPCOREHEADER */
2319 colors
= bmi
->bmiHeader
.biClrUsed
;
2320 if (colors
> 256) colors
= 256;
2321 if (!colors
&& (bpp
<= 8)) colors
= 1 << bpp
;
2324 c_W
= GetSysColor(COLOR_WINDOW
);
2325 c_S
= GetSysColor(COLOR_3DSHADOW
);
2326 c_F
= GetSysColor(COLOR_3DFACE
);
2327 c_L
= GetSysColor(COLOR_3DLIGHT
);
2329 if (loadflags
& LR_LOADTRANSPARENT
) {
2331 case 1: pix
= pix
>> 7; break;
2332 case 4: pix
= pix
>> 4; break;
2335 WARN_(resource
)("(%d): Unsupported depth\n", bpp
);
2338 if (pix
>= colors
) {
2339 WARN_(resource
)("pixel has color index greater than biClrUsed!\n");
2342 if (loadflags
& LR_LOADMAP3DCOLORS
) c_W
= c_F
;
2343 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+pix
*incr
);
2344 ptr
->rgbBlue
= GetBValue(c_W
);
2345 ptr
->rgbGreen
= GetGValue(c_W
);
2346 ptr
->rgbRed
= GetRValue(c_W
);
2348 if (loadflags
& LR_LOADMAP3DCOLORS
)
2349 for (i
=0; i
<colors
; i
++) {
2350 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+i
*incr
);
2351 c_C
= RGB(ptr
->rgbRed
, ptr
->rgbGreen
, ptr
->rgbBlue
);
2352 if (c_C
== RGB(128, 128, 128)) {
2353 ptr
->rgbRed
= GetRValue(c_S
);
2354 ptr
->rgbGreen
= GetGValue(c_S
);
2355 ptr
->rgbBlue
= GetBValue(c_S
);
2356 } else if (c_C
== RGB(192, 192, 192)) {
2357 ptr
->rgbRed
= GetRValue(c_F
);
2358 ptr
->rgbGreen
= GetGValue(c_F
);
2359 ptr
->rgbBlue
= GetBValue(c_F
);
2360 } else if (c_C
== RGB(223, 223, 223)) {
2361 ptr
->rgbRed
= GetRValue(c_L
);
2362 ptr
->rgbGreen
= GetGValue(c_L
);
2363 ptr
->rgbBlue
= GetBValue(c_L
);
2369 /**********************************************************************
2372 static HBITMAP
BITMAP_Load( HINSTANCE instance
, LPCWSTR name
,
2373 INT desiredx
, INT desiredy
, UINT loadflags
)
2375 HBITMAP hbitmap
= 0, orig_bm
;
2379 BITMAPINFO
*info
, *fix_info
= NULL
, *scaled_info
= NULL
;
2383 LONG width
, height
, new_width
, new_height
;
2387 HDC screen_mem_dc
= NULL
;
2389 if (!(loadflags
& LR_LOADFROMFILE
))
2393 /* OEM bitmap: try to load the resource from user32.dll */
2394 instance
= user32_module
;
2397 if (!(hRsrc
= FindResourceW( instance
, name
, (LPWSTR
)RT_BITMAP
))) return 0;
2398 if (!(handle
= LoadResource( instance
, hRsrc
))) return 0;
2400 if ((info
= LockResource( handle
)) == NULL
) return 0;
2404 BITMAPFILEHEADER
* bmfh
;
2406 if (!(ptr
= map_fileW( name
, NULL
))) return 0;
2407 info
= (BITMAPINFO
*)(ptr
+ sizeof(BITMAPFILEHEADER
));
2408 bmfh
= (BITMAPFILEHEADER
*)ptr
;
2409 if (!( bmfh
->bfType
== 0x4d42 /* 'BM' */ &&
2410 bmfh
->bfReserved1
== 0 &&
2411 bmfh
->bfReserved2
== 0))
2413 WARN("Invalid/unsupported bitmap format!\n");
2414 UnmapViewOfFile( ptr
);
2419 size
= bitmap_info_size(info
, DIB_RGB_COLORS
);
2420 fix_info
= HeapAlloc(GetProcessHeap(), 0, size
);
2421 scaled_info
= HeapAlloc(GetProcessHeap(), 0, size
);
2423 if (!fix_info
|| !scaled_info
) goto end
;
2424 memcpy(fix_info
, info
, size
);
2426 pix
= *((LPBYTE
)info
+ size
);
2427 DIB_FixColorsToLoadflags(fix_info
, loadflags
, pix
);
2429 memcpy(scaled_info
, fix_info
, size
);
2430 bm_type
= DIB_GetBitmapInfo( &fix_info
->bmiHeader
, &width
, &height
,
2431 &bpp_dummy
, &compr_dummy
);
2433 new_width
= desiredx
;
2438 new_height
= height
> 0 ? desiredy
: -desiredy
;
2440 new_height
= height
;
2444 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)&scaled_info
->bmiHeader
;
2445 core
->bcWidth
= new_width
;
2446 core
->bcHeight
= new_height
;
2450 scaled_info
->bmiHeader
.biWidth
= new_width
;
2451 scaled_info
->bmiHeader
.biHeight
= new_height
;
2454 if (new_height
< 0) new_height
= -new_height
;
2456 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
2457 if (!(screen_mem_dc
= CreateCompatibleDC( screen_dc
))) goto end
;
2459 bits
= (char *)info
+ size
;
2461 if (loadflags
& LR_CREATEDIBSECTION
)
2463 scaled_info
->bmiHeader
.biCompression
= 0; /* DIBSection can't be compressed */
2464 hbitmap
= CreateDIBSection(screen_dc
, scaled_info
, DIB_RGB_COLORS
, NULL
, 0, 0);
2468 if (is_dib_monochrome(fix_info
))
2469 hbitmap
= CreateBitmap(new_width
, new_height
, 1, 1, NULL
);
2471 hbitmap
= CreateCompatibleBitmap(screen_dc
, new_width
, new_height
);
2474 orig_bm
= SelectObject(screen_mem_dc
, hbitmap
);
2475 StretchDIBits(screen_mem_dc
, 0, 0, new_width
, new_height
, 0, 0, width
, height
, bits
, fix_info
, DIB_RGB_COLORS
, SRCCOPY
);
2476 SelectObject(screen_mem_dc
, orig_bm
);
2479 if (screen_mem_dc
) DeleteDC(screen_mem_dc
);
2480 HeapFree(GetProcessHeap(), 0, scaled_info
);
2481 HeapFree(GetProcessHeap(), 0, fix_info
);
2482 if (loadflags
& LR_LOADFROMFILE
) UnmapViewOfFile( ptr
);
2487 /**********************************************************************
2488 * LoadImageA (USER32.@)
2492 HANDLE WINAPI
LoadImageA( HINSTANCE hinst
, LPCSTR name
, UINT type
,
2493 INT desiredx
, INT desiredy
, UINT loadflags
)
2499 return LoadImageW(hinst
, (LPCWSTR
)name
, type
, desiredx
, desiredy
, loadflags
);
2502 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
2503 u_name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2504 MultiByteToWideChar( CP_ACP
, 0, name
, -1, u_name
, len
);
2506 __EXCEPT_PAGE_FAULT
{
2507 SetLastError( ERROR_INVALID_PARAMETER
);
2511 res
= LoadImageW(hinst
, u_name
, type
, desiredx
, desiredy
, loadflags
);
2512 HeapFree(GetProcessHeap(), 0, u_name
);
2517 /******************************************************************************
2518 * LoadImageW (USER32.@) Loads an icon, cursor, or bitmap
2521 * hinst [I] Handle of instance that contains image
2522 * name [I] Name of image
2523 * type [I] Type of image
2524 * desiredx [I] Desired width
2525 * desiredy [I] Desired height
2526 * loadflags [I] Load flags
2529 * Success: Handle to newly loaded image
2532 * FIXME: Implementation lacks some features, see LR_ defines in winuser.h
2534 HANDLE WINAPI
LoadImageW( HINSTANCE hinst
, LPCWSTR name
, UINT type
,
2535 INT desiredx
, INT desiredy
, UINT loadflags
)
2537 TRACE_(resource
)("(%p,%s,%d,%d,%d,0x%08x)\n",
2538 hinst
,debugstr_w(name
),type
,desiredx
,desiredy
,loadflags
);
2540 if (loadflags
& LR_DEFAULTSIZE
) {
2541 if (type
== IMAGE_ICON
) {
2542 if (!desiredx
) desiredx
= GetSystemMetrics(SM_CXICON
);
2543 if (!desiredy
) desiredy
= GetSystemMetrics(SM_CYICON
);
2544 } else if (type
== IMAGE_CURSOR
) {
2545 if (!desiredx
) desiredx
= GetSystemMetrics(SM_CXCURSOR
);
2546 if (!desiredy
) desiredy
= GetSystemMetrics(SM_CYCURSOR
);
2549 if (loadflags
& LR_LOADFROMFILE
) loadflags
&= ~LR_SHARED
;
2552 return BITMAP_Load( hinst
, name
, desiredx
, desiredy
, loadflags
);
2555 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
2558 UINT palEnts
= GetSystemPaletteEntries(screen_dc
, 0, 0, NULL
);
2559 if (palEnts
== 0) palEnts
= 256;
2560 return CURSORICON_Load(hinst
, name
, desiredx
, desiredy
,
2561 palEnts
, FALSE
, loadflags
);
2566 return CURSORICON_Load(hinst
, name
, desiredx
, desiredy
,
2567 1, TRUE
, loadflags
);
2572 /******************************************************************************
2573 * CopyImage (USER32.@) Creates new image and copies attributes to it
2576 * hnd [I] Handle to image to copy
2577 * type [I] Type of image to copy
2578 * desiredx [I] Desired width of new image
2579 * desiredy [I] Desired height of new image
2580 * flags [I] Copy flags
2583 * Success: Handle to newly created image
2587 * Only Windows NT 4.0 supports the LR_COPYRETURNORG flag for bitmaps,
2588 * all other versions (95/2000/XP have been tested) ignore it.
2591 * If LR_CREATEDIBSECTION is absent, the copy will be monochrome for
2592 * a monochrome source bitmap or if LR_MONOCHROME is present, otherwise
2593 * the copy will have the same depth as the screen.
2594 * The content of the image will only be copied if the bit depth of the
2595 * original image is compatible with the bit depth of the screen, or
2596 * if the source is a DIB section.
2597 * The LR_MONOCHROME flag is ignored if LR_CREATEDIBSECTION is present.
2599 HANDLE WINAPI
CopyImage( HANDLE hnd
, UINT type
, INT desiredx
,
2600 INT desiredy
, UINT flags
)
2602 TRACE("hnd=%p, type=%u, desiredx=%d, desiredy=%d, flags=%x\n",
2603 hnd
, type
, desiredx
, desiredy
, flags
);
2614 objSize
= GetObjectW( hnd
, sizeof(ds
), &ds
);
2615 if (!objSize
) return 0;
2616 if ((desiredx
< 0) || (desiredy
< 0)) return 0;
2618 if (flags
& LR_COPYFROMRESOURCE
)
2620 FIXME("The flag LR_COPYFROMRESOURCE is not implemented for bitmaps\n");
2623 if (desiredx
== 0) desiredx
= ds
.dsBm
.bmWidth
;
2624 if (desiredy
== 0) desiredy
= ds
.dsBm
.bmHeight
;
2626 /* Allocate memory for a BITMAPINFOHEADER structure and a
2627 color table. The maximum number of colors in a color table
2628 is 256 which corresponds to a bitmap with depth 8.
2629 Bitmaps with higher depths don't have color tables. */
2630 bi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
2633 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
2634 bi
->bmiHeader
.biPlanes
= ds
.dsBm
.bmPlanes
;
2635 bi
->bmiHeader
.biBitCount
= ds
.dsBm
.bmBitsPixel
;
2636 bi
->bmiHeader
.biCompression
= BI_RGB
;
2638 if (flags
& LR_CREATEDIBSECTION
)
2640 /* Create a DIB section. LR_MONOCHROME is ignored */
2642 HDC dc
= CreateCompatibleDC(NULL
);
2644 if (objSize
== sizeof(DIBSECTION
))
2646 /* The source bitmap is a DIB.
2647 Get its attributes to create an exact copy */
2648 memcpy(bi
, &ds
.dsBmih
, sizeof(BITMAPINFOHEADER
));
2651 /* Get the color table or the color masks */
2652 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2654 bi
->bmiHeader
.biWidth
= desiredx
;
2655 bi
->bmiHeader
.biHeight
= desiredy
;
2656 bi
->bmiHeader
.biSizeImage
= 0;
2658 res
= CreateDIBSection(dc
, bi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2663 /* Create a device-dependent bitmap */
2665 BOOL monochrome
= (flags
& LR_MONOCHROME
);
2667 if (objSize
== sizeof(DIBSECTION
))
2669 /* The source bitmap is a DIB section.
2670 Get its attributes */
2671 HDC dc
= CreateCompatibleDC(NULL
);
2672 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
2673 bi
->bmiHeader
.biBitCount
= ds
.dsBm
.bmBitsPixel
;
2674 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2677 if (!monochrome
&& ds
.dsBm
.bmBitsPixel
== 1)
2679 /* Look if the colors of the DIB are black and white */
2682 (bi
->bmiColors
[0].rgbRed
== 0xff
2683 && bi
->bmiColors
[0].rgbGreen
== 0xff
2684 && bi
->bmiColors
[0].rgbBlue
== 0xff
2685 && bi
->bmiColors
[0].rgbReserved
== 0
2686 && bi
->bmiColors
[1].rgbRed
== 0
2687 && bi
->bmiColors
[1].rgbGreen
== 0
2688 && bi
->bmiColors
[1].rgbBlue
== 0
2689 && bi
->bmiColors
[1].rgbReserved
== 0)
2691 (bi
->bmiColors
[0].rgbRed
== 0
2692 && bi
->bmiColors
[0].rgbGreen
== 0
2693 && bi
->bmiColors
[0].rgbBlue
== 0
2694 && bi
->bmiColors
[0].rgbReserved
== 0
2695 && bi
->bmiColors
[1].rgbRed
== 0xff
2696 && bi
->bmiColors
[1].rgbGreen
== 0xff
2697 && bi
->bmiColors
[1].rgbBlue
== 0xff
2698 && bi
->bmiColors
[1].rgbReserved
== 0);
2701 else if (!monochrome
)
2703 monochrome
= ds
.dsBm
.bmBitsPixel
== 1;
2708 res
= CreateBitmap(desiredx
, desiredy
, 1, 1, NULL
);
2712 HDC screenDC
= GetDC(NULL
);
2713 res
= CreateCompatibleBitmap(screenDC
, desiredx
, desiredy
);
2714 ReleaseDC(NULL
, screenDC
);
2720 /* Only copy the bitmap if it's a DIB section or if it's
2721 compatible to the screen */
2724 if (objSize
== sizeof(DIBSECTION
))
2726 copyContents
= TRUE
;
2730 HDC screenDC
= GetDC(NULL
);
2731 int screen_depth
= GetDeviceCaps(screenDC
, BITSPIXEL
);
2732 ReleaseDC(NULL
, screenDC
);
2734 copyContents
= (ds
.dsBm
.bmBitsPixel
== 1 || ds
.dsBm
.bmBitsPixel
== screen_depth
);
2739 /* The source bitmap may already be selected in a device context,
2740 use GetDIBits/StretchDIBits and not StretchBlt */
2745 dc
= CreateCompatibleDC(NULL
);
2747 bi
->bmiHeader
.biWidth
= ds
.dsBm
.bmWidth
;
2748 bi
->bmiHeader
.biHeight
= ds
.dsBm
.bmHeight
;
2749 bi
->bmiHeader
.biSizeImage
= 0;
2750 bi
->bmiHeader
.biClrUsed
= 0;
2751 bi
->bmiHeader
.biClrImportant
= 0;
2753 /* Fill in biSizeImage */
2754 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2755 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, bi
->bmiHeader
.biSizeImage
);
2761 /* Get the image bits of the source bitmap */
2762 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, bits
, bi
, DIB_RGB_COLORS
);
2764 /* Copy it to the destination bitmap */
2765 oldBmp
= SelectObject(dc
, res
);
2766 StretchDIBits(dc
, 0, 0, desiredx
, desiredy
,
2767 0, 0, ds
.dsBm
.bmWidth
, ds
.dsBm
.bmHeight
,
2768 bits
, bi
, DIB_RGB_COLORS
, SRCCOPY
);
2769 SelectObject(dc
, oldBmp
);
2771 HeapFree(GetProcessHeap(), 0, bits
);
2777 if (flags
& LR_COPYDELETEORG
)
2782 HeapFree(GetProcessHeap(), 0, bi
);
2786 return CURSORICON_ExtCopy(hnd
,type
, desiredx
, desiredy
, flags
);
2788 /* Should call CURSORICON_ExtCopy but more testing
2789 * needs to be done before we change this
2791 if (flags
) FIXME("Flags are ignored\n");
2792 return CopyCursor(hnd
);
2798 /******************************************************************************
2799 * LoadBitmapW (USER32.@) Loads bitmap from the executable file
2802 * Success: Handle to specified bitmap
2805 HBITMAP WINAPI
LoadBitmapW(
2806 HINSTANCE instance
, /* [in] Handle to application instance */
2807 LPCWSTR name
) /* [in] Address of bitmap resource name */
2809 return LoadImageW( instance
, name
, IMAGE_BITMAP
, 0, 0, 0 );
2812 /**********************************************************************
2813 * LoadBitmapA (USER32.@)
2817 HBITMAP WINAPI
LoadBitmapA( HINSTANCE instance
, LPCSTR name
)
2819 return LoadImageA( instance
, name
, IMAGE_BITMAP
, 0, 0, 0 );