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
26 #include "wine/port.h"
38 #include "wine/exception.h"
39 #include "wine/server.h"
42 #include "user_private.h"
43 #include "wine/list.h"
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(cursor
);
48 WINE_DECLARE_DEBUG_CHANNEL(icon
);
49 WINE_DECLARE_DEBUG_CHANNEL(resource
);
62 } CURSORICONFILEDIRENTRY
;
69 CURSORICONFILEDIRENTRY idEntries
[1];
76 static const WCHAR DISPLAYW
[] = {'D','I','S','P','L','A','Y',0};
78 static struct list icon_cache
= LIST_INIT( icon_cache
);
80 /**********************************************************************
81 * User objects management
84 struct cursoricon_frame
86 UINT width
; /* frame-specific width */
87 UINT height
; /* frame-specific height */
88 UINT delay
; /* frame-specific delay between this frame and the next (in jiffies) */
89 HBITMAP color
; /* color bitmap */
90 HBITMAP alpha
; /* pre-multiplied alpha bitmap for 32-bpp icons */
91 HBITMAP mask
; /* mask bitmap (followed by color for 1-bpp icons) */
94 struct cursoricon_object
96 struct user_object obj
; /* object header */
97 struct list entry
; /* entry in shared icons list */
98 ULONG_PTR param
; /* opaque param used by 16-bit code */
99 HMODULE module
; /* module for icons loaded from resources */
100 LPWSTR resname
; /* resource name for icons loaded from resources */
101 HRSRC rsrc
; /* resource for shared icons */
102 BOOL is_icon
; /* whether icon or cursor */
103 BOOL is_ani
; /* whether this object is a static cursor or an animated cursor */
104 UINT delay
; /* delay between this frame and the next (in jiffies) */
108 struct static_cursoricon_object
110 struct cursoricon_object shared
;
111 struct cursoricon_frame frame
; /* frame-specific icon data */
114 struct animated_cursoricon_object
116 struct cursoricon_object shared
;
117 UINT num_frames
; /* number of frames in the icon/cursor */
118 UINT num_steps
; /* number of sequence steps in the icon/cursor */
119 HICON frames
[1]; /* list of animated cursor frames */
122 static HICON
alloc_icon_handle( BOOL is_ani
, UINT num_frames
)
124 struct cursoricon_object
*obj
;
128 icon_size
= FIELD_OFFSET( struct animated_cursoricon_object
, frames
[num_frames
] );
130 icon_size
= sizeof( struct static_cursoricon_object
);
131 obj
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, icon_size
);
134 obj
->is_ani
= is_ani
;
137 struct animated_cursoricon_object
*ani_icon_data
= (struct animated_cursoricon_object
*) obj
;
139 ani_icon_data
->num_steps
= num_frames
; /* changed later for some animated cursors */
140 ani_icon_data
->num_frames
= num_frames
;
142 return alloc_user_handle( &obj
->obj
, USER_ICON
);
145 static struct cursoricon_object
*get_icon_ptr( HICON handle
)
147 struct cursoricon_object
*obj
= get_user_handle_ptr( handle
, USER_ICON
);
148 if (obj
== OBJ_OTHER_PROCESS
)
150 WARN( "icon handle %p from other process\n", handle
);
156 static void release_icon_ptr( HICON handle
, struct cursoricon_object
*ptr
)
158 release_user_handle_ptr( ptr
);
161 static struct cursoricon_frame
*get_icon_frame( struct cursoricon_object
*obj
, int istep
)
163 struct static_cursoricon_object
*req_frame
;
167 struct animated_cursoricon_object
*ani_icon_data
;
168 struct cursoricon_object
*frameobj
;
170 ani_icon_data
= (struct animated_cursoricon_object
*) obj
;
171 if (!(frameobj
= get_icon_ptr( ani_icon_data
->frames
[istep
] )))
173 req_frame
= (struct static_cursoricon_object
*) frameobj
;
176 req_frame
= (struct static_cursoricon_object
*) obj
;
178 return &req_frame
->frame
;
181 static void release_icon_frame( struct cursoricon_object
*obj
, int istep
, struct cursoricon_frame
*frame
)
185 struct animated_cursoricon_object
*ani_icon_data
;
186 struct cursoricon_object
*frameobj
;
188 ani_icon_data
= (struct animated_cursoricon_object
*) obj
;
189 frameobj
= (struct cursoricon_object
*) (((char *)frame
) - FIELD_OFFSET(struct static_cursoricon_object
, frame
));
190 release_icon_ptr( ani_icon_data
->frames
[istep
], frameobj
);
194 static UINT
get_icon_steps( struct cursoricon_object
*obj
)
198 struct animated_cursoricon_object
*ani_icon_data
;
200 ani_icon_data
= (struct animated_cursoricon_object
*) obj
;
201 return ani_icon_data
->num_steps
;
206 static BOOL
free_icon_handle( HICON handle
)
208 struct cursoricon_object
*obj
= free_user_handle( handle
, USER_ICON
);
210 if (obj
== OBJ_OTHER_PROCESS
) WARN( "icon handle %p from other process\n", handle
);
213 ULONG_PTR param
= obj
->param
;
216 assert( !obj
->rsrc
); /* shared icons can't be freed */
220 struct cursoricon_frame
*frame
= get_icon_frame( obj
, 0 );
222 if (frame
->alpha
) DeleteObject( frame
->alpha
);
223 if (frame
->color
) DeleteObject( frame
->color
);
224 DeleteObject( frame
->mask
);
225 release_icon_frame( obj
, 0, frame
);
229 struct animated_cursoricon_object
*ani_icon_data
= (struct animated_cursoricon_object
*) obj
;
231 for (i
=0; i
<ani_icon_data
->num_frames
; i
++)
232 free_icon_handle( ani_icon_data
->frames
[i
] );
234 if (!IS_INTRESOURCE( obj
->resname
)) HeapFree( GetProcessHeap(), 0, obj
->resname
);
235 HeapFree( GetProcessHeap(), 0, obj
);
236 if (wow_handlers
.free_icon_param
&& param
) wow_handlers
.free_icon_param( param
);
237 USER_Driver
->pDestroyCursorIcon( handle
);
243 ULONG_PTR
get_icon_param( HICON handle
)
246 struct cursoricon_object
*obj
= get_user_handle_ptr( handle
, USER_ICON
);
248 if (obj
== OBJ_OTHER_PROCESS
) WARN( "icon handle %p from other process\n", handle
);
252 release_user_handle_ptr( obj
);
257 ULONG_PTR
set_icon_param( HICON handle
, ULONG_PTR param
)
260 struct cursoricon_object
*obj
= get_user_handle_ptr( handle
, USER_ICON
);
262 if (obj
== OBJ_OTHER_PROCESS
) WARN( "icon handle %p from other process\n", handle
);
267 release_user_handle_ptr( obj
);
273 /***********************************************************************
276 * Helper function to map a file to memory:
278 * [RETURN] ptr - pointer to mapped file
279 * [RETURN] filesize - pointer size of file to be stored if not NULL
281 static void *map_fileW( LPCWSTR name
, LPDWORD filesize
)
283 HANDLE hFile
, hMapping
;
286 hFile
= CreateFileW( name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
287 OPEN_EXISTING
, FILE_FLAG_RANDOM_ACCESS
, 0 );
288 if (hFile
!= INVALID_HANDLE_VALUE
)
290 hMapping
= CreateFileMappingW( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
293 ptr
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
294 CloseHandle( hMapping
);
296 *filesize
= GetFileSize( hFile
, NULL
);
298 CloseHandle( hFile
);
304 /***********************************************************************
305 * get_dib_width_bytes
307 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
309 static int get_dib_width_bytes( int width
, int depth
)
315 case 1: words
= (width
+ 31) / 32; break;
316 case 4: words
= (width
+ 7) / 8; break;
317 case 8: words
= (width
+ 3) / 4; break;
319 case 16: words
= (width
+ 1) / 2; break;
320 case 24: words
= (width
* 3 + 3)/4; break;
322 WARN("(%d): Unsupported depth\n", depth
);
331 /***********************************************************************
334 * Return the size of the bitmap info structure including color table.
336 static int bitmap_info_size( const BITMAPINFO
* info
, WORD coloruse
)
338 unsigned int colors
, size
, masks
= 0;
340 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
342 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
343 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
344 return sizeof(BITMAPCOREHEADER
) + colors
*
345 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
347 else /* assume BITMAPINFOHEADER */
349 colors
= info
->bmiHeader
.biClrUsed
;
350 if (colors
> 256) /* buffer overflow otherwise */
352 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
353 colors
= 1 << info
->bmiHeader
.biBitCount
;
354 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
355 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
356 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
361 /***********************************************************************
364 * Helper function to duplicate a bitmap.
366 static HBITMAP
copy_bitmap( HBITMAP bitmap
)
369 HBITMAP new_bitmap
= 0;
372 if (!bitmap
) return 0;
373 if (!GetObjectW( bitmap
, sizeof(bmp
), &bmp
)) return 0;
375 if ((src
= CreateCompatibleDC( 0 )) && (dst
= CreateCompatibleDC( 0 )))
377 SelectObject( src
, bitmap
);
378 if ((new_bitmap
= CreateCompatibleBitmap( src
, bmp
.bmWidth
, bmp
.bmHeight
)))
380 SelectObject( dst
, new_bitmap
);
381 BitBlt( dst
, 0, 0, bmp
.bmWidth
, bmp
.bmHeight
, src
, 0, 0, SRCCOPY
);
390 /***********************************************************************
393 * Returns whether a DIB can be converted to a monochrome DDB.
395 * A DIB can be converted if its color table contains only black and
396 * white. Black must be the first color in the color table.
398 * Note : If the first color in the color table is white followed by
399 * black, we can't convert it to a monochrome DDB with
400 * SetDIBits, because black and white would be inverted.
402 static BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
404 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
406 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
408 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*)info
)->bmciColors
;
410 /* Check if the first color is black */
411 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
415 /* Check if the second color is white */
416 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
417 && (rgb
->rgbtBlue
== 0xff));
421 else /* assume BITMAPINFOHEADER */
423 const RGBQUAD
*rgb
= info
->bmiColors
;
425 /* Check if the first color is black */
426 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
427 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
431 /* Check if the second color is white */
432 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
433 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
439 /***********************************************************************
442 * Get the info from a bitmap header.
443 * Return 1 for INFOHEADER, 0 for COREHEADER, -1 in case of failure.
445 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
446 LONG
*height
, WORD
*bpp
, DWORD
*compr
)
448 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
450 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
451 *width
= core
->bcWidth
;
452 *height
= core
->bcHeight
;
453 *bpp
= core
->bcBitCount
;
457 else if (header
->biSize
== sizeof(BITMAPINFOHEADER
) ||
458 header
->biSize
== sizeof(BITMAPV4HEADER
) ||
459 header
->biSize
== sizeof(BITMAPV5HEADER
))
461 *width
= header
->biWidth
;
462 *height
= header
->biHeight
;
463 *bpp
= header
->biBitCount
;
464 *compr
= header
->biCompression
;
467 WARN("unknown/wrong size (%u) for header\n", header
->biSize
);
471 /**********************************************************************
474 BOOL
get_icon_size( HICON handle
, SIZE
*size
)
476 struct cursoricon_object
*info
;
477 struct cursoricon_frame
*frame
;
479 if (!(info
= get_icon_ptr( handle
))) return FALSE
;
480 frame
= get_icon_frame( info
, 0 );
481 size
->cx
= frame
->width
;
482 size
->cy
= frame
->height
;
483 release_icon_frame( info
, 0, frame
);
484 release_icon_ptr( handle
, info
);
489 * The following macro functions account for the irregularities of
490 * accessing cursor and icon resources in files and resource entries.
492 typedef BOOL (*fnGetCIEntry
)( LPCVOID dir
, int n
,
493 int *width
, int *height
, int *bits
);
495 /**********************************************************************
496 * CURSORICON_FindBestIcon
498 * Find the icon closest to the requested size and bit depth.
500 static int CURSORICON_FindBestIcon( LPCVOID dir
, fnGetCIEntry get_entry
,
501 int width
, int height
, int depth
, UINT loadflags
)
503 int i
, cx
, cy
, bits
, bestEntry
= -1;
504 UINT iTotalDiff
, iXDiff
=0, iYDiff
=0, iColorDiff
;
505 UINT iTempXDiff
, iTempYDiff
, iTempColorDiff
;
508 iTotalDiff
= 0xFFFFFFFF;
509 iColorDiff
= 0xFFFFFFFF;
511 if (loadflags
& LR_DEFAULTSIZE
)
513 if (!width
) width
= GetSystemMetrics( SM_CXICON
);
514 if (!height
) height
= GetSystemMetrics( SM_CYICON
);
516 else if (!width
&& !height
)
518 /* use the size of the first entry */
519 if (!get_entry( dir
, 0, &width
, &height
, &bits
)) return -1;
523 for ( i
= 0; iTotalDiff
&& get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
525 iTempXDiff
= abs(width
- cx
);
526 iTempYDiff
= abs(height
- cy
);
528 if(iTotalDiff
> (iTempXDiff
+ iTempYDiff
))
532 iTotalDiff
= iXDiff
+ iYDiff
;
536 /* Find Best Colors for Best Fit */
537 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
539 if(abs(width
- cx
) == iXDiff
&& abs(height
- cy
) == iYDiff
)
541 iTempColorDiff
= abs(depth
- bits
);
542 if(iColorDiff
> iTempColorDiff
)
545 iColorDiff
= iTempColorDiff
;
553 static BOOL
CURSORICON_GetResIconEntry( LPCVOID dir
, int n
,
554 int *width
, int *height
, int *bits
)
556 const CURSORICONDIR
*resdir
= dir
;
557 const ICONRESDIR
*icon
;
559 if ( resdir
->idCount
<= n
)
561 icon
= &resdir
->idEntries
[n
].ResInfo
.icon
;
562 *width
= icon
->bWidth
;
563 *height
= icon
->bHeight
;
564 *bits
= resdir
->idEntries
[n
].wBitCount
;
568 /**********************************************************************
569 * CURSORICON_FindBestCursor
571 * Find the cursor closest to the requested size.
573 * FIXME: parameter 'color' ignored.
575 static int CURSORICON_FindBestCursor( LPCVOID dir
, fnGetCIEntry get_entry
,
576 int width
, int height
, int depth
, UINT loadflags
)
578 int i
, maxwidth
, maxheight
, cx
, cy
, bits
, bestEntry
= -1;
580 if (loadflags
& LR_DEFAULTSIZE
)
582 if (!width
) width
= GetSystemMetrics( SM_CXCURSOR
);
583 if (!height
) height
= GetSystemMetrics( SM_CYCURSOR
);
585 else if (!width
&& !height
)
587 /* use the first entry */
588 if (!get_entry( dir
, 0, &width
, &height
, &bits
)) return -1;
592 /* Double height to account for AND and XOR masks */
596 /* First find the largest one smaller than or equal to the requested size*/
598 maxwidth
= maxheight
= 0;
599 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
601 if ((cx
<= width
) && (cy
<= height
) &&
602 (cx
> maxwidth
) && (cy
> maxheight
))
609 if (bestEntry
!= -1) return bestEntry
;
611 /* Now find the smallest one larger than the requested size */
613 maxwidth
= maxheight
= 255;
614 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
616 if (((cx
< maxwidth
) && (cy
< maxheight
)) || (bestEntry
== -1))
627 static BOOL
CURSORICON_GetResCursorEntry( LPCVOID dir
, int n
,
628 int *width
, int *height
, int *bits
)
630 const CURSORICONDIR
*resdir
= dir
;
631 const CURSORDIR
*cursor
;
633 if ( resdir
->idCount
<= n
)
635 cursor
= &resdir
->idEntries
[n
].ResInfo
.cursor
;
636 *width
= cursor
->wWidth
;
637 *height
= cursor
->wHeight
;
638 *bits
= resdir
->idEntries
[n
].wBitCount
;
642 static const CURSORICONDIRENTRY
*CURSORICON_FindBestIconRes( const CURSORICONDIR
* dir
,
643 int width
, int height
, int depth
,
648 n
= CURSORICON_FindBestIcon( dir
, CURSORICON_GetResIconEntry
,
649 width
, height
, depth
, loadflags
);
652 return &dir
->idEntries
[n
];
655 static const CURSORICONDIRENTRY
*CURSORICON_FindBestCursorRes( const CURSORICONDIR
*dir
,
656 int width
, int height
, int depth
,
659 int n
= CURSORICON_FindBestCursor( dir
, CURSORICON_GetResCursorEntry
,
660 width
, height
, depth
, loadflags
);
663 return &dir
->idEntries
[n
];
666 static BOOL
CURSORICON_GetFileEntry( LPCVOID dir
, int n
,
667 int *width
, int *height
, int *bits
)
669 const CURSORICONFILEDIR
*filedir
= dir
;
670 const CURSORICONFILEDIRENTRY
*entry
;
671 const BITMAPINFOHEADER
*info
;
673 if ( filedir
->idCount
<= n
)
675 entry
= &filedir
->idEntries
[n
];
676 /* FIXME: check against file size */
677 info
= (const BITMAPINFOHEADER
*)((const char *)dir
+ entry
->dwDIBOffset
);
678 *width
= entry
->bWidth
;
679 *height
= entry
->bHeight
;
680 *bits
= info
->biBitCount
;
684 static const CURSORICONFILEDIRENTRY
*CURSORICON_FindBestCursorFile( const CURSORICONFILEDIR
*dir
,
685 int width
, int height
, int depth
,
688 int n
= CURSORICON_FindBestCursor( dir
, CURSORICON_GetFileEntry
,
689 width
, height
, depth
, loadflags
);
692 return &dir
->idEntries
[n
];
695 static const CURSORICONFILEDIRENTRY
*CURSORICON_FindBestIconFile( const CURSORICONFILEDIR
*dir
,
696 int width
, int height
, int depth
,
699 int n
= CURSORICON_FindBestIcon( dir
, CURSORICON_GetFileEntry
,
700 width
, height
, depth
, loadflags
);
703 return &dir
->idEntries
[n
];
706 /***********************************************************************
709 static BOOL
bmi_has_alpha( const BITMAPINFO
*info
, const void *bits
)
712 BOOL has_alpha
= FALSE
;
713 const unsigned char *ptr
= bits
;
715 if (info
->bmiHeader
.biBitCount
!= 32) return FALSE
;
716 for (i
= 0; i
< info
->bmiHeader
.biWidth
* abs(info
->bmiHeader
.biHeight
); i
++, ptr
+= 4)
717 if ((has_alpha
= (ptr
[3] != 0))) break;
721 /***********************************************************************
722 * create_alpha_bitmap
724 * Create the alpha bitmap for a 32-bpp icon that has an alpha channel.
726 static HBITMAP
create_alpha_bitmap( HBITMAP color
, HBITMAP mask
,
727 const BITMAPINFO
*src_info
, const void *color_bits
)
730 BITMAPINFO
*info
= NULL
;
737 if (!GetObjectW( color
, sizeof(bm
), &bm
)) return 0;
738 if (bm
.bmBitsPixel
!= 32) return 0;
740 if (!(hdc
= CreateCompatibleDC( 0 ))) return 0;
741 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) goto done
;
742 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
743 info
->bmiHeader
.biWidth
= bm
.bmWidth
;
744 info
->bmiHeader
.biHeight
= -bm
.bmHeight
;
745 info
->bmiHeader
.biPlanes
= 1;
746 info
->bmiHeader
.biBitCount
= 32;
747 info
->bmiHeader
.biCompression
= BI_RGB
;
748 info
->bmiHeader
.biSizeImage
= bm
.bmWidth
* bm
.bmHeight
* 4;
749 info
->bmiHeader
.biXPelsPerMeter
= 0;
750 info
->bmiHeader
.biYPelsPerMeter
= 0;
751 info
->bmiHeader
.biClrUsed
= 0;
752 info
->bmiHeader
.biClrImportant
= 0;
753 if (!(alpha
= CreateDIBSection( hdc
, info
, DIB_RGB_COLORS
, &bits
, NULL
, 0 ))) goto done
;
757 SelectObject( hdc
, alpha
);
758 StretchDIBits( hdc
, 0, 0, bm
.bmWidth
, bm
.bmHeight
,
759 0, 0, src_info
->bmiHeader
.biWidth
, src_info
->bmiHeader
.biHeight
,
760 color_bits
, src_info
, DIB_RGB_COLORS
, SRCCOPY
);
765 GetDIBits( hdc
, color
, 0, bm
.bmHeight
, bits
, info
, DIB_RGB_COLORS
);
766 if (!bmi_has_alpha( info
, bits
))
768 DeleteObject( alpha
);
774 /* pre-multiply by alpha */
775 for (i
= 0, ptr
= bits
; i
< bm
.bmWidth
* bm
.bmHeight
; i
++, ptr
+= 4)
777 unsigned int alpha
= ptr
[3];
778 ptr
[0] = ptr
[0] * alpha
/ 255;
779 ptr
[1] = ptr
[1] * alpha
/ 255;
780 ptr
[2] = ptr
[2] * alpha
/ 255;
785 HeapFree( GetProcessHeap(), 0, info
);
790 /***********************************************************************
791 * create_icon_bitmaps
793 * Create the color, mask and alpha bitmaps from the DIB info.
795 static BOOL
create_icon_bitmaps( const BITMAPINFO
*bmi
, int width
, int height
,
796 HBITMAP
*color
, HBITMAP
*mask
, HBITMAP
*alpha
)
798 BOOL monochrome
= is_dib_monochrome( bmi
);
799 unsigned int size
= bitmap_info_size( bmi
, DIB_RGB_COLORS
);
801 const void *color_bits
, *mask_bits
;
805 if (!(info
= HeapAlloc( GetProcessHeap(), 0, max( size
, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] )))))
807 if (!(hdc
= CreateCompatibleDC( 0 ))) goto done
;
809 memcpy( info
, bmi
, size
);
810 info
->bmiHeader
.biHeight
/= 2;
812 color_bits
= (const char*)bmi
+ size
;
813 mask_bits
= (const char*)color_bits
+
814 get_dib_width_bytes( bmi
->bmiHeader
.biWidth
,
815 bmi
->bmiHeader
.biBitCount
) * abs(info
->bmiHeader
.biHeight
);
820 if (!(*mask
= CreateBitmap( width
, height
* 2, 1, 1, NULL
))) goto done
;
823 /* copy color data into second half of mask bitmap */
824 SelectObject( hdc
, *mask
);
825 StretchDIBits( hdc
, 0, height
, width
, height
,
826 0, 0, info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
,
827 color_bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
831 if (!(*mask
= CreateBitmap( width
, height
, 1, 1, NULL
))) goto done
;
832 if (!(*color
= CreateBitmap( width
, height
, GetDeviceCaps( screen_dc
, PLANES
),
833 GetDeviceCaps( screen_dc
, BITSPIXEL
), NULL
)))
835 DeleteObject( *mask
);
838 SelectObject( hdc
, *color
);
839 StretchDIBits( hdc
, 0, 0, width
, height
,
840 0, 0, info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
,
841 color_bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
843 if (bmi_has_alpha( info
, color_bits
))
844 *alpha
= create_alpha_bitmap( *color
, *mask
, info
, color_bits
);
846 /* convert info to monochrome to copy the mask */
847 info
->bmiHeader
.biBitCount
= 1;
848 if (info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
))
850 RGBQUAD
*rgb
= info
->bmiColors
;
852 info
->bmiHeader
.biClrUsed
= info
->bmiHeader
.biClrImportant
= 2;
853 rgb
[0].rgbBlue
= rgb
[0].rgbGreen
= rgb
[0].rgbRed
= 0x00;
854 rgb
[1].rgbBlue
= rgb
[1].rgbGreen
= rgb
[1].rgbRed
= 0xff;
855 rgb
[0].rgbReserved
= rgb
[1].rgbReserved
= 0;
859 RGBTRIPLE
*rgb
= (RGBTRIPLE
*)(((BITMAPCOREHEADER
*)info
) + 1);
861 rgb
[0].rgbtBlue
= rgb
[0].rgbtGreen
= rgb
[0].rgbtRed
= 0x00;
862 rgb
[1].rgbtBlue
= rgb
[1].rgbtGreen
= rgb
[1].rgbtRed
= 0xff;
866 SelectObject( hdc
, *mask
);
867 StretchDIBits( hdc
, 0, 0, width
, height
,
868 0, 0, info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
,
869 mask_bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
874 HeapFree( GetProcessHeap(), 0, info
);
878 static HICON
CURSORICON_CreateIconFromBMI( BITMAPINFO
*bmi
, HMODULE module
, LPCWSTR resname
, HRSRC rsrc
,
879 POINT hotspot
, BOOL bIcon
, INT width
, INT height
, UINT cFlag
)
882 HBITMAP color
= 0, mask
= 0, alpha
= 0;
885 /* Check bitmap header */
887 if ( (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) &&
888 (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) ||
889 bmi
->bmiHeader
.biCompression
!= BI_RGB
) )
891 WARN_(cursor
)("\tinvalid resource bitmap header.\n");
895 if (cFlag
& LR_DEFAULTSIZE
)
897 if (!width
) width
= GetSystemMetrics( bIcon
? SM_CXICON
: SM_CXCURSOR
);
898 if (!height
) height
= GetSystemMetrics( bIcon
? SM_CYICON
: SM_CYCURSOR
);
902 if (!width
) width
= bmi
->bmiHeader
.biWidth
;
903 if (!height
) height
= bmi
->bmiHeader
.biHeight
/2;
905 do_stretch
= (bmi
->bmiHeader
.biHeight
/2 != height
) ||
906 (bmi
->bmiHeader
.biWidth
!= width
);
908 /* Scale the hotspot */
911 hotspot
.x
= width
/ 2;
912 hotspot
.y
= height
/ 2;
916 hotspot
.x
= (hotspot
.x
* width
) / bmi
->bmiHeader
.biWidth
;
917 hotspot
.y
= (hotspot
.y
* height
) / (bmi
->bmiHeader
.biHeight
/ 2);
920 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
921 if (!screen_dc
) return 0;
923 if (!create_icon_bitmaps( bmi
, width
, height
, &color
, &mask
, &alpha
)) return 0;
925 hObj
= alloc_icon_handle( FALSE
, 1 );
928 struct cursoricon_object
*info
= get_icon_ptr( hObj
);
929 struct cursoricon_frame
*frame
;
931 info
->is_icon
= bIcon
;
932 info
->module
= module
;
933 info
->hotspot
= hotspot
;
934 frame
= get_icon_frame( info
, 0 );
936 frame
->width
= width
;
937 frame
->height
= height
;
938 frame
->color
= color
;
940 frame
->alpha
= alpha
;
941 release_icon_frame( info
, 0, frame
);
942 if (!IS_INTRESOURCE(resname
))
944 info
->resname
= HeapAlloc( GetProcessHeap(), 0, (strlenW(resname
) + 1) * sizeof(WCHAR
) );
945 if (info
->resname
) strcpyW( info
->resname
, resname
);
947 else info
->resname
= MAKEINTRESOURCEW( LOWORD(resname
) );
949 if (module
&& (cFlag
& LR_SHARED
))
952 list_add_head( &icon_cache
, &info
->entry
);
954 release_icon_ptr( hObj
, info
);
955 USER_Driver
->pCreateCursorIcon( hObj
);
959 DeleteObject( color
);
960 DeleteObject( alpha
);
961 DeleteObject( mask
);
967 /**********************************************************************
968 * .ANI cursor support
970 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
971 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
972 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
974 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
975 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
976 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
977 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
978 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
979 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
980 #define ANI_rate_ID RIFF_FOURCC('r', 'a', 't', 'e')
982 #define ANI_FLAG_ICON 0x1
983 #define ANI_FLAG_SEQUENCE 0x2
999 const unsigned char *data
;
1002 static void dump_ani_header( const ani_header
*header
)
1004 TRACE(" header size: %d\n", header
->header_size
);
1005 TRACE(" frames: %d\n", header
->num_frames
);
1006 TRACE(" steps: %d\n", header
->num_steps
);
1007 TRACE(" width: %d\n", header
->width
);
1008 TRACE(" height: %d\n", header
->height
);
1009 TRACE(" bpp: %d\n", header
->bpp
);
1010 TRACE(" planes: %d\n", header
->num_planes
);
1011 TRACE(" display rate: %d\n", header
->display_rate
);
1012 TRACE(" flags: 0x%08x\n", header
->flags
);
1034 static void riff_find_chunk( DWORD chunk_id
, DWORD chunk_type
, const riff_chunk_t
*parent_chunk
, riff_chunk_t
*chunk
)
1036 const unsigned char *ptr
= parent_chunk
->data
;
1037 const unsigned char *end
= parent_chunk
->data
+ (parent_chunk
->data_size
- (2 * sizeof(DWORD
)));
1039 if (chunk_type
== ANI_LIST_ID
|| chunk_type
== ANI_RIFF_ID
) end
-= sizeof(DWORD
);
1043 if ((!chunk_type
&& *(const DWORD
*)ptr
== chunk_id
)
1044 || (chunk_type
&& *(const DWORD
*)ptr
== chunk_type
&& *((const DWORD
*)ptr
+ 2) == chunk_id
))
1046 ptr
+= sizeof(DWORD
);
1047 chunk
->data_size
= (*(const DWORD
*)ptr
+ 1) & ~1;
1048 ptr
+= sizeof(DWORD
);
1049 if (chunk_type
== ANI_LIST_ID
|| chunk_type
== ANI_RIFF_ID
) ptr
+= sizeof(DWORD
);
1055 ptr
+= sizeof(DWORD
);
1056 ptr
+= (*(const DWORD
*)ptr
+ 1) & ~1;
1057 ptr
+= sizeof(DWORD
);
1065 * RIFF:'ACON' RIFF chunk
1066 * |- CHUNK:'anih' Header
1067 * |- CHUNK:'seq ' Sequence information (optional)
1068 * \- LIST:'fram' Frame list
1069 * |- CHUNK:icon Cursor frames
1074 static HCURSOR
CURSORICON_CreateIconFromANI( const LPBYTE bits
, DWORD bits_size
,
1075 INT width
, INT height
, INT depth
, UINT loadflags
)
1077 struct animated_cursoricon_object
*ani_icon_data
;
1078 struct cursoricon_object
*info
;
1079 DWORD
*frame_rates
= NULL
;
1080 ani_header header
= {0};
1084 riff_chunk_t root_chunk
= { bits_size
, bits
};
1085 riff_chunk_t ACON_chunk
= {0};
1086 riff_chunk_t anih_chunk
= {0};
1087 riff_chunk_t fram_chunk
= {0};
1088 riff_chunk_t rate_chunk
= {0};
1089 const unsigned char *icon_chunk
;
1090 const unsigned char *icon_data
;
1092 TRACE("bits %p, bits_size %d\n", bits
, bits_size
);
1094 riff_find_chunk( ANI_ACON_ID
, ANI_RIFF_ID
, &root_chunk
, &ACON_chunk
);
1095 if (!ACON_chunk
.data
)
1097 ERR("Failed to get root chunk.\n");
1101 riff_find_chunk( ANI_anih_ID
, 0, &ACON_chunk
, &anih_chunk
);
1102 if (!anih_chunk
.data
)
1104 ERR("Failed to get 'anih' chunk.\n");
1107 memcpy( &header
, anih_chunk
.data
, sizeof(header
) );
1108 dump_ani_header( &header
);
1110 if (!(header
.flags
& ANI_FLAG_ICON
))
1112 FIXME("Raw animated icon/cursor data is not currently supported.\n");
1116 if (header
.flags
& ANI_FLAG_SEQUENCE
)
1117 FIXME("Animated icon/cursor sequence data is not currently supported, frames may appear out of sequence.\n");
1119 riff_find_chunk( ANI_rate_ID
, 0, &ACON_chunk
, &rate_chunk
);
1120 if (rate_chunk
.data
&& header
.num_steps
== header
.num_frames
)
1121 frame_rates
= (DWORD
*) rate_chunk
.data
;
1122 else if (rate_chunk
.data
&& header
.num_steps
!= 1)
1123 FIXME("Animated icon/cursor rate data for sequence-based cursors not supported.\n");
1125 riff_find_chunk( ANI_fram_ID
, ANI_LIST_ID
, &ACON_chunk
, &fram_chunk
);
1126 if (!fram_chunk
.data
)
1128 ERR("Failed to get icon list.\n");
1132 cursor
= alloc_icon_handle( TRUE
, header
.num_frames
);
1133 if (!cursor
) return 0;
1135 info
= get_icon_ptr( cursor
);
1136 ani_icon_data
= (struct animated_cursoricon_object
*) info
;
1137 info
->is_icon
= FALSE
;
1138 if (header
.num_steps
> header
.num_frames
)
1140 FIXME("More steps than frames and sequence-based cursors not yet supported.\n");
1141 ani_icon_data
->num_steps
= header
.num_frames
;
1144 ani_icon_data
->num_steps
= header
.num_steps
;
1146 /* The .ANI stores the display rate in jiffies (1/60s) */
1147 info
->delay
= header
.display_rate
;
1149 icon_chunk
= fram_chunk
.data
;
1150 icon_data
= fram_chunk
.data
+ (2 * sizeof(DWORD
));
1151 for (i
=0; i
<header
.num_frames
; i
++)
1153 const DWORD chunk_size
= *(const DWORD
*)(icon_chunk
+ sizeof(DWORD
));
1154 const CURSORICONFILEDIRENTRY
*entry
;
1155 struct cursoricon_frame
*frame
;
1156 INT frameWidth
, frameHeight
;
1157 const BITMAPINFO
*bmi
;
1160 entry
= CURSORICON_FindBestIconFile((const CURSORICONFILEDIR
*) icon_data
,
1161 width
, height
, depth
, loadflags
);
1163 bmi
= (const BITMAPINFO
*) (icon_data
+ entry
->dwDIBOffset
);
1164 info
->hotspot
.x
= entry
->xHotspot
;
1165 info
->hotspot
.y
= entry
->yHotspot
;
1166 if (!header
.width
|| !header
.height
)
1168 frameWidth
= entry
->bWidth
;
1169 frameHeight
= entry
->bHeight
;
1173 frameWidth
= header
.width
;
1174 frameHeight
= header
.height
;
1177 /* Grab a frame from the animation */
1178 hIconFrame
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*)bmi
, NULL
, NULL
, NULL
, info
->hotspot
,
1179 FALSE
, frameWidth
, frameHeight
, loadflags
);
1182 FIXME_(cursor
)("failed to convert animated cursor frame.\n");
1186 FIXME_(cursor
)("Completely failed to create animated cursor!\n");
1187 ani_icon_data
->num_frames
= 0;
1188 release_icon_ptr( cursor
, info
);
1189 free_icon_handle( cursor
);
1195 /* Setup the animated frame */
1196 ani_icon_data
->frames
[i
] = hIconFrame
;
1197 frame
= get_icon_frame( info
, i
);
1199 frame
->delay
= frame_rates
[i
];
1202 release_icon_frame( info
, i
, frame
);
1204 /* Advance to the next chunk */
1205 icon_chunk
+= chunk_size
+ (2 * sizeof(DWORD
));
1206 icon_data
= icon_chunk
+ (2 * sizeof(DWORD
));
1209 /* There was an error but we at least decoded the first frame, so just use that frame */
1212 FIXME_(cursor
)("Error creating animated cursor, only using first frame!\n");
1213 for (i
=1; i
<ani_icon_data
->num_frames
; i
++)
1214 free_icon_handle( ani_icon_data
->frames
[i
] );
1216 ani_icon_data
->num_steps
= 1;
1217 ani_icon_data
->num_frames
= 1;
1219 release_icon_ptr( cursor
, info
);
1225 /**********************************************************************
1226 * CreateIconFromResourceEx (USER32.@)
1228 * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
1229 * with cbSize parameter as well.
1231 HICON WINAPI
CreateIconFromResourceEx( LPBYTE bits
, UINT cbSize
,
1232 BOOL bIcon
, DWORD dwVersion
,
1233 INT width
, INT height
,
1239 TRACE_(cursor
)("%p (%u bytes), ver %08x, %ix%i %s %s\n",
1240 bits
, cbSize
, dwVersion
, width
, height
,
1241 bIcon
? "icon" : "cursor", (cFlag
& LR_MONOCHROME
) ? "mono" : "" );
1243 if (!bits
) return 0;
1245 if (dwVersion
== 0x00020000)
1247 FIXME_(cursor
)("\t2.xx resources are not supported\n");
1251 /* Check if the resource is an animated icon/cursor */
1252 if (!memcmp(bits
, "RIFF", 4))
1253 return CURSORICON_CreateIconFromANI( bits
, cbSize
, width
, height
, 0 /* default depth */, cFlag
);
1257 hotspot
.x
= width
/ 2;
1258 hotspot
.y
= height
/ 2;
1259 bmi
= (BITMAPINFO
*)bits
;
1261 else /* get the hotspot */
1263 SHORT
*pt
= (SHORT
*)bits
;
1266 bmi
= (BITMAPINFO
*)(pt
+ 2);
1269 return CURSORICON_CreateIconFromBMI( bmi
, NULL
, NULL
, NULL
, hotspot
, bIcon
, width
, height
, cFlag
);
1273 /**********************************************************************
1274 * CreateIconFromResource (USER32.@)
1276 HICON WINAPI
CreateIconFromResource( LPBYTE bits
, UINT cbSize
,
1277 BOOL bIcon
, DWORD dwVersion
)
1279 return CreateIconFromResourceEx( bits
, cbSize
, bIcon
, dwVersion
, 0,0,0);
1283 static HICON
CURSORICON_LoadFromFile( LPCWSTR filename
,
1284 INT width
, INT height
, INT depth
,
1285 BOOL fCursor
, UINT loadflags
)
1287 const CURSORICONFILEDIRENTRY
*entry
;
1288 const CURSORICONFILEDIR
*dir
;
1294 TRACE("loading %s\n", debugstr_w( filename
));
1296 bits
= map_fileW( filename
, &filesize
);
1300 /* Check for .ani. */
1301 if (memcmp( bits
, "RIFF", 4 ) == 0)
1303 hIcon
= CURSORICON_CreateIconFromANI( bits
, filesize
, width
, height
, depth
, loadflags
);
1307 dir
= (const CURSORICONFILEDIR
*) bits
;
1308 if ( filesize
< sizeof(*dir
) )
1311 if ( filesize
< (sizeof(*dir
) + sizeof(dir
->idEntries
[0])*(dir
->idCount
-1)) )
1315 entry
= CURSORICON_FindBestCursorFile( dir
, width
, height
, depth
, loadflags
);
1317 entry
= CURSORICON_FindBestIconFile( dir
, width
, height
, depth
, loadflags
);
1322 /* check that we don't run off the end of the file */
1323 if ( entry
->dwDIBOffset
> filesize
)
1325 if ( entry
->dwDIBOffset
+ entry
->dwDIBSize
> filesize
)
1328 hotspot
.x
= entry
->xHotspot
;
1329 hotspot
.y
= entry
->yHotspot
;
1330 hIcon
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*)&bits
[entry
->dwDIBOffset
], NULL
, NULL
, NULL
,
1331 hotspot
, !fCursor
, width
, height
, loadflags
);
1333 TRACE("loaded %s -> %p\n", debugstr_w( filename
), hIcon
);
1334 UnmapViewOfFile( bits
);
1338 /**********************************************************************
1341 * Load a cursor or icon from resource or file.
1343 static HICON
CURSORICON_Load(HINSTANCE hInstance
, LPCWSTR name
,
1344 INT width
, INT height
, INT depth
,
1345 BOOL fCursor
, UINT loadflags
)
1350 const CURSORICONDIR
*dir
;
1351 const CURSORICONDIRENTRY
*dirEntry
;
1356 TRACE("%p, %s, %dx%d, depth %d, fCursor %d, flags 0x%04x\n",
1357 hInstance
, debugstr_w(name
), width
, height
, depth
, fCursor
, loadflags
);
1359 if ( loadflags
& LR_LOADFROMFILE
) /* Load from file */
1360 return CURSORICON_LoadFromFile( name
, width
, height
, depth
, fCursor
, loadflags
);
1362 if (!hInstance
) hInstance
= user32_module
; /* Load OEM cursor/icon */
1364 /* don't cache 16-bit instances (FIXME: should never get 16-bit instances in the first place) */
1365 if ((ULONG_PTR
)hInstance
>> 16 == 0) loadflags
&= ~LR_SHARED
;
1367 /* Get directory resource ID */
1369 if (!(hRsrc
= FindResourceW( hInstance
, name
,
1370 (LPWSTR
)(fCursor
? RT_GROUP_CURSOR
: RT_GROUP_ICON
) )))
1373 /* Find the best entry in the directory */
1375 if (!(handle
= LoadResource( hInstance
, hRsrc
))) return 0;
1376 if (!(dir
= LockResource( handle
))) return 0;
1378 dirEntry
= CURSORICON_FindBestCursorRes( dir
, width
, height
, depth
, loadflags
);
1380 dirEntry
= CURSORICON_FindBestIconRes( dir
, width
, height
, depth
, loadflags
);
1381 if (!dirEntry
) return 0;
1382 wResId
= dirEntry
->wResId
;
1383 FreeResource( handle
);
1385 /* Load the resource */
1387 if (!(hRsrc
= FindResourceW(hInstance
,MAKEINTRESOURCEW(wResId
),
1388 (LPWSTR
)(fCursor
? RT_CURSOR
: RT_ICON
) ))) return 0;
1390 /* If shared icon, check whether it was already loaded */
1391 if (loadflags
& LR_SHARED
)
1393 struct cursoricon_object
*ptr
;
1396 LIST_FOR_EACH_ENTRY( ptr
, &icon_cache
, struct cursoricon_object
, entry
)
1398 if (ptr
->module
!= hInstance
) continue;
1399 if (ptr
->rsrc
!= hRsrc
) continue;
1400 hIcon
= ptr
->obj
.handle
;
1404 if (hIcon
) return hIcon
;
1407 if (!(handle
= LoadResource( hInstance
, hRsrc
))) return 0;
1408 bits
= LockResource( handle
);
1412 hotspot
.x
= width
/ 2;
1413 hotspot
.y
= height
/ 2;
1415 else /* get the hotspot */
1417 SHORT
*pt
= (SHORT
*)bits
;
1420 bits
+= 2 * sizeof(SHORT
);
1422 hIcon
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*)bits
, hInstance
, name
, hRsrc
,
1423 hotspot
, !fCursor
, width
, height
, loadflags
);
1424 FreeResource( handle
);
1429 /***********************************************************************
1430 * CreateCursor (USER32.@)
1432 HCURSOR WINAPI
CreateCursor( HINSTANCE hInstance
,
1433 INT xHotSpot
, INT yHotSpot
,
1434 INT nWidth
, INT nHeight
,
1435 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
1440 TRACE_(cursor
)("%dx%d spot=%d,%d xor=%p and=%p\n",
1441 nWidth
, nHeight
, xHotSpot
, yHotSpot
, lpXORbits
, lpANDbits
);
1444 info
.xHotspot
= xHotSpot
;
1445 info
.yHotspot
= yHotSpot
;
1446 info
.hbmMask
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpANDbits
);
1447 info
.hbmColor
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpXORbits
);
1448 hCursor
= CreateIconIndirect( &info
);
1449 DeleteObject( info
.hbmMask
);
1450 DeleteObject( info
.hbmColor
);
1455 /***********************************************************************
1456 * CreateIcon (USER32.@)
1458 * Creates an icon based on the specified bitmaps. The bitmaps must be
1459 * provided in a device dependent format and will be resized to
1460 * (SM_CXICON,SM_CYICON) and depth converted to match the screen's color
1461 * depth. The provided bitmaps must be top-down bitmaps.
1462 * Although Windows does not support 15bpp(*) this API must support it
1463 * for Winelib applications.
1465 * (*) Windows does not support 15bpp but it supports the 555 RGB 16bpp
1469 * Success: handle to an icon
1472 * FIXME: Do we need to resize the bitmaps?
1474 HICON WINAPI
CreateIcon(
1475 HINSTANCE hInstance
, /* [in] the application's hInstance */
1476 INT nWidth
, /* [in] the width of the provided bitmaps */
1477 INT nHeight
, /* [in] the height of the provided bitmaps */
1478 BYTE bPlanes
, /* [in] the number of planes in the provided bitmaps */
1479 BYTE bBitsPixel
, /* [in] the number of bits per pixel of the lpXORbits bitmap */
1480 LPCVOID lpANDbits
, /* [in] a monochrome bitmap representing the icon's mask */
1481 LPCVOID lpXORbits
) /* [in] the icon's 'color' bitmap */
1486 TRACE_(icon
)("%dx%d, planes %d, bpp %d, xor %p, and %p\n",
1487 nWidth
, nHeight
, bPlanes
, bBitsPixel
, lpXORbits
, lpANDbits
);
1490 iinfo
.xHotspot
= nWidth
/ 2;
1491 iinfo
.yHotspot
= nHeight
/ 2;
1492 iinfo
.hbmMask
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpANDbits
);
1493 iinfo
.hbmColor
= CreateBitmap( nWidth
, nHeight
, bPlanes
, bBitsPixel
, lpXORbits
);
1495 hIcon
= CreateIconIndirect( &iinfo
);
1497 DeleteObject( iinfo
.hbmMask
);
1498 DeleteObject( iinfo
.hbmColor
);
1504 /***********************************************************************
1505 * CopyIcon (USER32.@)
1507 HICON WINAPI
CopyIcon( HICON hIcon
)
1509 struct cursoricon_object
*ptrOld
, *ptrNew
;
1512 if (!(ptrOld
= get_icon_ptr( hIcon
)))
1514 SetLastError( ERROR_INVALID_CURSOR_HANDLE
);
1517 if ((hNew
= alloc_icon_handle( FALSE
, 1 )))
1519 struct cursoricon_frame
*frameOld
, *frameNew
;
1521 ptrNew
= get_icon_ptr( hNew
);
1522 ptrNew
->is_icon
= ptrOld
->is_icon
;
1523 ptrNew
->hotspot
= ptrOld
->hotspot
;
1524 if (!(frameOld
= get_icon_frame( ptrOld
, 0 )))
1526 release_icon_ptr( hIcon
, ptrOld
);
1527 SetLastError( ERROR_INVALID_CURSOR_HANDLE
);
1530 if (!(frameNew
= get_icon_frame( ptrNew
, 0 )))
1532 release_icon_frame( ptrOld
, 0, frameOld
);
1533 release_icon_ptr( hIcon
, ptrOld
);
1534 SetLastError( ERROR_INVALID_CURSOR_HANDLE
);
1537 frameNew
->delay
= 0;
1538 frameNew
->width
= frameOld
->width
;
1539 frameNew
->height
= frameOld
->height
;
1540 frameNew
->mask
= copy_bitmap( frameOld
->mask
);
1541 frameNew
->color
= copy_bitmap( frameOld
->color
);
1542 frameNew
->alpha
= copy_bitmap( frameOld
->alpha
);
1543 release_icon_frame( ptrOld
, 0, frameOld
);
1544 release_icon_frame( ptrNew
, 0, frameNew
);
1545 release_icon_ptr( hNew
, ptrNew
);
1547 release_icon_ptr( hIcon
, ptrOld
);
1548 if (hNew
) USER_Driver
->pCreateCursorIcon( hNew
);
1553 /***********************************************************************
1554 * DestroyIcon (USER32.@)
1556 BOOL WINAPI
DestroyIcon( HICON hIcon
)
1559 struct cursoricon_object
*obj
= get_icon_ptr( hIcon
);
1561 TRACE_(icon
)("%p\n", hIcon
);
1565 BOOL shared
= (obj
->rsrc
!= NULL
);
1566 release_icon_ptr( hIcon
, obj
);
1567 ret
= (GetCursor() != hIcon
);
1568 if (!shared
) free_icon_handle( hIcon
);
1574 /***********************************************************************
1575 * DestroyCursor (USER32.@)
1577 BOOL WINAPI
DestroyCursor( HCURSOR hCursor
)
1579 return DestroyIcon( hCursor
);
1582 /***********************************************************************
1583 * DrawIcon (USER32.@)
1585 BOOL WINAPI
DrawIcon( HDC hdc
, INT x
, INT y
, HICON hIcon
)
1587 return DrawIconEx( hdc
, x
, y
, hIcon
, 0, 0, 0, 0, DI_NORMAL
| DI_COMPAT
| DI_DEFAULTSIZE
);
1590 /***********************************************************************
1591 * SetCursor (USER32.@)
1593 * Set the cursor shape.
1596 * A handle to the previous cursor shape.
1598 HCURSOR WINAPI DECLSPEC_HOTPATCH
SetCursor( HCURSOR hCursor
/* [in] Handle of cursor to show */ )
1600 struct cursoricon_object
*obj
;
1605 TRACE("%p\n", hCursor
);
1607 SERVER_START_REQ( set_cursor
)
1609 req
->flags
= SET_CURSOR_HANDLE
;
1610 req
->handle
= wine_server_user_handle( hCursor
);
1611 if ((ret
= !wine_server_call_err( req
)))
1613 hOldCursor
= wine_server_ptr_handle( reply
->prev_handle
);
1614 show_count
= reply
->prev_count
;
1621 /* Change the cursor shape only if it is visible */
1622 if (show_count
>= 0 && hOldCursor
!= hCursor
) USER_Driver
->pSetCursor( hCursor
);
1624 if (!(obj
= get_icon_ptr( hOldCursor
))) return 0;
1625 release_icon_ptr( hOldCursor
, obj
);
1629 /***********************************************************************
1630 * ShowCursor (USER32.@)
1632 INT WINAPI DECLSPEC_HOTPATCH
ShowCursor( BOOL bShow
)
1635 int increment
= bShow
? 1 : -1;
1638 SERVER_START_REQ( set_cursor
)
1640 req
->flags
= SET_CURSOR_COUNT
;
1641 req
->show_count
= increment
;
1642 wine_server_call( req
);
1643 cursor
= wine_server_ptr_handle( reply
->prev_handle
);
1644 count
= reply
->prev_count
+ increment
;
1648 TRACE("%d, count=%d\n", bShow
, count
);
1650 if (bShow
&& !count
) USER_Driver
->pSetCursor( cursor
);
1651 else if (!bShow
&& count
== -1) USER_Driver
->pSetCursor( 0 );
1656 /***********************************************************************
1657 * GetCursor (USER32.@)
1659 HCURSOR WINAPI
GetCursor(void)
1663 SERVER_START_REQ( set_cursor
)
1666 wine_server_call( req
);
1667 ret
= wine_server_ptr_handle( reply
->prev_handle
);
1674 /***********************************************************************
1675 * ClipCursor (USER32.@)
1677 BOOL WINAPI DECLSPEC_HOTPATCH
ClipCursor( const RECT
*rect
)
1682 TRACE( "Clipping to %s\n", wine_dbgstr_rect(rect
) );
1684 SERVER_START_REQ( set_cursor
)
1686 req
->flags
= SET_CURSOR_CLIP
;
1689 req
->clip
.left
= rect
->left
;
1690 req
->clip
.top
= rect
->top
;
1691 req
->clip
.right
= rect
->right
;
1692 req
->clip
.bottom
= rect
->bottom
;
1694 if ((ret
= !wine_server_call( req
)))
1696 new_rect
.left
= reply
->new_clip
.left
;
1697 new_rect
.top
= reply
->new_clip
.top
;
1698 new_rect
.right
= reply
->new_clip
.right
;
1699 new_rect
.bottom
= reply
->new_clip
.bottom
;
1703 if (ret
) USER_Driver
->pClipCursor( &new_rect
);
1708 /***********************************************************************
1709 * GetClipCursor (USER32.@)
1711 BOOL WINAPI DECLSPEC_HOTPATCH
GetClipCursor( RECT
*rect
)
1715 if (!rect
) return FALSE
;
1717 SERVER_START_REQ( set_cursor
)
1720 if ((ret
= !wine_server_call( req
)))
1722 rect
->left
= reply
->new_clip
.left
;
1723 rect
->top
= reply
->new_clip
.top
;
1724 rect
->right
= reply
->new_clip
.right
;
1725 rect
->bottom
= reply
->new_clip
.bottom
;
1733 /***********************************************************************
1734 * SetSystemCursor (USER32.@)
1736 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
1738 FIXME("(%p,%08x),stub!\n", hcur
, id
);
1743 /**********************************************************************
1744 * LookupIconIdFromDirectoryEx (USER32.@)
1746 INT WINAPI
LookupIconIdFromDirectoryEx( LPBYTE xdir
, BOOL bIcon
,
1747 INT width
, INT height
, UINT cFlag
)
1749 const CURSORICONDIR
*dir
= (const CURSORICONDIR
*)xdir
;
1751 if( dir
&& !dir
->idReserved
&& (dir
->idType
& 3) )
1753 const CURSORICONDIRENTRY
* entry
;
1755 const HDC hdc
= GetDC(0);
1756 const int depth
= (cFlag
& LR_MONOCHROME
) ?
1757 1 : GetDeviceCaps(hdc
, BITSPIXEL
);
1761 entry
= CURSORICON_FindBestIconRes( dir
, width
, height
, depth
, LR_DEFAULTSIZE
);
1763 entry
= CURSORICON_FindBestCursorRes( dir
, width
, height
, depth
, LR_DEFAULTSIZE
);
1765 if( entry
) retVal
= entry
->wResId
;
1767 else WARN_(cursor
)("invalid resource directory\n");
1771 /**********************************************************************
1772 * LookupIconIdFromDirectory (USER32.@)
1774 INT WINAPI
LookupIconIdFromDirectory( LPBYTE dir
, BOOL bIcon
)
1776 return LookupIconIdFromDirectoryEx( dir
, bIcon
, 0, 0, bIcon
? 0 : LR_MONOCHROME
);
1779 /***********************************************************************
1780 * LoadCursorW (USER32.@)
1782 HCURSOR WINAPI
LoadCursorW(HINSTANCE hInstance
, LPCWSTR name
)
1784 TRACE("%p, %s\n", hInstance
, debugstr_w(name
));
1786 return LoadImageW( hInstance
, name
, IMAGE_CURSOR
, 0, 0,
1787 LR_SHARED
| LR_DEFAULTSIZE
);
1790 /***********************************************************************
1791 * LoadCursorA (USER32.@)
1793 HCURSOR WINAPI
LoadCursorA(HINSTANCE hInstance
, LPCSTR name
)
1795 TRACE("%p, %s\n", hInstance
, debugstr_a(name
));
1797 return LoadImageA( hInstance
, name
, IMAGE_CURSOR
, 0, 0,
1798 LR_SHARED
| LR_DEFAULTSIZE
);
1801 /***********************************************************************
1802 * LoadCursorFromFileW (USER32.@)
1804 HCURSOR WINAPI
LoadCursorFromFileW (LPCWSTR name
)
1806 TRACE("%s\n", debugstr_w(name
));
1808 return LoadImageW( 0, name
, IMAGE_CURSOR
, 0, 0,
1809 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
1812 /***********************************************************************
1813 * LoadCursorFromFileA (USER32.@)
1815 HCURSOR WINAPI
LoadCursorFromFileA (LPCSTR name
)
1817 TRACE("%s\n", debugstr_a(name
));
1819 return LoadImageA( 0, name
, IMAGE_CURSOR
, 0, 0,
1820 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
1823 /***********************************************************************
1824 * LoadIconW (USER32.@)
1826 HICON WINAPI
LoadIconW(HINSTANCE hInstance
, LPCWSTR name
)
1828 TRACE("%p, %s\n", hInstance
, debugstr_w(name
));
1830 return LoadImageW( hInstance
, name
, IMAGE_ICON
, 0, 0,
1831 LR_SHARED
| LR_DEFAULTSIZE
);
1834 /***********************************************************************
1835 * LoadIconA (USER32.@)
1837 HICON WINAPI
LoadIconA(HINSTANCE hInstance
, LPCSTR name
)
1839 TRACE("%p, %s\n", hInstance
, debugstr_a(name
));
1841 return LoadImageA( hInstance
, name
, IMAGE_ICON
, 0, 0,
1842 LR_SHARED
| LR_DEFAULTSIZE
);
1845 /**********************************************************************
1846 * GetCursorFrameInfo (USER32.@)
1848 HCURSOR WINAPI
GetCursorFrameInfo(HCURSOR hCursor
, DWORD unk1
, DWORD istep
, DWORD
*rate_jiffies
, DWORD
*num_steps
)
1850 struct cursoricon_object
*ptr
;
1854 if (rate_jiffies
== NULL
|| num_steps
== NULL
) return 0;
1856 if (!(ptr
= get_icon_ptr( hCursor
))) return 0;
1858 FIXME("semi-stub! %p => %d %d %p %p\n", hCursor
, unk1
, istep
, rate_jiffies
, num_steps
);
1860 icon_steps
= get_icon_steps(ptr
);
1861 /* Important Note: Sequences are not currently supported, so this implementation
1862 * will not properly handle all cases. */
1863 if (istep
< icon_steps
|| !ptr
->is_ani
)
1865 struct animated_cursoricon_object
*ani_icon_data
= (struct animated_cursoricon_object
*) ptr
;
1866 UINT icon_frames
= 1;
1869 icon_frames
= ani_icon_data
->num_frames
;
1870 if (ptr
->is_ani
&& icon_frames
> 1)
1871 ret
= ani_icon_data
->frames
[istep
];
1874 if (icon_frames
== 1)
1879 else if (icon_steps
== 1)
1882 *rate_jiffies
= ptr
->delay
;
1884 else if (istep
< icon_steps
)
1886 struct cursoricon_frame
*frame
;
1888 *num_steps
= icon_steps
;
1889 frame
= get_icon_frame( ptr
, istep
);
1890 if (get_icon_steps(ptr
) == 1)
1893 *num_steps
= get_icon_steps(ptr
);
1894 /* If this specific frame does not have a delay then use the global delay */
1895 if (frame
->delay
== ~0)
1896 *rate_jiffies
= ptr
->delay
;
1898 *rate_jiffies
= frame
->delay
;
1899 release_icon_frame( ptr
, istep
, frame
);
1903 release_icon_ptr( hCursor
, ptr
);
1908 /**********************************************************************
1909 * GetIconInfo (USER32.@)
1911 BOOL WINAPI
GetIconInfo(HICON hIcon
, PICONINFO iconinfo
)
1915 infoW
.cbSize
= sizeof(infoW
);
1916 if (!GetIconInfoExW( hIcon
, &infoW
)) return FALSE
;
1917 iconinfo
->fIcon
= infoW
.fIcon
;
1918 iconinfo
->xHotspot
= infoW
.xHotspot
;
1919 iconinfo
->yHotspot
= infoW
.yHotspot
;
1920 iconinfo
->hbmColor
= infoW
.hbmColor
;
1921 iconinfo
->hbmMask
= infoW
.hbmMask
;
1925 /**********************************************************************
1926 * GetIconInfoExA (USER32.@)
1928 BOOL WINAPI
GetIconInfoExA( HICON icon
, ICONINFOEXA
*info
)
1932 if (info
->cbSize
!= sizeof(*info
))
1934 SetLastError( ERROR_INVALID_PARAMETER
);
1937 infoW
.cbSize
= sizeof(infoW
);
1938 if (!GetIconInfoExW( icon
, &infoW
)) return FALSE
;
1939 info
->fIcon
= infoW
.fIcon
;
1940 info
->xHotspot
= infoW
.xHotspot
;
1941 info
->yHotspot
= infoW
.yHotspot
;
1942 info
->hbmColor
= infoW
.hbmColor
;
1943 info
->hbmMask
= infoW
.hbmMask
;
1944 info
->wResID
= infoW
.wResID
;
1945 WideCharToMultiByte( CP_ACP
, 0, infoW
.szModName
, -1, info
->szModName
, MAX_PATH
, NULL
, NULL
);
1946 WideCharToMultiByte( CP_ACP
, 0, infoW
.szResName
, -1, info
->szResName
, MAX_PATH
, NULL
, NULL
);
1950 /**********************************************************************
1951 * GetIconInfoExW (USER32.@)
1953 BOOL WINAPI
GetIconInfoExW( HICON icon
, ICONINFOEXW
*info
)
1955 struct cursoricon_frame
*frame
;
1956 struct cursoricon_object
*ptr
;
1960 if (info
->cbSize
!= sizeof(*info
))
1962 SetLastError( ERROR_INVALID_PARAMETER
);
1965 if (!(ptr
= get_icon_ptr( icon
)))
1967 SetLastError( ERROR_INVALID_CURSOR_HANDLE
);
1971 frame
= get_icon_frame( ptr
, 0 );
1974 release_icon_ptr( icon
, ptr
);
1975 SetLastError( ERROR_INVALID_CURSOR_HANDLE
);
1979 TRACE("%p => %dx%d\n", icon
, frame
->width
, frame
->height
);
1981 info
->fIcon
= ptr
->is_icon
;
1982 info
->xHotspot
= ptr
->hotspot
.x
;
1983 info
->yHotspot
= ptr
->hotspot
.y
;
1984 info
->hbmColor
= copy_bitmap( frame
->color
);
1985 info
->hbmMask
= copy_bitmap( frame
->mask
);
1987 info
->szModName
[0] = 0;
1988 info
->szResName
[0] = 0;
1991 if (IS_INTRESOURCE( ptr
->resname
)) info
->wResID
= LOWORD( ptr
->resname
);
1992 else lstrcpynW( info
->szResName
, ptr
->resname
, MAX_PATH
);
1994 if (!info
->hbmMask
|| (!info
->hbmColor
&& frame
->color
))
1996 DeleteObject( info
->hbmMask
);
1997 DeleteObject( info
->hbmColor
);
2000 module
= ptr
->module
;
2001 release_icon_frame( ptr
, 0, frame
);
2002 release_icon_ptr( icon
, ptr
);
2003 if (ret
&& module
) GetModuleFileNameW( module
, info
->szModName
, MAX_PATH
);
2007 /* copy an icon bitmap, even when it can't be selected into a DC */
2008 /* helper for CreateIconIndirect */
2009 static void stretch_blt_icon( HDC hdc_dst
, int dst_x
, int dst_y
, int dst_width
, int dst_height
,
2010 HBITMAP src
, int width
, int height
)
2012 HDC hdc
= CreateCompatibleDC( 0 );
2014 if (!SelectObject( hdc
, src
)) /* do it the hard way */
2019 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) return;
2020 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
2021 info
->bmiHeader
.biWidth
= width
;
2022 info
->bmiHeader
.biHeight
= height
;
2023 info
->bmiHeader
.biPlanes
= GetDeviceCaps( hdc_dst
, PLANES
);
2024 info
->bmiHeader
.biBitCount
= GetDeviceCaps( hdc_dst
, BITSPIXEL
);
2025 info
->bmiHeader
.biCompression
= BI_RGB
;
2026 info
->bmiHeader
.biSizeImage
= height
* get_dib_width_bytes( width
, info
->bmiHeader
.biBitCount
);
2027 info
->bmiHeader
.biXPelsPerMeter
= 0;
2028 info
->bmiHeader
.biYPelsPerMeter
= 0;
2029 info
->bmiHeader
.biClrUsed
= 0;
2030 info
->bmiHeader
.biClrImportant
= 0;
2031 bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
);
2032 if (bits
&& GetDIBits( hdc
, src
, 0, height
, bits
, info
, DIB_RGB_COLORS
))
2033 StretchDIBits( hdc_dst
, dst_x
, dst_y
, dst_width
, dst_height
,
2034 0, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
2036 HeapFree( GetProcessHeap(), 0, bits
);
2037 HeapFree( GetProcessHeap(), 0, info
);
2039 else StretchBlt( hdc_dst
, dst_x
, dst_y
, dst_width
, dst_height
, hdc
, 0, 0, width
, height
, SRCCOPY
);
2044 /**********************************************************************
2045 * CreateIconIndirect (USER32.@)
2047 HICON WINAPI
CreateIconIndirect(PICONINFO iconinfo
)
2049 BITMAP bmpXor
, bmpAnd
;
2051 HBITMAP color
= 0, mask
;
2055 TRACE("color %p, mask %p, hotspot %ux%u, fIcon %d\n",
2056 iconinfo
->hbmColor
, iconinfo
->hbmMask
,
2057 iconinfo
->xHotspot
, iconinfo
->yHotspot
, iconinfo
->fIcon
);
2059 if (!iconinfo
->hbmMask
) return 0;
2061 GetObjectW( iconinfo
->hbmMask
, sizeof(bmpAnd
), &bmpAnd
);
2062 TRACE("mask: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
2063 bmpAnd
.bmWidth
, bmpAnd
.bmHeight
, bmpAnd
.bmWidthBytes
,
2064 bmpAnd
.bmPlanes
, bmpAnd
.bmBitsPixel
);
2066 if (iconinfo
->hbmColor
)
2068 GetObjectW( iconinfo
->hbmColor
, sizeof(bmpXor
), &bmpXor
);
2069 TRACE("color: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
2070 bmpXor
.bmWidth
, bmpXor
.bmHeight
, bmpXor
.bmWidthBytes
,
2071 bmpXor
.bmPlanes
, bmpXor
.bmBitsPixel
);
2073 width
= bmpXor
.bmWidth
;
2074 height
= bmpXor
.bmHeight
;
2075 if (bmpXor
.bmPlanes
* bmpXor
.bmBitsPixel
!= 1)
2077 color
= CreateCompatibleBitmap( screen_dc
, width
, height
);
2078 mask
= CreateBitmap( width
, height
, 1, 1, NULL
);
2080 else mask
= CreateBitmap( width
, height
* 2, 1, 1, NULL
);
2084 width
= bmpAnd
.bmWidth
;
2085 height
= bmpAnd
.bmHeight
;
2086 mask
= CreateBitmap( width
, height
, 1, 1, NULL
);
2089 hdc
= CreateCompatibleDC( 0 );
2090 SelectObject( hdc
, mask
);
2091 stretch_blt_icon( hdc
, 0, 0, width
, height
, iconinfo
->hbmMask
, bmpAnd
.bmWidth
, bmpAnd
.bmHeight
);
2095 SelectObject( hdc
, color
);
2096 stretch_blt_icon( hdc
, 0, 0, width
, height
, iconinfo
->hbmColor
, width
, height
);
2098 else if (iconinfo
->hbmColor
)
2100 stretch_blt_icon( hdc
, 0, height
, width
, height
, iconinfo
->hbmColor
, width
, height
);
2106 hObj
= alloc_icon_handle( FALSE
, 1 );
2109 struct cursoricon_object
*info
= get_icon_ptr( hObj
);
2110 struct cursoricon_frame
*frame
;
2112 info
->is_icon
= iconinfo
->fIcon
;
2113 frame
= get_icon_frame( info
, 0 );
2115 frame
->width
= width
;
2116 frame
->height
= height
;
2117 frame
->color
= color
;
2119 frame
->alpha
= create_alpha_bitmap( iconinfo
->hbmColor
, mask
, NULL
, NULL
);
2120 release_icon_frame( info
, 0, frame
);
2123 info
->hotspot
.x
= width
/ 2;
2124 info
->hotspot
.y
= height
/ 2;
2128 info
->hotspot
.x
= iconinfo
->xHotspot
;
2129 info
->hotspot
.y
= iconinfo
->yHotspot
;
2132 release_icon_ptr( hObj
, info
);
2133 USER_Driver
->pCreateCursorIcon( hObj
);
2138 /******************************************************************************
2139 * DrawIconEx (USER32.@) Draws an icon or cursor on device context
2142 * Why is this using SM_CXICON instead of SM_CXCURSOR?
2145 * hdc [I] Handle to device context
2146 * x0 [I] X coordinate of upper left corner
2147 * y0 [I] Y coordinate of upper left corner
2148 * hIcon [I] Handle to icon to draw
2149 * cxWidth [I] Width of icon
2150 * cyWidth [I] Height of icon
2151 * istep [I] Index of frame in animated cursor
2152 * hbr [I] Handle to background brush
2153 * flags [I] Icon-drawing flags
2159 BOOL WINAPI
DrawIconEx( HDC hdc
, INT x0
, INT y0
, HICON hIcon
,
2160 INT cxWidth
, INT cyWidth
, UINT istep
,
2161 HBRUSH hbr
, UINT flags
)
2163 struct cursoricon_frame
*frame
;
2164 struct cursoricon_object
*ptr
;
2165 HDC hdc_dest
, hMemDC
;
2166 BOOL result
= FALSE
, DoOffscreen
;
2168 COLORREF oldFg
, oldBg
;
2169 INT x
, y
, nStretchMode
;
2171 TRACE_(icon
)("(hdc=%p,pos=%d.%d,hicon=%p,extend=%d.%d,istep=%d,br=%p,flags=0x%08x)\n",
2172 hdc
,x0
,y0
,hIcon
,cxWidth
,cyWidth
,istep
,hbr
,flags
);
2174 if (!(ptr
= get_icon_ptr( hIcon
))) return FALSE
;
2175 if (istep
>= get_icon_steps( ptr
))
2177 TRACE_(icon
)("Stepped past end of animated frames=%d\n", istep
);
2178 release_icon_ptr( hIcon
, ptr
);
2181 if (!(frame
= get_icon_frame( ptr
, istep
)))
2183 FIXME_(icon
)("Error retrieving icon frame %d\n", istep
);
2184 release_icon_ptr( hIcon
, ptr
);
2187 if (!(hMemDC
= CreateCompatibleDC( hdc
)))
2189 release_icon_frame( ptr
, istep
, frame
);
2190 release_icon_ptr( hIcon
, ptr
);
2194 if (flags
& DI_NOMIRROR
)
2195 FIXME_(icon
)("Ignoring flag DI_NOMIRROR\n");
2197 /* Calculate the size of the destination image. */
2200 if (flags
& DI_DEFAULTSIZE
)
2201 cxWidth
= GetSystemMetrics (SM_CXICON
);
2203 cxWidth
= frame
->width
;
2207 if (flags
& DI_DEFAULTSIZE
)
2208 cyWidth
= GetSystemMetrics (SM_CYICON
);
2210 cyWidth
= frame
->height
;
2213 DoOffscreen
= (GetObjectType( hbr
) == OBJ_BRUSH
);
2223 if (!(hdc_dest
= CreateCompatibleDC(hdc
))) goto failed
;
2224 if (!(hB_off
= CreateCompatibleBitmap(hdc
, cxWidth
, cyWidth
)))
2226 DeleteDC( hdc_dest
);
2229 SelectObject(hdc_dest
, hB_off
);
2230 FillRect(hdc_dest
, &r
, hbr
);
2240 nStretchMode
= SetStretchBltMode (hdc
, STRETCH_DELETESCANS
);
2242 oldFg
= SetTextColor( hdc
, RGB(0,0,0) );
2243 oldBg
= SetBkColor( hdc
, RGB(255,255,255) );
2245 if (frame
->alpha
&& (flags
& DI_IMAGE
))
2247 BOOL is_mono
= FALSE
;
2249 if (GetObjectType( hdc_dest
) == OBJ_MEMDC
)
2252 HBITMAP bmp
= GetCurrentObject( hdc_dest
, OBJ_BITMAP
);
2253 is_mono
= GetObjectW( bmp
, sizeof(bm
), &bm
) && bm
.bmBitsPixel
== 1;
2257 BLENDFUNCTION pixelblend
= { AC_SRC_OVER
, 0, 255, AC_SRC_ALPHA
};
2258 SelectObject( hMemDC
, frame
->alpha
);
2259 if (GdiAlphaBlend( hdc_dest
, x
, y
, cxWidth
, cyWidth
, hMemDC
,
2260 0, 0, frame
->width
, frame
->height
,
2261 pixelblend
)) goto done
;
2265 if (flags
& DI_MASK
)
2267 SelectObject( hMemDC
, frame
->mask
);
2268 StretchBlt( hdc_dest
, x
, y
, cxWidth
, cyWidth
,
2269 hMemDC
, 0, 0, frame
->width
, frame
->height
, SRCAND
);
2272 if (flags
& DI_IMAGE
)
2276 DWORD rop
= (flags
& DI_MASK
) ? SRCINVERT
: SRCCOPY
;
2277 SelectObject( hMemDC
, frame
->color
);
2278 StretchBlt( hdc_dest
, x
, y
, cxWidth
, cyWidth
,
2279 hMemDC
, 0, 0, frame
->width
, frame
->height
, rop
);
2283 DWORD rop
= (flags
& DI_MASK
) ? SRCINVERT
: SRCCOPY
;
2284 SelectObject( hMemDC
, frame
->mask
);
2285 StretchBlt( hdc_dest
, x
, y
, cxWidth
, cyWidth
,
2286 hMemDC
, 0, frame
->height
, frame
->width
,
2287 frame
->height
, rop
);
2292 if (DoOffscreen
) BitBlt( hdc
, x0
, y0
, cxWidth
, cyWidth
, hdc_dest
, 0, 0, SRCCOPY
);
2294 SetTextColor( hdc
, oldFg
);
2295 SetBkColor( hdc
, oldBg
);
2296 SetStretchBltMode (hdc
, nStretchMode
);
2298 if (hdc_dest
!= hdc
) DeleteDC( hdc_dest
);
2299 if (hB_off
) DeleteObject(hB_off
);
2302 release_icon_frame( ptr
, istep
, frame
);
2303 release_icon_ptr( hIcon
, ptr
);
2307 /***********************************************************************
2308 * DIB_FixColorsToLoadflags
2310 * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
2313 static void DIB_FixColorsToLoadflags(BITMAPINFO
* bmi
, UINT loadflags
, BYTE pix
)
2316 COLORREF c_W
, c_S
, c_F
, c_L
, c_C
;
2325 if (((bitmap_type
= DIB_GetBitmapInfo((BITMAPINFOHEADER
*) bmi
, &width
, &height
, &bpp
, &compr
)) == -1))
2327 WARN_(resource
)("Invalid bitmap\n");
2331 if (bpp
> 8) return;
2333 if (bitmap_type
== 0) /* BITMAPCOREHEADER */
2341 colors
= bmi
->bmiHeader
.biClrUsed
;
2342 if (colors
> 256) colors
= 256;
2343 if (!colors
&& (bpp
<= 8)) colors
= 1 << bpp
;
2346 c_W
= GetSysColor(COLOR_WINDOW
);
2347 c_S
= GetSysColor(COLOR_3DSHADOW
);
2348 c_F
= GetSysColor(COLOR_3DFACE
);
2349 c_L
= GetSysColor(COLOR_3DLIGHT
);
2351 if (loadflags
& LR_LOADTRANSPARENT
) {
2353 case 1: pix
= pix
>> 7; break;
2354 case 4: pix
= pix
>> 4; break;
2357 WARN_(resource
)("(%d): Unsupported depth\n", bpp
);
2360 if (pix
>= colors
) {
2361 WARN_(resource
)("pixel has color index greater than biClrUsed!\n");
2364 if (loadflags
& LR_LOADMAP3DCOLORS
) c_W
= c_F
;
2365 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+pix
*incr
);
2366 ptr
->rgbBlue
= GetBValue(c_W
);
2367 ptr
->rgbGreen
= GetGValue(c_W
);
2368 ptr
->rgbRed
= GetRValue(c_W
);
2370 if (loadflags
& LR_LOADMAP3DCOLORS
)
2371 for (i
=0; i
<colors
; i
++) {
2372 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+i
*incr
);
2373 c_C
= RGB(ptr
->rgbRed
, ptr
->rgbGreen
, ptr
->rgbBlue
);
2374 if (c_C
== RGB(128, 128, 128)) {
2375 ptr
->rgbRed
= GetRValue(c_S
);
2376 ptr
->rgbGreen
= GetGValue(c_S
);
2377 ptr
->rgbBlue
= GetBValue(c_S
);
2378 } else if (c_C
== RGB(192, 192, 192)) {
2379 ptr
->rgbRed
= GetRValue(c_F
);
2380 ptr
->rgbGreen
= GetGValue(c_F
);
2381 ptr
->rgbBlue
= GetBValue(c_F
);
2382 } else if (c_C
== RGB(223, 223, 223)) {
2383 ptr
->rgbRed
= GetRValue(c_L
);
2384 ptr
->rgbGreen
= GetGValue(c_L
);
2385 ptr
->rgbBlue
= GetBValue(c_L
);
2391 /**********************************************************************
2394 static HBITMAP
BITMAP_Load( HINSTANCE instance
, LPCWSTR name
,
2395 INT desiredx
, INT desiredy
, UINT loadflags
)
2397 HBITMAP hbitmap
= 0, orig_bm
;
2401 BITMAPINFO
*info
, *fix_info
= NULL
, *scaled_info
= NULL
;
2405 LONG width
, height
, new_width
, new_height
;
2407 DWORD compr_dummy
, offbits
= 0;
2409 HDC screen_mem_dc
= NULL
;
2411 if (!(loadflags
& LR_LOADFROMFILE
))
2415 /* OEM bitmap: try to load the resource from user32.dll */
2416 instance
= user32_module
;
2419 if (!(hRsrc
= FindResourceW( instance
, name
, (LPWSTR
)RT_BITMAP
))) return 0;
2420 if (!(handle
= LoadResource( instance
, hRsrc
))) return 0;
2422 if ((info
= LockResource( handle
)) == NULL
) return 0;
2426 BITMAPFILEHEADER
* bmfh
;
2428 if (!(ptr
= map_fileW( name
, NULL
))) return 0;
2429 info
= (BITMAPINFO
*)(ptr
+ sizeof(BITMAPFILEHEADER
));
2430 bmfh
= (BITMAPFILEHEADER
*)ptr
;
2431 if (bmfh
->bfType
!= 0x4d42 /* 'BM' */)
2433 WARN("Invalid/unsupported bitmap format!\n");
2436 if (bmfh
->bfOffBits
) offbits
= bmfh
->bfOffBits
- sizeof(BITMAPFILEHEADER
);
2439 bm_type
= DIB_GetBitmapInfo( &info
->bmiHeader
, &width
, &height
,
2440 &bpp_dummy
, &compr_dummy
);
2443 WARN("Invalid bitmap format!\n");
2447 size
= bitmap_info_size(info
, DIB_RGB_COLORS
);
2448 fix_info
= HeapAlloc(GetProcessHeap(), 0, size
);
2449 scaled_info
= HeapAlloc(GetProcessHeap(), 0, size
);
2451 if (!fix_info
|| !scaled_info
) goto end
;
2452 memcpy(fix_info
, info
, size
);
2454 pix
= *((LPBYTE
)info
+ size
);
2455 DIB_FixColorsToLoadflags(fix_info
, loadflags
, pix
);
2457 memcpy(scaled_info
, fix_info
, size
);
2460 new_width
= desiredx
;
2465 new_height
= height
> 0 ? desiredy
: -desiredy
;
2467 new_height
= height
;
2471 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)&scaled_info
->bmiHeader
;
2472 core
->bcWidth
= new_width
;
2473 core
->bcHeight
= new_height
;
2477 /* Some sanity checks for BITMAPINFO (not applicable to BITMAPCOREINFO) */
2478 if (info
->bmiHeader
.biHeight
> 65535 || info
->bmiHeader
.biWidth
> 65535) {
2479 WARN("Broken BitmapInfoHeader!\n");
2483 scaled_info
->bmiHeader
.biWidth
= new_width
;
2484 scaled_info
->bmiHeader
.biHeight
= new_height
;
2487 if (new_height
< 0) new_height
= -new_height
;
2489 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
2490 if (!(screen_mem_dc
= CreateCompatibleDC( screen_dc
))) goto end
;
2492 bits
= (char *)info
+ (offbits
? offbits
: size
);
2494 if (loadflags
& LR_CREATEDIBSECTION
)
2496 scaled_info
->bmiHeader
.biCompression
= 0; /* DIBSection can't be compressed */
2497 hbitmap
= CreateDIBSection(screen_dc
, scaled_info
, DIB_RGB_COLORS
, NULL
, 0, 0);
2501 if (is_dib_monochrome(fix_info
))
2502 hbitmap
= CreateBitmap(new_width
, new_height
, 1, 1, NULL
);
2504 hbitmap
= CreateCompatibleBitmap(screen_dc
, new_width
, new_height
);
2507 orig_bm
= SelectObject(screen_mem_dc
, hbitmap
);
2508 StretchDIBits(screen_mem_dc
, 0, 0, new_width
, new_height
, 0, 0, width
, height
, bits
, fix_info
, DIB_RGB_COLORS
, SRCCOPY
);
2509 SelectObject(screen_mem_dc
, orig_bm
);
2512 if (screen_mem_dc
) DeleteDC(screen_mem_dc
);
2513 HeapFree(GetProcessHeap(), 0, scaled_info
);
2514 HeapFree(GetProcessHeap(), 0, fix_info
);
2515 if (loadflags
& LR_LOADFROMFILE
) UnmapViewOfFile( ptr
);
2520 /**********************************************************************
2521 * LoadImageA (USER32.@)
2525 HANDLE WINAPI
LoadImageA( HINSTANCE hinst
, LPCSTR name
, UINT type
,
2526 INT desiredx
, INT desiredy
, UINT loadflags
)
2531 if (IS_INTRESOURCE(name
))
2532 return LoadImageW(hinst
, (LPCWSTR
)name
, type
, desiredx
, desiredy
, loadflags
);
2535 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
2536 u_name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
2537 MultiByteToWideChar( CP_ACP
, 0, name
, -1, u_name
, len
);
2539 __EXCEPT_PAGE_FAULT
{
2540 SetLastError( ERROR_INVALID_PARAMETER
);
2544 res
= LoadImageW(hinst
, u_name
, type
, desiredx
, desiredy
, loadflags
);
2545 HeapFree(GetProcessHeap(), 0, u_name
);
2550 /******************************************************************************
2551 * LoadImageW (USER32.@) Loads an icon, cursor, or bitmap
2554 * hinst [I] Handle of instance that contains image
2555 * name [I] Name of image
2556 * type [I] Type of image
2557 * desiredx [I] Desired width
2558 * desiredy [I] Desired height
2559 * loadflags [I] Load flags
2562 * Success: Handle to newly loaded image
2565 * FIXME: Implementation lacks some features, see LR_ defines in winuser.h
2567 HANDLE WINAPI
LoadImageW( HINSTANCE hinst
, LPCWSTR name
, UINT type
,
2568 INT desiredx
, INT desiredy
, UINT loadflags
)
2570 TRACE_(resource
)("(%p,%s,%d,%d,%d,0x%08x)\n",
2571 hinst
,debugstr_w(name
),type
,desiredx
,desiredy
,loadflags
);
2573 if (loadflags
& LR_LOADFROMFILE
) loadflags
&= ~LR_SHARED
;
2576 return BITMAP_Load( hinst
, name
, desiredx
, desiredy
, loadflags
);
2579 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
2582 return CURSORICON_Load(hinst
, name
, desiredx
, desiredy
,
2583 GetDeviceCaps(screen_dc
, BITSPIXEL
),
2589 return CURSORICON_Load(hinst
, name
, desiredx
, desiredy
,
2590 1, TRUE
, loadflags
);
2595 /******************************************************************************
2596 * CopyImage (USER32.@) Creates new image and copies attributes to it
2599 * hnd [I] Handle to image to copy
2600 * type [I] Type of image to copy
2601 * desiredx [I] Desired width of new image
2602 * desiredy [I] Desired height of new image
2603 * flags [I] Copy flags
2606 * Success: Handle to newly created image
2610 * Only Windows NT 4.0 supports the LR_COPYRETURNORG flag for bitmaps,
2611 * all other versions (95/2000/XP have been tested) ignore it.
2614 * If LR_CREATEDIBSECTION is absent, the copy will be monochrome for
2615 * a monochrome source bitmap or if LR_MONOCHROME is present, otherwise
2616 * the copy will have the same depth as the screen.
2617 * The content of the image will only be copied if the bit depth of the
2618 * original image is compatible with the bit depth of the screen, or
2619 * if the source is a DIB section.
2620 * The LR_MONOCHROME flag is ignored if LR_CREATEDIBSECTION is present.
2622 HANDLE WINAPI
CopyImage( HANDLE hnd
, UINT type
, INT desiredx
,
2623 INT desiredy
, UINT flags
)
2625 TRACE("hnd=%p, type=%u, desiredx=%d, desiredy=%d, flags=%x\n",
2626 hnd
, type
, desiredx
, desiredy
, flags
);
2637 objSize
= GetObjectW( hnd
, sizeof(ds
), &ds
);
2638 if (!objSize
) return 0;
2639 if ((desiredx
< 0) || (desiredy
< 0)) return 0;
2641 if (flags
& LR_COPYFROMRESOURCE
)
2643 FIXME("The flag LR_COPYFROMRESOURCE is not implemented for bitmaps\n");
2646 if (desiredx
== 0) desiredx
= ds
.dsBm
.bmWidth
;
2647 if (desiredy
== 0) desiredy
= ds
.dsBm
.bmHeight
;
2649 /* Allocate memory for a BITMAPINFOHEADER structure and a
2650 color table. The maximum number of colors in a color table
2651 is 256 which corresponds to a bitmap with depth 8.
2652 Bitmaps with higher depths don't have color tables. */
2653 bi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
2656 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
2657 bi
->bmiHeader
.biPlanes
= ds
.dsBm
.bmPlanes
;
2658 bi
->bmiHeader
.biBitCount
= ds
.dsBm
.bmBitsPixel
;
2659 bi
->bmiHeader
.biCompression
= BI_RGB
;
2661 if (flags
& LR_CREATEDIBSECTION
)
2663 /* Create a DIB section. LR_MONOCHROME is ignored */
2665 HDC dc
= CreateCompatibleDC(NULL
);
2667 if (objSize
== sizeof(DIBSECTION
))
2669 /* The source bitmap is a DIB.
2670 Get its attributes to create an exact copy */
2671 memcpy(bi
, &ds
.dsBmih
, sizeof(BITMAPINFOHEADER
));
2674 /* Get the color table or the color masks */
2675 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2677 bi
->bmiHeader
.biWidth
= desiredx
;
2678 bi
->bmiHeader
.biHeight
= desiredy
;
2679 bi
->bmiHeader
.biSizeImage
= 0;
2681 res
= CreateDIBSection(dc
, bi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
2686 /* Create a device-dependent bitmap */
2688 BOOL monochrome
= (flags
& LR_MONOCHROME
);
2690 if (objSize
== sizeof(DIBSECTION
))
2692 /* The source bitmap is a DIB section.
2693 Get its attributes */
2694 HDC dc
= CreateCompatibleDC(NULL
);
2695 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
2696 bi
->bmiHeader
.biBitCount
= ds
.dsBm
.bmBitsPixel
;
2697 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2700 if (!monochrome
&& ds
.dsBm
.bmBitsPixel
== 1)
2702 /* Look if the colors of the DIB are black and white */
2705 (bi
->bmiColors
[0].rgbRed
== 0xff
2706 && bi
->bmiColors
[0].rgbGreen
== 0xff
2707 && bi
->bmiColors
[0].rgbBlue
== 0xff
2708 && bi
->bmiColors
[0].rgbReserved
== 0
2709 && bi
->bmiColors
[1].rgbRed
== 0
2710 && bi
->bmiColors
[1].rgbGreen
== 0
2711 && bi
->bmiColors
[1].rgbBlue
== 0
2712 && bi
->bmiColors
[1].rgbReserved
== 0)
2714 (bi
->bmiColors
[0].rgbRed
== 0
2715 && bi
->bmiColors
[0].rgbGreen
== 0
2716 && bi
->bmiColors
[0].rgbBlue
== 0
2717 && bi
->bmiColors
[0].rgbReserved
== 0
2718 && bi
->bmiColors
[1].rgbRed
== 0xff
2719 && bi
->bmiColors
[1].rgbGreen
== 0xff
2720 && bi
->bmiColors
[1].rgbBlue
== 0xff
2721 && bi
->bmiColors
[1].rgbReserved
== 0);
2724 else if (!monochrome
)
2726 monochrome
= ds
.dsBm
.bmBitsPixel
== 1;
2731 res
= CreateBitmap(desiredx
, desiredy
, 1, 1, NULL
);
2735 HDC screenDC
= GetDC(NULL
);
2736 res
= CreateCompatibleBitmap(screenDC
, desiredx
, desiredy
);
2737 ReleaseDC(NULL
, screenDC
);
2743 /* Only copy the bitmap if it's a DIB section or if it's
2744 compatible to the screen */
2747 if (objSize
== sizeof(DIBSECTION
))
2749 copyContents
= TRUE
;
2753 HDC screenDC
= GetDC(NULL
);
2754 int screen_depth
= GetDeviceCaps(screenDC
, BITSPIXEL
);
2755 ReleaseDC(NULL
, screenDC
);
2757 copyContents
= (ds
.dsBm
.bmBitsPixel
== 1 || ds
.dsBm
.bmBitsPixel
== screen_depth
);
2762 /* The source bitmap may already be selected in a device context,
2763 use GetDIBits/StretchDIBits and not StretchBlt */
2768 dc
= CreateCompatibleDC(NULL
);
2770 bi
->bmiHeader
.biWidth
= ds
.dsBm
.bmWidth
;
2771 bi
->bmiHeader
.biHeight
= ds
.dsBm
.bmHeight
;
2772 bi
->bmiHeader
.biSizeImage
= 0;
2773 bi
->bmiHeader
.biClrUsed
= 0;
2774 bi
->bmiHeader
.biClrImportant
= 0;
2776 /* Fill in biSizeImage */
2777 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2778 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, bi
->bmiHeader
.biSizeImage
);
2784 /* Get the image bits of the source bitmap */
2785 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, bits
, bi
, DIB_RGB_COLORS
);
2787 /* Copy it to the destination bitmap */
2788 oldBmp
= SelectObject(dc
, res
);
2789 StretchDIBits(dc
, 0, 0, desiredx
, desiredy
,
2790 0, 0, ds
.dsBm
.bmWidth
, ds
.dsBm
.bmHeight
,
2791 bits
, bi
, DIB_RGB_COLORS
, SRCCOPY
);
2792 SelectObject(dc
, oldBmp
);
2794 HeapFree(GetProcessHeap(), 0, bits
);
2800 if (flags
& LR_COPYDELETEORG
)
2805 HeapFree(GetProcessHeap(), 0, bi
);
2811 struct cursoricon_object
*icon
;
2813 int depth
= (flags
& LR_MONOCHROME
) ? 1 : GetDeviceCaps( screen_dc
, BITSPIXEL
);
2815 if (flags
& LR_DEFAULTSIZE
)
2817 if (!desiredx
) desiredx
= GetSystemMetrics( type
== IMAGE_ICON
? SM_CXICON
: SM_CXCURSOR
);
2818 if (!desiredy
) desiredy
= GetSystemMetrics( type
== IMAGE_ICON
? SM_CYICON
: SM_CYCURSOR
);
2821 if (!(icon
= get_icon_ptr( hnd
))) return 0;
2823 if (icon
->rsrc
&& (flags
& LR_COPYFROMRESOURCE
))
2824 res
= CURSORICON_Load( icon
->module
, icon
->resname
, desiredx
, desiredy
, depth
,
2825 type
== IMAGE_CURSOR
, flags
);
2827 res
= CopyIcon( hnd
); /* FIXME: change size if necessary */
2828 release_icon_ptr( hnd
, icon
);
2830 if (res
&& (flags
& LR_COPYDELETEORG
)) DeleteObject( hnd
);
2838 /******************************************************************************
2839 * LoadBitmapW (USER32.@) Loads bitmap from the executable file
2842 * Success: Handle to specified bitmap
2845 HBITMAP WINAPI
LoadBitmapW(
2846 HINSTANCE instance
, /* [in] Handle to application instance */
2847 LPCWSTR name
) /* [in] Address of bitmap resource name */
2849 return LoadImageW( instance
, name
, IMAGE_BITMAP
, 0, 0, 0 );
2852 /**********************************************************************
2853 * LoadBitmapA (USER32.@)
2857 HBITMAP WINAPI
LoadBitmapA( HINSTANCE instance
, LPCSTR name
)
2859 return LoadImageA( instance
, name
, IMAGE_BITMAP
, 0, 0, 0 );