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
27 #include <wine/debug.h>
29 WINE_DEFAULT_DEBUG_CHANNEL(cursor
);
30 WINE_DECLARE_DEBUG_CHANNEL(icon
);
31 WINE_DECLARE_DEBUG_CHANNEL(resource
);
44 } CURSORICONFILEDIRENTRY
;
51 CURSORICONFILEDIRENTRY idEntries
[1];
58 static const WCHAR DISPLAYW
[] = {'D','I','S','P','L','A','Y',0};
61 static CRITICAL_SECTION IconCrst
;
62 static CRITICAL_SECTION_DEBUG critsect_debug
=
65 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
66 0, 0, { (DWORD_PTR
)(__FILE__
": IconCrst") }
68 static CRITICAL_SECTION IconCrst
= { &critsect_debug
, -1, 0, 0, 0, 0 };
70 /***********************************************************************
71 * CreateCursorIconHandle
73 * Creates a handle with everything in there
77 CreateCursorIconHandle( PICONINFO IconInfo
)
79 HICON hIcon
= NtUserxCreateEmptyCurObject(0);
83 NtUserSetCursorContents(hIcon
, IconInfo
);
89 /***********************************************************************
92 * Helper function to map a file to memory:
94 * [RETURN] ptr - pointer to mapped file
95 * [RETURN] filesize - pointer size of file to be stored if not NULL
97 static void *map_fileW( LPCWSTR name
, LPDWORD filesize
)
99 HANDLE hFile
, hMapping
;
102 hFile
= CreateFileW( name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
103 OPEN_EXISTING
, FILE_FLAG_RANDOM_ACCESS
, 0 );
104 if (hFile
!= INVALID_HANDLE_VALUE
)
106 hMapping
= CreateFileMappingW( hFile
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
109 ptr
= MapViewOfFile( hMapping
, FILE_MAP_READ
, 0, 0, 0 );
110 CloseHandle( hMapping
);
112 *filesize
= GetFileSize( hFile
, NULL
);
114 CloseHandle( hFile
);
120 /***********************************************************************
121 * get_dib_width_bytes
123 * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
125 static int get_dib_width_bytes( int width
, int depth
)
131 case 1: words
= (width
+ 31) / 32; break;
132 case 4: words
= (width
+ 7) / 8; break;
133 case 8: words
= (width
+ 3) / 4; break;
135 case 16: words
= (width
+ 1) / 2; break;
136 case 24: words
= (width
* 3 + 3)/4; break;
138 WARN("(%d): Unsupported depth\n", depth
);
147 /***********************************************************************
150 * Return the size of the bitmap info structure including color table.
152 static int bitmap_info_size( const BITMAPINFO
* info
, WORD coloruse
)
154 unsigned int colors
, size
, masks
= 0;
156 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
158 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)info
;
159 colors
= (core
->bcBitCount
<= 8) ? 1 << core
->bcBitCount
: 0;
160 return sizeof(BITMAPCOREHEADER
) + colors
*
161 ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBTRIPLE
) : sizeof(WORD
));
163 else /* assume BITMAPINFOHEADER */
165 colors
= info
->bmiHeader
.biClrUsed
;
166 if (colors
> 256) /* buffer overflow otherwise */
168 if (!colors
&& (info
->bmiHeader
.biBitCount
<= 8))
169 colors
= 1 << info
->bmiHeader
.biBitCount
;
170 if (info
->bmiHeader
.biCompression
== BI_BITFIELDS
) masks
= 3;
171 size
= max( info
->bmiHeader
.biSize
, sizeof(BITMAPINFOHEADER
) + masks
* sizeof(DWORD
) );
172 return size
+ colors
* ((coloruse
== DIB_RGB_COLORS
) ? sizeof(RGBQUAD
) : sizeof(WORD
));
177 /***********************************************************************
180 * Returns whether a DIB can be converted to a monochrome DDB.
182 * A DIB can be converted if its color table contains only black and
183 * white. Black must be the first color in the color table.
185 * Note : If the first color in the color table is white followed by
186 * black, we can't convert it to a monochrome DDB with
187 * SetDIBits, because black and white would be inverted.
189 static BOOL
is_dib_monochrome( const BITMAPINFO
* info
)
191 if (info
->bmiHeader
.biBitCount
!= 1) return FALSE
;
193 if (info
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
195 const RGBTRIPLE
*rgb
= ((const BITMAPCOREINFO
*)info
)->bmciColors
;
197 /* Check if the first color is black */
198 if ((rgb
->rgbtRed
== 0) && (rgb
->rgbtGreen
== 0) && (rgb
->rgbtBlue
== 0))
202 /* Check if the second color is white */
203 return ((rgb
->rgbtRed
== 0xff) && (rgb
->rgbtGreen
== 0xff)
204 && (rgb
->rgbtBlue
== 0xff));
208 else /* assume BITMAPINFOHEADER */
210 const RGBQUAD
*rgb
= info
->bmiColors
;
212 /* Check if the first color is black */
213 if ((rgb
->rgbRed
== 0) && (rgb
->rgbGreen
== 0) &&
214 (rgb
->rgbBlue
== 0) && (rgb
->rgbReserved
== 0))
218 /* Check if the second color is white */
219 return ((rgb
->rgbRed
== 0xff) && (rgb
->rgbGreen
== 0xff)
220 && (rgb
->rgbBlue
== 0xff) && (rgb
->rgbReserved
== 0));
226 /***********************************************************************
229 * Get the info from a bitmap header.
230 * Return 1 for INFOHEADER, 0 for COREHEADER,
232 static int DIB_GetBitmapInfo( const BITMAPINFOHEADER
*header
, LONG
*width
,
233 LONG
*height
, WORD
*bpp
, DWORD
*compr
)
235 if (header
->biSize
== sizeof(BITMAPCOREHEADER
))
237 const BITMAPCOREHEADER
*core
= (const BITMAPCOREHEADER
*)header
;
238 *width
= core
->bcWidth
;
239 *height
= core
->bcHeight
;
240 *bpp
= core
->bcBitCount
;
244 else if (header
->biSize
== sizeof(BITMAPINFOHEADER
) ||
245 header
->biSize
== sizeof(BITMAPV4HEADER
) ||
246 header
->biSize
== sizeof(BITMAPV5HEADER
))
248 *width
= header
->biWidth
;
249 *height
= header
->biHeight
;
250 *bpp
= header
->biBitCount
;
251 *compr
= header
->biCompression
;
254 ERR("(%d): unknown/wrong size for header\n", header
->biSize
);
260 * The following macro functions account for the irregularities of
261 * accessing cursor and icon resources in files and resource entries.
263 typedef BOOL (*fnGetCIEntry
)( LPVOID dir
, int n
,
264 int *width
, int *height
, int *bits
);
266 /**********************************************************************
267 * CURSORICON_FindBestIcon
269 * Find the icon closest to the requested size and bit depth.
271 static int CURSORICON_FindBestIcon( LPVOID dir
, fnGetCIEntry get_entry
,
272 int width
, int height
, int depth
)
274 int i
, cx
, cy
, bits
, bestEntry
= -1;
275 UINT iTotalDiff
, iXDiff
=0, iYDiff
=0, iColorDiff
;
276 UINT iTempXDiff
, iTempYDiff
, iTempColorDiff
;
279 iTotalDiff
= 0xFFFFFFFF;
280 iColorDiff
= 0xFFFFFFFF;
281 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
283 iTempXDiff
= abs(width
- cx
);
284 iTempYDiff
= abs(height
- cy
);
286 if(iTotalDiff
> (iTempXDiff
+ iTempYDiff
))
290 iTotalDiff
= iXDiff
+ iYDiff
;
294 /* Find Best Colors for Best Fit */
295 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
297 if(abs(width
- cx
) == iXDiff
&& abs(height
- cy
) == iYDiff
)
299 iTempColorDiff
= abs(depth
- bits
);
300 if(iColorDiff
> iTempColorDiff
)
303 iColorDiff
= iTempColorDiff
;
311 static BOOL
CURSORICON_GetResIconEntry( LPVOID dir
, int n
,
312 int *width
, int *height
, int *bits
)
314 CURSORICONDIR
*resdir
= dir
;
317 if ( resdir
->idCount
<= n
)
319 icon
= &resdir
->idEntries
[n
].ResInfo
.icon
;
320 *width
= icon
->bWidth
;
321 *height
= icon
->bHeight
;
322 *bits
= resdir
->idEntries
[n
].wBitCount
;
326 /**********************************************************************
327 * CURSORICON_FindBestCursor
329 * Find the cursor closest to the requested size.
331 * FIXME: parameter 'color' ignored.
333 static int CURSORICON_FindBestCursor( LPVOID dir
, fnGetCIEntry get_entry
,
334 int width
, int height
, int depth
)
336 int i
, maxwidth
, maxheight
, cx
, cy
, bits
, bestEntry
= -1;
338 /* Double height to account for AND and XOR masks */
342 /* First find the largest one smaller than or equal to the requested size*/
344 maxwidth
= maxheight
= 0;
345 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
347 if ((cx
<= width
) && (cy
<= height
) &&
348 (cx
> maxwidth
) && (cy
> maxheight
))
355 if (bestEntry
!= -1) return bestEntry
;
357 /* Now find the smallest one larger than the requested size */
359 maxwidth
= maxheight
= 255;
360 for ( i
= 0; get_entry( dir
, i
, &cx
, &cy
, &bits
); i
++ )
362 if (((cx
< maxwidth
) && (cy
< maxheight
)) || (bestEntry
== -1))
373 static BOOL
CURSORICON_GetResCursorEntry( LPVOID dir
, int n
,
374 int *width
, int *height
, int *bits
)
376 CURSORICONDIR
*resdir
= dir
;
379 if ( resdir
->idCount
<= n
)
381 cursor
= &resdir
->idEntries
[n
].ResInfo
.cursor
;
382 *width
= cursor
->wWidth
;
383 *height
= cursor
->wHeight
;
384 *bits
= resdir
->idEntries
[n
].wBitCount
;
388 static CURSORICONDIRENTRY
*CURSORICON_FindBestIconRes( CURSORICONDIR
* dir
,
389 int width
, int height
, int depth
)
393 n
= CURSORICON_FindBestIcon( dir
, CURSORICON_GetResIconEntry
,
394 width
, height
, depth
);
397 return &dir
->idEntries
[n
];
400 static CURSORICONDIRENTRY
*CURSORICON_FindBestCursorRes( CURSORICONDIR
*dir
,
401 int width
, int height
, int depth
)
403 int n
= CURSORICON_FindBestCursor( dir
, CURSORICON_GetResCursorEntry
,
404 width
, height
, depth
);
407 return &dir
->idEntries
[n
];
410 static BOOL
CURSORICON_GetFileEntry( LPVOID dir
, int n
,
411 int *width
, int *height
, int *bits
)
413 CURSORICONFILEDIR
*filedir
= dir
;
414 CURSORICONFILEDIRENTRY
*entry
;
415 BITMAPINFOHEADER
*info
;
417 if ( filedir
->idCount
<= n
)
419 entry
= &filedir
->idEntries
[n
];
420 /* FIXME: check against file size */
421 info
= (BITMAPINFOHEADER
*)((char *)dir
+ entry
->dwDIBOffset
);
422 *width
= entry
->bWidth
;
423 *height
= entry
->bHeight
;
424 *bits
= info
->biBitCount
;
428 static CURSORICONFILEDIRENTRY
*CURSORICON_FindBestCursorFile( CURSORICONFILEDIR
*dir
,
429 int width
, int height
, int depth
)
431 int n
= CURSORICON_FindBestCursor( dir
, CURSORICON_GetFileEntry
,
432 width
, height
, depth
);
435 return &dir
->idEntries
[n
];
438 static CURSORICONFILEDIRENTRY
*CURSORICON_FindBestIconFile( CURSORICONFILEDIR
*dir
,
439 int width
, int height
, int depth
)
441 int n
= CURSORICON_FindBestIcon( dir
, CURSORICON_GetFileEntry
,
442 width
, height
, depth
);
445 return &dir
->idEntries
[n
];
448 /***********************************************************************
449 * create_icon_bitmaps
451 * Create the color, mask and alpha bitmaps from the DIB info.
453 static BOOL
create_icon_bitmaps( const BITMAPINFO
*bmi
, int width
, int height
,
454 HBITMAP
*color
, HBITMAP
*mask
)
456 BOOL monochrome
= is_dib_monochrome( bmi
);
457 unsigned int size
= bitmap_info_size( bmi
, DIB_RGB_COLORS
);
459 void *color_bits
, *mask_bits
;
463 if (!(info
= HeapAlloc( GetProcessHeap(), 0, max( size
, FIELD_OFFSET( BITMAPINFO
, bmiColors
[2] )))))
465 if (!(hdc
= CreateCompatibleDC(NULL
))) goto done
;
467 memcpy( info
, bmi
, size
);
468 info
->bmiHeader
.biHeight
/= 2;
470 color_bits
= (char *)bmi
+ size
;
471 mask_bits
= (char *)color_bits
+
472 get_dib_width_bytes( bmi
->bmiHeader
.biWidth
,
473 bmi
->bmiHeader
.biBitCount
) * abs(info
->bmiHeader
.biHeight
);
477 if (!(*mask
= CreateBitmap( width
, height
* 2, 1, 1, NULL
))) goto done
;
480 /* copy color data into second half of mask bitmap */
481 SelectObject( hdc
, *mask
);
482 StretchDIBits( hdc
, 0, height
, width
, height
,
483 0, 0, info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
,
484 color_bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
488 if (!(*mask
= CreateBitmap( width
, height
, 1, 1, NULL
))) goto done
;
489 if (!(*color
= CreateBitmap( width
, height
, GetDeviceCaps(hdc
, PLANES
),
490 GetDeviceCaps(hdc
, BITSPIXEL
), NULL
)))
492 DeleteObject( *mask
);
495 SelectObject( hdc
, *color
);
496 StretchDIBits( hdc
, 0, 0, width
, height
,
497 0, 0, info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
,
498 color_bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
500 /* convert info to monochrome to copy the mask */
501 info
->bmiHeader
.biBitCount
= 1;
502 if (info
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
))
504 RGBQUAD
*rgb
= info
->bmiColors
;
506 info
->bmiHeader
.biClrUsed
= info
->bmiHeader
.biClrImportant
= 2;
507 rgb
[0].rgbBlue
= rgb
[0].rgbGreen
= rgb
[0].rgbRed
= 0x00;
508 rgb
[1].rgbBlue
= rgb
[1].rgbGreen
= rgb
[1].rgbRed
= 0xff;
509 rgb
[0].rgbReserved
= rgb
[1].rgbReserved
= 0;
513 RGBTRIPLE
*rgb
= (RGBTRIPLE
*)(((BITMAPCOREHEADER
*)info
) + 1);
515 rgb
[0].rgbtBlue
= rgb
[0].rgbtGreen
= rgb
[0].rgbtRed
= 0x00;
516 rgb
[1].rgbtBlue
= rgb
[1].rgbtGreen
= rgb
[1].rgbtRed
= 0xff;
520 SelectObject( hdc
, *mask
);
521 StretchDIBits( hdc
, 0, 0, width
, height
,
522 0, 0, info
->bmiHeader
.biWidth
, info
->bmiHeader
.biHeight
,
523 mask_bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
527 if(hdc
) DeleteDC( hdc
);
528 HeapFree( GetProcessHeap(), 0, info
);
532 static HICON
CURSORICON_CreateIconFromBMI( BITMAPINFO
*bmi
,
533 POINT hotspot
, BOOL bIcon
,
535 INT width
, INT height
,
538 HBITMAP color
= 0, mask
= 0;
542 if (dwVersion
== 0x00020000)
544 FIXME_(cursor
)("\t2.xx resources are not supported\n");
548 /* Check bitmap header */
550 if ( (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) &&
551 (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) ||
552 bmi
->bmiHeader
.biCompression
!= BI_RGB
) )
554 WARN_(cursor
)("\tinvalid resource bitmap header.\n");
558 if (!width
) width
= bmi
->bmiHeader
.biWidth
;
559 if (!height
) height
= bmi
->bmiHeader
.biHeight
/2;
560 do_stretch
= (bmi
->bmiHeader
.biHeight
/2 != height
) ||
561 (bmi
->bmiHeader
.biWidth
!= width
);
563 /* Scale the hotspot */
566 hotspot
.x
= width
/ 2;
567 hotspot
.y
= height
/ 2;
571 hotspot
.x
= (hotspot
.x
* width
) / bmi
->bmiHeader
.biWidth
;
572 hotspot
.y
= (hotspot
.y
* height
) / (bmi
->bmiHeader
.biHeight
/ 2);
575 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
576 if (!screen_dc
) return 0;
578 if (!create_icon_bitmaps( bmi
, width
, height
, &color
, &mask
)) return 0;
580 IconInfo
.xHotspot
= hotspot
.x
;
581 IconInfo
.yHotspot
= hotspot
.y
;
582 IconInfo
.fIcon
= bIcon
;
583 IconInfo
.hbmColor
= color
;
584 IconInfo
.hbmMask
= mask
;
586 return CreateCursorIconHandle(&IconInfo
);
590 /**********************************************************************
591 * .ANI cursor support
593 #define RIFF_FOURCC( c0, c1, c2, c3 ) \
594 ( (DWORD)(BYTE)(c0) | ( (DWORD)(BYTE)(c1) << 8 ) | \
595 ( (DWORD)(BYTE)(c2) << 16 ) | ( (DWORD)(BYTE)(c3) << 24 ) )
597 #define ANI_RIFF_ID RIFF_FOURCC('R', 'I', 'F', 'F')
598 #define ANI_LIST_ID RIFF_FOURCC('L', 'I', 'S', 'T')
599 #define ANI_ACON_ID RIFF_FOURCC('A', 'C', 'O', 'N')
600 #define ANI_anih_ID RIFF_FOURCC('a', 'n', 'i', 'h')
601 #define ANI_seq__ID RIFF_FOURCC('s', 'e', 'q', ' ')
602 #define ANI_fram_ID RIFF_FOURCC('f', 'r', 'a', 'm')
604 #define ANI_FLAG_ICON 0x1
605 #define ANI_FLAG_SEQUENCE 0x2
621 const unsigned char *data
;
624 static void dump_ani_header( const ani_header
*header
)
626 TRACE(" header size: %d\n", header
->header_size
);
627 TRACE(" frames: %d\n", header
->num_frames
);
628 TRACE(" steps: %d\n", header
->num_steps
);
629 TRACE(" width: %d\n", header
->width
);
630 TRACE(" height: %d\n", header
->height
);
631 TRACE(" bpp: %d\n", header
->bpp
);
632 TRACE(" planes: %d\n", header
->num_planes
);
633 TRACE(" display rate: %d\n", header
->display_rate
);
634 TRACE(" flags: 0x%08x\n", header
->flags
);
656 static void riff_find_chunk( DWORD chunk_id
, DWORD chunk_type
, const riff_chunk_t
*parent_chunk
, riff_chunk_t
*chunk
)
658 const unsigned char *ptr
= parent_chunk
->data
;
659 const unsigned char *end
= parent_chunk
->data
+ (parent_chunk
->data_size
- (2 * sizeof(DWORD
)));
661 if (chunk_type
== ANI_LIST_ID
|| chunk_type
== ANI_RIFF_ID
) end
-= sizeof(DWORD
);
665 if ((!chunk_type
&& *(const DWORD
*)ptr
== chunk_id
)
666 || (chunk_type
&& *(const DWORD
*)ptr
== chunk_type
&& *((const DWORD
*)ptr
+ 2) == chunk_id
))
668 ptr
+= sizeof(DWORD
);
669 chunk
->data_size
= (*(const DWORD
*)ptr
+ 1) & ~1;
670 ptr
+= sizeof(DWORD
);
671 if (chunk_type
== ANI_LIST_ID
|| chunk_type
== ANI_RIFF_ID
) ptr
+= sizeof(DWORD
);
677 ptr
+= sizeof(DWORD
);
678 ptr
+= (*(const DWORD
*)ptr
+ 1) & ~1;
679 ptr
+= sizeof(DWORD
);
687 * RIFF:'ACON' RIFF chunk
688 * |- CHUNK:'anih' Header
689 * |- CHUNK:'seq ' Sequence information (optional)
690 * \- LIST:'fram' Frame list
691 * |- CHUNK:icon Cursor frames
696 static HCURSOR
CURSORICON_CreateIconFromANI( const LPBYTE bits
, DWORD bits_size
,
697 INT width
, INT height
, INT depth
)
700 ani_header header
= {0};
701 LPBYTE frame_bits
= 0;
703 CURSORICONFILEDIRENTRY
*entry
;
705 riff_chunk_t root_chunk
= { bits_size
, bits
};
706 riff_chunk_t ACON_chunk
= {0};
707 riff_chunk_t anih_chunk
= {0};
708 riff_chunk_t fram_chunk
= {0};
709 const unsigned char *icon_data
;
711 TRACE("bits %p, bits_size %d\n", bits
, bits_size
);
715 riff_find_chunk( ANI_ACON_ID
, ANI_RIFF_ID
, &root_chunk
, &ACON_chunk
);
716 if (!ACON_chunk
.data
)
718 ERR("Failed to get root chunk.\n");
722 riff_find_chunk( ANI_anih_ID
, 0, &ACON_chunk
, &anih_chunk
);
723 if (!anih_chunk
.data
)
725 ERR("Failed to get 'anih' chunk.\n");
728 memcpy( &header
, anih_chunk
.data
, sizeof(header
) );
729 dump_ani_header( &header
);
731 riff_find_chunk( ANI_fram_ID
, ANI_LIST_ID
, &ACON_chunk
, &fram_chunk
);
732 if (!fram_chunk
.data
)
734 ERR("Failed to get icon list.\n");
738 /* FIXME: For now, just load the first frame. Before we can load all the
739 * frames, we need to write the needed code in wineserver, etc. to handle
740 * cursors. Once this code is written, we can extend it to support .ani
741 * cursors and then update user32 and winex11.drv to load all frames.
743 * Hopefully this will at least make some games (C&C3, etc.) more playable
746 FIXME("Loading all frames for .ani cursors not implemented.\n");
747 icon_data
= fram_chunk
.data
+ (2 * sizeof(DWORD
));
749 entry
= CURSORICON_FindBestIconFile( (CURSORICONFILEDIR
*) icon_data
,
750 width
, height
, depth
);
752 frame_bits
= HeapAlloc( GetProcessHeap(), 0, entry
->dwDIBSize
);
753 memcpy( frame_bits
, icon_data
+ entry
->dwDIBOffset
, entry
->dwDIBSize
);
755 if (!header
.width
|| !header
.height
)
757 header
.width
= entry
->bWidth
;
758 header
.height
= entry
->bHeight
;
761 hotspot
.x
= entry
->xHotspot
;
762 hotspot
.y
= entry
->yHotspot
;
764 cursor
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*) frame_bits
, hotspot
,
765 FALSE
, 0x00030000, header
.width
, header
.height
, 0 );
767 HeapFree( GetProcessHeap(), 0, frame_bits
);
773 /**********************************************************************
774 * CreateIconFromResourceEx (USER32.@)
776 * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
777 * with cbSize parameter as well.
779 HICON WINAPI
CreateIconFromResourceEx( PBYTE bits
, DWORD cbSize
,
780 BOOL bIcon
, DWORD dwVersion
,
781 int width
, int height
,
787 TRACE_(cursor
)("%p (%u bytes), ver %08x, %ix%i %s %s\n",
788 bits
, cbSize
, dwVersion
, width
, height
,
789 bIcon
? "icon" : "cursor", (cFlag
& LR_MONOCHROME
) ? "mono" : "" );
793 hotspot
.x
= width
/ 2;
794 hotspot
.y
= height
/ 2;
795 bmi
= (BITMAPINFO
*)bits
;
797 else /* get the hotspot */
799 SHORT
*pt
= (SHORT
*)bits
;
802 bmi
= (BITMAPINFO
*)(pt
+ 2);
805 return CURSORICON_CreateIconFromBMI( bmi
, hotspot
, bIcon
, dwVersion
,
806 width
, height
, cFlag
);
810 /**********************************************************************
811 * CreateIconFromResource (USER32.@)
813 HICON WINAPI
CreateIconFromResource( PBYTE bits
, DWORD cbSize
,
814 BOOL bIcon
, DWORD dwVersion
)
816 return CreateIconFromResourceEx( bits
, cbSize
, bIcon
, dwVersion
, 0,0,0);
820 static HICON
CURSORICON_LoadFromFile( LPCWSTR filename
,
821 INT width
, INT height
, INT depth
,
822 BOOL fCursor
, UINT loadflags
)
824 CURSORICONFILEDIRENTRY
*entry
;
825 CURSORICONFILEDIR
*dir
;
831 TRACE("loading %s\n", debugstr_w( filename
));
833 bits
= map_fileW( filename
, &filesize
);
837 /* Check for .ani. */
838 if (memcmp( bits
, "RIFF", 4 ) == 0)
840 hIcon
= CURSORICON_CreateIconFromANI( bits
, filesize
, width
, height
,
845 dir
= (CURSORICONFILEDIR
*) bits
;
846 if ( filesize
< sizeof(*dir
) )
849 if ( filesize
< (sizeof(*dir
) + sizeof(dir
->idEntries
[0])*(dir
->idCount
-1)) )
853 entry
= CURSORICON_FindBestCursorFile( dir
, width
, height
, depth
);
855 entry
= CURSORICON_FindBestIconFile( dir
, width
, height
, depth
);
860 /* check that we don't run off the end of the file */
861 if ( entry
->dwDIBOffset
> filesize
)
863 if ( entry
->dwDIBOffset
+ entry
->dwDIBSize
> filesize
)
866 hotspot
.x
= entry
->xHotspot
;
867 hotspot
.y
= entry
->yHotspot
;
868 hIcon
= CURSORICON_CreateIconFromBMI( (BITMAPINFO
*)&bits
[entry
->dwDIBOffset
],
869 hotspot
, !fCursor
, 0x00030000,
870 width
, height
, loadflags
);
872 TRACE("loaded %s -> %p\n", debugstr_w( filename
), hIcon
);
873 UnmapViewOfFile( bits
);
877 /**********************************************************************
880 * Load a cursor or icon from resource or file.
882 static HICON
CURSORICON_Load(HINSTANCE hInstance
, LPCWSTR name
,
883 INT width
, INT height
, INT depth
,
884 BOOL fCursor
, UINT loadflags
)
891 CURSORICONDIRENTRY
*dirEntry
;
896 TRACE("%p, %s, %dx%d, depth %d, fCursor %d, flags 0x%04x\n",
897 hInstance
, debugstr_w(name
), width
, height
, depth
, fCursor
, loadflags
);
899 if ( loadflags
& LR_LOADFROMFILE
) /* Load from file */
900 return CURSORICON_LoadFromFile( name
, width
, height
, depth
, fCursor
, loadflags
);
902 if (!hInstance
) hInstance
= User32Instance
; /* Load OEM cursor/icon */
904 /* don't cache 16-bit instances (FIXME: should never get 16-bit instances in the first place) */
905 if ((ULONG_PTR
)hInstance
>> 16 == 0) loadflags
&= ~LR_SHARED
;
907 /* Get directory resource ID */
909 if (!(hRsrc
= FindResourceW( hInstance
, name
,
910 (LPWSTR
)(fCursor
? RT_GROUP_CURSOR
: RT_GROUP_ICON
) )))
912 //hGroupRsrc = hRsrc;
914 /* Find the best entry in the directory */
916 if (!(handle
= LoadResource( hInstance
, hRsrc
))) return 0;
917 if (!(dir
= LockResource( handle
))) return 0;
919 dirEntry
= CURSORICON_FindBestCursorRes( dir
, width
, height
, depth
);
921 dirEntry
= CURSORICON_FindBestIconRes( dir
, width
, height
, depth
);
922 if (!dirEntry
) return 0;
923 wResId
= dirEntry
->wResId
;
924 dwBytesInRes
= dirEntry
->dwBytesInRes
;
925 FreeResource( handle
);
927 /* Load the resource */
929 if (!(hRsrc
= FindResourceW(hInstance
,MAKEINTRESOURCEW(wResId
),
930 (LPWSTR
)(fCursor
? RT_CURSOR
: RT_ICON
) ))) return 0;
932 /* If shared icon, check whether it was already loaded */
933 if ( (loadflags
& LR_SHARED
)
934 && (hIcon
= NtUserFindExistingCursorIcon( hInstance
, hRsrc
, 0, 0 ) ) != 0 )
937 if (!(handle
= LoadResource( hInstance
, hRsrc
))) return 0;
938 bits
= LockResource( handle
);
939 hIcon
= CreateIconFromResourceEx( bits
, dwBytesInRes
,
940 !fCursor
, 0x00030000, width
, height
, loadflags
);
941 FreeResource( handle
);
943 /* If shared icon, add to icon cache */
945 if (hIcon
&& 0 != (loadflags
& LR_SHARED
))
948 NtUserSetCursorIconData((HICON
)hIcon
, NULL
, NULL
, hInstance
, hRsrc
,
953 if(NtUserGetIconInfo(ResIcon
, &iconInfo
, NULL
, NULL
, NULL
, FALSE
))
954 NtUserSetCursorIconData((HICON
)hIcon
, hinst
, NULL
, &iconInfo
);
962 /*************************************************************************
965 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified
968 * Handle [I] handle to an Image
969 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON)
970 * iDesiredCX [I] The Desired width of the Image
971 * iDesiredCY [I] The desired height of the Image
972 * nFlags [I] The flags from CopyImage
975 * Success: The new handle of the Image
978 * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented.
979 * LR_MONOCHROME should be implemented by CreateIconFromResourceEx.
980 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache.
985 static HICON
CURSORICON_ExtCopy(HICON hIcon
, UINT nType
,
986 INT iDesiredCX
, INT iDesiredCY
,
991 TRACE_(icon
)("hIcon %p, nType %u, iDesiredCX %i, iDesiredCY %i, nFlags %u\n",
992 hIcon
, nType
, iDesiredCX
, iDesiredCY
, nFlags
);
999 /* Best Fit or Monochrome */
1000 if( (nFlags
& LR_COPYFROMRESOURCE
1001 && (iDesiredCX
> 0 || iDesiredCY
> 0))
1002 || nFlags
& LR_MONOCHROME
)
1004 TRACE("Copying from resource isn't implemented yet\n");
1005 hNew
= CopyIcon(hIcon
);
1008 ICONCACHE
* pIconCache
= CURSORICON_FindCache(hIcon
);
1010 /* Not Found in Cache, then do a straight copy
1012 if(pIconCache
== NULL
)
1014 hNew
= CopyIcon( hIcon
);
1015 if(nFlags
& LR_COPYFROMRESOURCE
)
1017 TRACE_(icon
)("LR_COPYFROMRESOURCE: Failed to load from cache\n");
1022 int iTargetCY
= iDesiredCY
, iTargetCX
= iDesiredCX
;
1028 CURSORICONDIR
*pDir
;
1029 CURSORICONDIRENTRY
*pDirEntry
;
1030 BOOL bIsIcon
= (nType
== IMAGE_ICON
);
1032 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
1034 if(((nFlags
& LR_MONOCHROME
) && !(nFlags
& LR_COPYFROMRESOURCE
))
1035 || (iDesiredCX
== 0 && iDesiredCY
== 0))
1037 iDesiredCY
= GetSystemMetrics(bIsIcon
?
1038 SM_CYICON
: SM_CYCURSOR
);
1039 iDesiredCX
= GetSystemMetrics(bIsIcon
?
1040 SM_CXICON
: SM_CXCURSOR
);
1043 /* Retrieve the CURSORICONDIRENTRY
1045 if (!(hMem
= LoadResource( pIconCache
->hModule
,
1046 pIconCache
->hGroupRsrc
)))
1050 if (!(pDir
= LockResource( hMem
)))
1059 pDirEntry
= CURSORICON_FindBestIconRes(
1060 pDir
, iDesiredCX
, iDesiredCY
, 256 );
1064 pDirEntry
= CURSORICON_FindBestCursorRes(
1065 pDir
, iDesiredCX
, iDesiredCY
, 1);
1068 wResId
= pDirEntry
->wResId
;
1069 dwBytesInRes
= pDirEntry
->dwBytesInRes
;
1072 TRACE_(icon
)("ResID %u, BytesInRes %u, Width %d, Height %d DX %d, DY %d\n",
1073 wResId
, dwBytesInRes
, pDirEntry
->ResInfo
.icon
.bWidth
,
1074 pDirEntry
->ResInfo
.icon
.bHeight
, iDesiredCX
, iDesiredCY
);
1078 if (!(hRsrc
= FindResourceW(pIconCache
->hModule
,
1079 MAKEINTRESOURCEW(wResId
), (LPWSTR
)(bIsIcon
? RT_ICON
: RT_CURSOR
))))
1083 if (!(hMem
= LoadResource( pIconCache
->hModule
, hRsrc
)))
1088 pBits
= LockResource( hMem
);
1090 if(nFlags
& LR_DEFAULTSIZE
)
1092 iTargetCY
= GetSystemMetrics(SM_CYICON
);
1093 iTargetCX
= GetSystemMetrics(SM_CXICON
);
1096 /* Create a New Icon with the proper dimension
1098 hNew
= CreateIconFromResourceEx( pBits
, dwBytesInRes
,
1099 bIsIcon
, 0x00030000, iTargetCX
, iTargetCY
, nFlags
);
1104 else hNew
= CopyIcon( hIcon
);
1109 /***********************************************************************
1110 * CreateCursor (USER32.@)
1112 HCURSOR WINAPI
CreateCursor( HINSTANCE hInstance
,
1113 INT xHotSpot
, INT yHotSpot
,
1114 INT nWidth
, INT nHeight
,
1115 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
1120 TRACE_(cursor
)("%dx%d spot=%d,%d xor=%p and=%p\n",
1121 nWidth
, nHeight
, xHotSpot
, yHotSpot
, lpXORbits
, lpANDbits
);
1124 info
.xHotspot
= xHotSpot
;
1125 info
.yHotspot
= yHotSpot
;
1126 info
.hbmMask
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpANDbits
);
1127 info
.hbmColor
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpXORbits
);
1128 hCursor
= CreateIconIndirect( &info
);
1129 DeleteObject( info
.hbmMask
);
1130 DeleteObject( info
.hbmColor
);
1135 /***********************************************************************
1136 * CreateIcon (USER32.@)
1138 * Creates an icon based on the specified bitmaps. The bitmaps must be
1139 * provided in a device dependent format and will be resized to
1140 * (SM_CXICON,SM_CYICON) and depth converted to match the screen's color
1141 * depth. The provided bitmaps must be top-down bitmaps.
1142 * Although Windows does not support 15bpp(*) this API must support it
1143 * for Winelib applications.
1145 * (*) Windows does not support 15bpp but it supports the 555 RGB 16bpp
1149 * Success: handle to an icon
1152 * FIXME: Do we need to resize the bitmaps?
1154 HICON WINAPI
CreateIcon(
1155 HINSTANCE hInstance
, /* [in] the application's hInstance */
1156 int nWidth
, /* [in] the width of the provided bitmaps */
1157 int nHeight
, /* [in] the height of the provided bitmaps */
1158 BYTE bPlanes
, /* [in] the number of planes in the provided bitmaps */
1159 BYTE bBitsPixel
, /* [in] the number of bits per pixel of the lpXORbits bitmap */
1160 const BYTE
* lpANDbits
, /* [in] a monochrome bitmap representing the icon's mask */
1161 const BYTE
* lpXORbits
) /* [in] the icon's 'color' bitmap */
1166 TRACE_(icon
)("%dx%d, planes %d, bpp %d, xor %p, and %p\n",
1167 nWidth
, nHeight
, bPlanes
, bBitsPixel
, lpXORbits
, lpANDbits
);
1170 iinfo
.xHotspot
= nWidth
/ 2;
1171 iinfo
.yHotspot
= nHeight
/ 2;
1172 if (bPlanes
* bBitsPixel
> 1)
1174 iinfo
.hbmColor
= CreateBitmap( nWidth
, nHeight
, bPlanes
, bBitsPixel
, lpXORbits
);
1175 iinfo
.hbmMask
= CreateBitmap( nWidth
, nHeight
, 1, 1, lpANDbits
);
1179 iinfo
.hbmMask
= CreateBitmap( nWidth
, nHeight
* 2, 1, 1, lpANDbits
);
1180 iinfo
.hbmColor
= NULL
;
1183 hIcon
= CreateIconIndirect( &iinfo
);
1185 DeleteObject( iinfo
.hbmMask
);
1186 if (iinfo
.hbmColor
) DeleteObject( iinfo
.hbmColor
);
1192 /***********************************************************************
1193 * CopyIcon (USER32.@)
1195 HICON WINAPI
CopyIcon( HICON hIcon
)
1197 HICON hRetIcon
= NULL
;
1200 if(GetIconInfo(hIcon
, &IconInfo
))
1202 hRetIcon
= CreateIconIndirect(&IconInfo
);
1203 DeleteObject(IconInfo
.hbmColor
);
1204 DeleteObject(IconInfo
.hbmMask
);
1211 /***********************************************************************
1212 * DestroyIcon (USER32.@)
1214 BOOL WINAPI
DestroyIcon( HICON hIcon
)
1216 TRACE_(icon
)("%p\n", hIcon
);
1218 return NtUserDestroyCursor(hIcon
, 0);
1222 /***********************************************************************
1223 * DestroyCursor (USER32.@)
1225 BOOL WINAPI
DestroyCursor( HCURSOR hCursor
)
1227 if (GetCursor() == hCursor
)
1229 WARN_(cursor
)("Destroying active cursor!\n" );
1232 return DestroyIcon( hCursor
);
1235 /***********************************************************************
1236 * DrawIcon (USER32.@)
1238 BOOL WINAPI
DrawIcon( HDC hdc
, INT x
, INT y
, HICON hIcon
)
1240 return DrawIconEx( hdc
, x
, y
, hIcon
, 0, 0, 0, 0, DI_NORMAL
| DI_COMPAT
| DI_DEFAULTSIZE
);
1243 /***********************************************************************
1244 * ShowCursor (USER32.@)
1246 INT WINAPI
/*DECLSPEC_HOTPATCH*/ ShowCursor( BOOL bShow
)
1248 return NtUserxShowCursor(bShow
);
1251 /***********************************************************************
1252 * GetCursor (USER32.@)
1254 HCURSOR WINAPI
GetCursor(void)
1257 ci
.cbSize
= sizeof(CURSORINFO
);
1258 if(NtUserGetCursorInfo(&ci
))
1265 /***********************************************************************
1266 * SetSystemCursor (USER32.@)
1268 BOOL WINAPI
SetSystemCursor(HCURSOR hcur
, DWORD id
)
1270 FIXME("(%p,%08x),stub!\n", hcur
, id
);
1275 /**********************************************************************
1276 * LookupIconIdFromDirectoryEx (USER32.@)
1278 INT WINAPI
LookupIconIdFromDirectoryEx( LPBYTE xdir
, BOOL bIcon
,
1279 INT width
, INT height
, UINT cFlag
)
1281 CURSORICONDIR
*dir
= (CURSORICONDIR
*)xdir
;
1283 if( dir
&& !dir
->idReserved
&& (dir
->idType
& 3) )
1285 CURSORICONDIRENTRY
* entry
;
1287 const HDC hdc
= GetDC(0);
1288 const int depth
= (cFlag
& LR_MONOCHROME
) ?
1289 1 : GetDeviceCaps(hdc
, BITSPIXEL
);
1293 entry
= CURSORICON_FindBestIconRes( dir
, width
, height
, depth
);
1295 entry
= CURSORICON_FindBestCursorRes( dir
, width
, height
, depth
);
1297 if( entry
) retVal
= entry
->wResId
;
1299 else WARN_(cursor
)("invalid resource directory\n");
1303 /**********************************************************************
1304 * LookupIconIdFromDirectory (USER32.@)
1306 INT WINAPI
LookupIconIdFromDirectory( LPBYTE dir
, BOOL bIcon
)
1308 return LookupIconIdFromDirectoryEx( dir
, bIcon
,
1309 bIcon
? GetSystemMetrics(SM_CXICON
) : GetSystemMetrics(SM_CXCURSOR
),
1310 bIcon
? GetSystemMetrics(SM_CYICON
) : GetSystemMetrics(SM_CYCURSOR
), bIcon
? 0 : LR_MONOCHROME
);
1313 /***********************************************************************
1314 * LoadCursorW (USER32.@)
1316 HCURSOR WINAPI
LoadCursorW(HINSTANCE hInstance
, LPCWSTR name
)
1318 TRACE("%p, %s\n", hInstance
, debugstr_w(name
));
1320 return LoadImageW( hInstance
, name
, IMAGE_CURSOR
, 0, 0,
1321 LR_SHARED
| LR_DEFAULTSIZE
);
1324 /***********************************************************************
1325 * LoadCursorA (USER32.@)
1327 HCURSOR WINAPI
LoadCursorA(HINSTANCE hInstance
, LPCSTR name
)
1329 TRACE("%p, %s\n", hInstance
, debugstr_a(name
));
1331 return LoadImageA( hInstance
, name
, IMAGE_CURSOR
, 0, 0,
1332 LR_SHARED
| LR_DEFAULTSIZE
);
1335 /***********************************************************************
1336 * LoadCursorFromFileW (USER32.@)
1338 HCURSOR WINAPI
LoadCursorFromFileW (LPCWSTR name
)
1340 TRACE("%s\n", debugstr_w(name
));
1342 return LoadImageW( 0, name
, IMAGE_CURSOR
, 0, 0,
1343 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
1346 /***********************************************************************
1347 * LoadCursorFromFileA (USER32.@)
1349 HCURSOR WINAPI
LoadCursorFromFileA (LPCSTR name
)
1351 TRACE("%s\n", debugstr_a(name
));
1353 return LoadImageA( 0, name
, IMAGE_CURSOR
, 0, 0,
1354 LR_LOADFROMFILE
| LR_DEFAULTSIZE
);
1357 /***********************************************************************
1358 * LoadIconW (USER32.@)
1360 HICON WINAPI
LoadIconW(HINSTANCE hInstance
, LPCWSTR name
)
1362 TRACE("%p, %s\n", hInstance
, debugstr_w(name
));
1364 return LoadImageW( hInstance
, name
, IMAGE_ICON
, 0, 0,
1365 LR_SHARED
| LR_DEFAULTSIZE
);
1368 /***********************************************************************
1369 * LoadIconA (USER32.@)
1371 HICON WINAPI
LoadIconA(HINSTANCE hInstance
, LPCSTR name
)
1373 TRACE("%p, %s\n", hInstance
, debugstr_a(name
));
1375 return LoadImageA( hInstance
, name
, IMAGE_ICON
, 0, 0,
1376 LR_SHARED
| LR_DEFAULTSIZE
);
1379 /**********************************************************************
1380 * GetIconInfo (USER32.@)
1382 BOOL WINAPI
GetIconInfo(HICON hIcon
, PICONINFO iconinfo
)
1384 return NtUserGetIconInfo(hIcon
, iconinfo
, 0, 0, 0, 0);
1387 /* copy an icon bitmap, even when it can't be selected into a DC */
1388 /* helper for CreateIconIndirect */
1389 static void stretch_blt_icon( HDC hdc_dst
, int dst_x
, int dst_y
, int dst_width
, int dst_height
,
1390 HBITMAP src
, int width
, int height
)
1392 HDC hdc
= CreateCompatibleDC( 0 );
1394 if (!SelectObject( hdc
, src
)) /* do it the hard way */
1399 if (!(info
= HeapAlloc( GetProcessHeap(), 0, FIELD_OFFSET( BITMAPINFO
, bmiColors
[256] )))) return;
1400 info
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
1401 info
->bmiHeader
.biWidth
= width
;
1402 info
->bmiHeader
.biHeight
= height
;
1403 info
->bmiHeader
.biPlanes
= GetDeviceCaps( hdc_dst
, PLANES
);
1404 info
->bmiHeader
.biBitCount
= GetDeviceCaps( hdc_dst
, BITSPIXEL
);
1405 info
->bmiHeader
.biCompression
= BI_RGB
;
1406 info
->bmiHeader
.biSizeImage
= height
* get_dib_width_bytes( width
, info
->bmiHeader
.biBitCount
);
1407 info
->bmiHeader
.biXPelsPerMeter
= 0;
1408 info
->bmiHeader
.biYPelsPerMeter
= 0;
1409 info
->bmiHeader
.biClrUsed
= 0;
1410 info
->bmiHeader
.biClrImportant
= 0;
1411 bits
= HeapAlloc( GetProcessHeap(), 0, info
->bmiHeader
.biSizeImage
);
1412 if (bits
&& GetDIBits( hdc
, src
, 0, height
, bits
, info
, DIB_RGB_COLORS
))
1413 StretchDIBits( hdc_dst
, dst_x
, dst_y
, dst_width
, dst_height
,
1414 0, 0, width
, height
, bits
, info
, DIB_RGB_COLORS
, SRCCOPY
);
1416 HeapFree( GetProcessHeap(), 0, bits
);
1417 HeapFree( GetProcessHeap(), 0, info
);
1419 else StretchBlt( hdc_dst
, dst_x
, dst_y
, dst_width
, dst_height
, hdc
, 0, 0, width
, height
, SRCCOPY
);
1424 /**********************************************************************
1425 * CreateIconIndirect (USER32.@)
1427 HICON WINAPI
CreateIconIndirect(PICONINFO iconinfo
)
1429 BITMAP bmpXor
, bmpAnd
;
1430 HBITMAP color
= 0, mask
;
1435 TRACE("color %p, mask %p, hotspot %ux%u, fIcon %d\n",
1436 iconinfo
->hbmColor
, iconinfo
->hbmMask
,
1437 iconinfo
->xHotspot
, iconinfo
->yHotspot
, iconinfo
->fIcon
);
1439 if (!iconinfo
->hbmMask
) return 0;
1441 GetObjectW( iconinfo
->hbmMask
, sizeof(bmpAnd
), &bmpAnd
);
1442 TRACE("mask: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
1443 bmpAnd
.bmWidth
, bmpAnd
.bmHeight
, bmpAnd
.bmWidthBytes
,
1444 bmpAnd
.bmPlanes
, bmpAnd
.bmBitsPixel
);
1446 if (iconinfo
->hbmColor
)
1448 GetObjectW( iconinfo
->hbmColor
, sizeof(bmpXor
), &bmpXor
);
1449 TRACE("color: width %d, height %d, width bytes %d, planes %u, bpp %u\n",
1450 bmpXor
.bmWidth
, bmpXor
.bmHeight
, bmpXor
.bmWidthBytes
,
1451 bmpXor
.bmPlanes
, bmpXor
.bmBitsPixel
);
1453 // the size of the mask bitmap always determines the icon size!
1454 width
= bmpAnd
.bmWidth
;
1455 height
= bmpAnd
.bmHeight
;
1456 if (bmpXor
.bmPlanes
* bmpXor
.bmBitsPixel
!= 1 )
1458 color
= CreateBitmap( width
, height
, bmpXor
.bmPlanes
, bmpXor
.bmBitsPixel
, NULL
);
1461 ERR("Unable to create color bitmap!\n");
1464 mask
= CreateBitmap( width
, height
, 1, 1, NULL
);
1467 ERR("Unable to create mask bitmap!\n");
1468 DeleteObject(color
);
1474 mask
= CreateBitmap( width
, height
* 2, 1, 1, NULL
);
1477 ERR("Unable to create mask bitmap!\n");
1484 width
= bmpAnd
.bmWidth
;
1485 height
= bmpAnd
.bmHeight
;
1486 mask
= CreateBitmap( width
, height
, 1, 1, NULL
);
1489 hdc
= CreateCompatibleDC( 0 );
1490 SelectObject( hdc
, mask
);
1491 stretch_blt_icon( hdc
, 0, 0, width
, height
, iconinfo
->hbmMask
, bmpAnd
.bmWidth
, bmpAnd
.bmHeight
);
1495 SelectObject( hdc
, color
);
1496 stretch_blt_icon( hdc
, 0, 0, width
, height
, iconinfo
->hbmColor
, width
, height
);
1498 else if (iconinfo
->hbmColor
)
1500 stretch_blt_icon( hdc
, 0, height
, width
, height
, iconinfo
->hbmColor
, width
, height
);
1506 iinfo
.hbmColor
= color
;
1507 iinfo
.hbmMask
= mask
;
1508 iinfo
.fIcon
= iconinfo
->fIcon
;
1511 iinfo
.xHotspot
= width
/ 2;
1512 iinfo
.yHotspot
= height
/ 2;
1516 iinfo
.xHotspot
= iconinfo
->xHotspot
;
1517 iinfo
.yHotspot
= iconinfo
->yHotspot
;
1520 return CreateCursorIconHandle(&iinfo
);
1523 /******************************************************************************
1524 * DrawIconEx (USER32.@) Draws an icon or cursor on device context
1527 * Why is this using SM_CXICON instead of SM_CXCURSOR?
1530 * hdc [I] Handle to device context
1531 * x0 [I] X coordinate of upper left corner
1532 * y0 [I] Y coordinate of upper left corner
1533 * hIcon [I] Handle to icon to draw
1534 * cxWidth [I] Width of icon
1535 * cyWidth [I] Height of icon
1536 * istep [I] Index of frame in animated cursor
1537 * hbr [I] Handle to background brush
1538 * flags [I] Icon-drawing flags
1544 BOOL WINAPI
DrawIconEx( HDC hdc
, INT xLeft
, INT yTop
, HICON hIcon
,
1545 INT cxWidth
, INT cyWidth
, UINT istepIfAniCur
,
1546 HBRUSH hbrFlickerFreeDraw
, UINT diFlags
)
1548 return NtUserDrawIconEx(hdc
, xLeft
, yTop
, hIcon
, cxWidth
, cyWidth
,
1549 istepIfAniCur
, hbrFlickerFreeDraw
, diFlags
,
1553 /***********************************************************************
1554 * DIB_FixColorsToLoadflags
1556 * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
1559 static void DIB_FixColorsToLoadflags(BITMAPINFO
* bmi
, UINT loadflags
, BYTE pix
)
1562 COLORREF c_W
, c_S
, c_F
, c_L
, c_C
;
1571 if (((bitmap_type
= DIB_GetBitmapInfo((BITMAPINFOHEADER
*) bmi
, &width
, &height
, &bpp
, &compr
)) == -1))
1573 WARN_(resource
)("Invalid bitmap\n");
1577 if (bpp
> 8) return;
1579 if (bitmap_type
== 0) /* BITMAPCOREHEADER */
1587 colors
= bmi
->bmiHeader
.biClrUsed
;
1588 if (colors
> 256) colors
= 256;
1589 if (!colors
&& (bpp
<= 8)) colors
= 1 << bpp
;
1592 c_W
= GetSysColor(COLOR_WINDOW
);
1593 c_S
= GetSysColor(COLOR_3DSHADOW
);
1594 c_F
= GetSysColor(COLOR_3DFACE
);
1595 c_L
= GetSysColor(COLOR_3DLIGHT
);
1597 if (loadflags
& LR_LOADTRANSPARENT
) {
1599 case 1: pix
= pix
>> 7; break;
1600 case 4: pix
= pix
>> 4; break;
1603 WARN_(resource
)("(%d): Unsupported depth\n", bpp
);
1606 if (pix
>= colors
) {
1607 WARN_(resource
)("pixel has color index greater than biClrUsed!\n");
1610 if (loadflags
& LR_LOADMAP3DCOLORS
) c_W
= c_F
;
1611 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+pix
*incr
);
1612 ptr
->rgbBlue
= GetBValue(c_W
);
1613 ptr
->rgbGreen
= GetGValue(c_W
);
1614 ptr
->rgbRed
= GetRValue(c_W
);
1616 if (loadflags
& LR_LOADMAP3DCOLORS
)
1617 for (i
=0; i
<colors
; i
++) {
1618 ptr
= (RGBQUAD
*)((char*)bmi
->bmiColors
+i
*incr
);
1619 c_C
= RGB(ptr
->rgbRed
, ptr
->rgbGreen
, ptr
->rgbBlue
);
1620 if (c_C
== RGB(128, 128, 128)) {
1621 ptr
->rgbRed
= GetRValue(c_S
);
1622 ptr
->rgbGreen
= GetGValue(c_S
);
1623 ptr
->rgbBlue
= GetBValue(c_S
);
1624 } else if (c_C
== RGB(192, 192, 192)) {
1625 ptr
->rgbRed
= GetRValue(c_F
);
1626 ptr
->rgbGreen
= GetGValue(c_F
);
1627 ptr
->rgbBlue
= GetBValue(c_F
);
1628 } else if (c_C
== RGB(223, 223, 223)) {
1629 ptr
->rgbRed
= GetRValue(c_L
);
1630 ptr
->rgbGreen
= GetGValue(c_L
);
1631 ptr
->rgbBlue
= GetBValue(c_L
);
1637 /**********************************************************************
1640 static HBITMAP
BITMAP_Load( HINSTANCE instance
, LPCWSTR name
,
1641 INT desiredx
, INT desiredy
, UINT loadflags
)
1643 HBITMAP hbitmap
= 0, orig_bm
;
1647 BITMAPINFO
*info
, *fix_info
= NULL
, *scaled_info
= NULL
;
1651 LONG width
, height
, new_width
, new_height
;
1653 DWORD compr_dummy
, offbits
= 0;
1655 HDC screen_mem_dc
= NULL
;
1657 if (!(loadflags
& LR_LOADFROMFILE
))
1661 /* OEM bitmap: try to load the resource from user32.dll */
1662 instance
= User32Instance
;
1665 if (!(hRsrc
= FindResourceW( instance
, name
, (LPWSTR
)RT_BITMAP
))) return 0;
1666 if (!(handle
= LoadResource( instance
, hRsrc
))) return 0;
1668 if ((info
= LockResource( handle
)) == NULL
) return 0;
1672 BITMAPFILEHEADER
* bmfh
;
1674 if (!(ptr
= map_fileW( name
, NULL
))) return 0;
1675 info
= (BITMAPINFO
*)(ptr
+ sizeof(BITMAPFILEHEADER
));
1676 bmfh
= (BITMAPFILEHEADER
*)ptr
;
1677 if (bmfh
->bfType
!= 0x4d42 /* 'BM' */)
1679 WARN("Invalid/unsupported bitmap format!\n");
1682 if (bmfh
->bfOffBits
) offbits
= bmfh
->bfOffBits
- sizeof(BITMAPFILEHEADER
);
1685 size
= bitmap_info_size(info
, DIB_RGB_COLORS
);
1686 fix_info
= HeapAlloc(GetProcessHeap(), 0, size
);
1687 scaled_info
= HeapAlloc(GetProcessHeap(), 0, size
);
1689 if (!fix_info
|| !scaled_info
) goto end
;
1690 memcpy(fix_info
, info
, size
);
1692 pix
= *((LPBYTE
)info
+ size
);
1693 DIB_FixColorsToLoadflags(fix_info
, loadflags
, pix
);
1695 memcpy(scaled_info
, fix_info
, size
);
1696 bm_type
= DIB_GetBitmapInfo( &fix_info
->bmiHeader
, &width
, &height
,
1697 &bpp_dummy
, &compr_dummy
);
1699 new_width
= desiredx
;
1704 new_height
= height
> 0 ? desiredy
: -desiredy
;
1706 new_height
= height
;
1710 BITMAPCOREHEADER
*core
= (BITMAPCOREHEADER
*)&scaled_info
->bmiHeader
;
1711 core
->bcWidth
= new_width
;
1712 core
->bcHeight
= new_height
;
1714 else if (bm_type
== 1)
1716 /* Some sanity checks for BITMAPINFO (not applicable to BITMAPCOREINFO) */
1717 if (info
->bmiHeader
.biHeight
> 65535 || info
->bmiHeader
.biWidth
> 65535) {
1718 WARN("Broken BitmapInfoHeader!\n");
1722 scaled_info
->bmiHeader
.biWidth
= new_width
;
1723 scaled_info
->bmiHeader
.biHeight
= new_height
;
1728 if (new_height
< 0) new_height
= -new_height
;
1730 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
1731 if (!(screen_mem_dc
= CreateCompatibleDC( screen_dc
))) goto end
;
1733 bits
= (char *)info
+ (offbits
? offbits
: size
);
1735 if (loadflags
& LR_CREATEDIBSECTION
)
1737 scaled_info
->bmiHeader
.biCompression
= 0; /* DIBSection can't be compressed */
1738 hbitmap
= CreateDIBSection(screen_dc
, scaled_info
, DIB_RGB_COLORS
, NULL
, 0, 0);
1742 if (is_dib_monochrome(fix_info
))
1743 hbitmap
= CreateBitmap(new_width
, new_height
, 1, 1, NULL
);
1745 hbitmap
= CreateCompatibleBitmap(screen_dc
, new_width
, new_height
);
1748 orig_bm
= SelectObject(screen_mem_dc
, hbitmap
);
1749 StretchDIBits(screen_mem_dc
, 0, 0, new_width
, new_height
, 0, 0, width
, height
, bits
, fix_info
, DIB_RGB_COLORS
, SRCCOPY
);
1750 SelectObject(screen_mem_dc
, orig_bm
);
1753 if (screen_mem_dc
) DeleteDC(screen_mem_dc
);
1754 HeapFree(GetProcessHeap(), 0, scaled_info
);
1755 HeapFree(GetProcessHeap(), 0, fix_info
);
1757 if (loadflags
& LR_LOADFROMFILE
) UnmapViewOfFile( ptr
);
1762 /**********************************************************************
1763 * LoadImageA (USER32.@)
1767 HANDLE WINAPI
LoadImageA( HINSTANCE hinst
, LPCSTR name
, UINT type
,
1768 INT desiredx
, INT desiredy
, UINT loadflags
)
1773 if (IS_INTRESOURCE(name
))
1774 return LoadImageW(hinst
, (LPCWSTR
)name
, type
, desiredx
, desiredy
, loadflags
);
1778 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, name
, -1, NULL
, 0 );
1779 u_name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1780 MultiByteToWideChar( CP_ACP
, 0, name
, -1, u_name
, len
);
1782 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1784 SetLastError( ERROR_INVALID_PARAMETER
);
1785 _SEH2_YIELD(return 0);
1788 res
= LoadImageW(hinst
, u_name
, type
, desiredx
, desiredy
, loadflags
);
1789 HeapFree(GetProcessHeap(), 0, u_name
);
1794 /******************************************************************************
1795 * LoadImageW (USER32.@) Loads an icon, cursor, or bitmap
1798 * hinst [I] Handle of instance that contains image
1799 * name [I] Name of image
1800 * type [I] Type of image
1801 * desiredx [I] Desired width
1802 * desiredy [I] Desired height
1803 * loadflags [I] Load flags
1806 * Success: Handle to newly loaded image
1809 * FIXME: Implementation lacks some features, see LR_ defines in winuser.h
1811 HANDLE WINAPI
LoadImageW( HINSTANCE hinst
, LPCWSTR name
, UINT type
,
1812 INT desiredx
, INT desiredy
, UINT loadflags
)
1814 TRACE_(resource
)("(%p,%s,%d,%d,%d,0x%08x)\n",
1815 hinst
,debugstr_w(name
),type
,desiredx
,desiredy
,loadflags
);
1817 if (loadflags
& LR_DEFAULTSIZE
) {
1818 if (type
== IMAGE_ICON
) {
1819 if (!desiredx
) desiredx
= GetSystemMetrics(SM_CXICON
);
1820 if (!desiredy
) desiredy
= GetSystemMetrics(SM_CYICON
);
1821 } else if (type
== IMAGE_CURSOR
) {
1822 if (!desiredx
) desiredx
= GetSystemMetrics(SM_CXCURSOR
);
1823 if (!desiredy
) desiredy
= GetSystemMetrics(SM_CYCURSOR
);
1826 if (loadflags
& LR_LOADFROMFILE
) loadflags
&= ~LR_SHARED
;
1829 return BITMAP_Load( hinst
, name
, desiredx
, desiredy
, loadflags
);
1832 if (!screen_dc
) screen_dc
= CreateDCW( DISPLAYW
, NULL
, NULL
, NULL
);
1835 return CURSORICON_Load(hinst
, name
, desiredx
, desiredy
,
1836 GetDeviceCaps(screen_dc
, BITSPIXEL
),
1842 return CURSORICON_Load(hinst
, name
, desiredx
, desiredy
,
1843 1, TRUE
, loadflags
);
1848 /******************************************************************************
1849 * CopyImage (USER32.@) Creates new image and copies attributes to it
1852 * hnd [I] Handle to image to copy
1853 * type [I] Type of image to copy
1854 * desiredx [I] Desired width of new image
1855 * desiredy [I] Desired height of new image
1856 * flags [I] Copy flags
1859 * Success: Handle to newly created image
1863 * Only Windows NT 4.0 supports the LR_COPYRETURNORG flag for bitmaps,
1864 * all other versions (95/2000/XP have been tested) ignore it.
1867 * If LR_CREATEDIBSECTION is absent, the copy will be monochrome for
1868 * a monochrome source bitmap or if LR_MONOCHROME is present, otherwise
1869 * the copy will have the same depth as the screen.
1870 * The content of the image will only be copied if the bit depth of the
1871 * original image is compatible with the bit depth of the screen, or
1872 * if the source is a DIB section.
1873 * The LR_MONOCHROME flag is ignored if LR_CREATEDIBSECTION is present.
1875 HANDLE WINAPI
CopyImage( HANDLE hnd
, UINT type
, INT desiredx
,
1876 INT desiredy
, UINT flags
)
1878 TRACE("hnd=%p, type=%u, desiredx=%d, desiredy=%d, flags=%x\n",
1879 hnd
, type
, desiredx
, desiredy
, flags
);
1890 objSize
= GetObjectW( hnd
, sizeof(ds
), &ds
);
1891 if (!objSize
) return 0;
1892 if ((desiredx
< 0) || (desiredy
< 0)) return 0;
1894 if (flags
& LR_COPYFROMRESOURCE
)
1896 FIXME("The flag LR_COPYFROMRESOURCE is not implemented for bitmaps\n");
1899 if (desiredx
== 0) desiredx
= ds
.dsBm
.bmWidth
;
1900 if (desiredy
== 0) desiredy
= ds
.dsBm
.bmHeight
;
1902 /* Allocate memory for a BITMAPINFOHEADER structure and a
1903 color table. The maximum number of colors in a color table
1904 is 256 which corresponds to a bitmap with depth 8.
1905 Bitmaps with higher depths don't have color tables. */
1906 bi
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(BITMAPINFOHEADER
) + 256 * sizeof(RGBQUAD
));
1909 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
1910 bi
->bmiHeader
.biPlanes
= ds
.dsBm
.bmPlanes
;
1911 bi
->bmiHeader
.biBitCount
= ds
.dsBm
.bmBitsPixel
;
1912 bi
->bmiHeader
.biCompression
= BI_RGB
;
1914 if (flags
& LR_CREATEDIBSECTION
)
1916 /* Create a DIB section. LR_MONOCHROME is ignored */
1918 HDC dc
= CreateCompatibleDC(NULL
);
1920 if (objSize
== sizeof(DIBSECTION
))
1922 /* The source bitmap is a DIB.
1923 Get its attributes to create an exact copy */
1924 memcpy(bi
, &ds
.dsBmih
, sizeof(BITMAPINFOHEADER
));
1927 /* Get the color table or the color masks */
1928 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
1930 bi
->bmiHeader
.biWidth
= desiredx
;
1931 bi
->bmiHeader
.biHeight
= desiredy
;
1932 bi
->bmiHeader
.biSizeImage
= 0;
1934 res
= CreateDIBSection(dc
, bi
, DIB_RGB_COLORS
, &bits
, NULL
, 0);
1939 /* Create a device-dependent bitmap */
1941 BOOL monochrome
= (flags
& LR_MONOCHROME
);
1943 if (objSize
== sizeof(DIBSECTION
))
1945 /* The source bitmap is a DIB section.
1946 Get its attributes */
1947 HDC dc
= CreateCompatibleDC(NULL
);
1948 bi
->bmiHeader
.biSize
= sizeof(bi
->bmiHeader
);
1949 bi
->bmiHeader
.biBitCount
= ds
.dsBm
.bmBitsPixel
;
1950 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
1953 if (!monochrome
&& ds
.dsBm
.bmBitsPixel
== 1)
1955 /* Look if the colors of the DIB are black and white */
1958 (bi
->bmiColors
[0].rgbRed
== 0xff
1959 && bi
->bmiColors
[0].rgbGreen
== 0xff
1960 && bi
->bmiColors
[0].rgbBlue
== 0xff
1961 && bi
->bmiColors
[0].rgbReserved
== 0
1962 && bi
->bmiColors
[1].rgbRed
== 0
1963 && bi
->bmiColors
[1].rgbGreen
== 0
1964 && bi
->bmiColors
[1].rgbBlue
== 0
1965 && bi
->bmiColors
[1].rgbReserved
== 0)
1967 (bi
->bmiColors
[0].rgbRed
== 0
1968 && bi
->bmiColors
[0].rgbGreen
== 0
1969 && bi
->bmiColors
[0].rgbBlue
== 0
1970 && bi
->bmiColors
[0].rgbReserved
== 0
1971 && bi
->bmiColors
[1].rgbRed
== 0xff
1972 && bi
->bmiColors
[1].rgbGreen
== 0xff
1973 && bi
->bmiColors
[1].rgbBlue
== 0xff
1974 && bi
->bmiColors
[1].rgbReserved
== 0);
1977 else if (!monochrome
)
1979 monochrome
= ds
.dsBm
.bmBitsPixel
== 1;
1984 res
= CreateBitmap(desiredx
, desiredy
, 1, 1, NULL
);
1988 HDC screenDC
= GetDC(NULL
);
1989 res
= CreateCompatibleBitmap(screenDC
, desiredx
, desiredy
);
1990 ReleaseDC(NULL
, screenDC
);
1996 /* Only copy the bitmap if it's a DIB section or if it's
1997 compatible to the screen */
2000 if (objSize
== sizeof(DIBSECTION
))
2002 copyContents
= TRUE
;
2006 HDC screenDC
= GetDC(NULL
);
2007 int screen_depth
= GetDeviceCaps(screenDC
, BITSPIXEL
);
2008 ReleaseDC(NULL
, screenDC
);
2010 copyContents
= (ds
.dsBm
.bmBitsPixel
== 1 || ds
.dsBm
.bmBitsPixel
== screen_depth
);
2015 /* The source bitmap may already be selected in a device context,
2016 use GetDIBits/StretchDIBits and not StretchBlt */
2021 dc
= CreateCompatibleDC(NULL
);
2023 bi
->bmiHeader
.biWidth
= ds
.dsBm
.bmWidth
;
2024 bi
->bmiHeader
.biHeight
= ds
.dsBm
.bmHeight
;
2025 bi
->bmiHeader
.biSizeImage
= 0;
2026 bi
->bmiHeader
.biClrUsed
= 0;
2027 bi
->bmiHeader
.biClrImportant
= 0;
2029 /* Fill in biSizeImage */
2030 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, NULL
, bi
, DIB_RGB_COLORS
);
2031 bits
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, bi
->bmiHeader
.biSizeImage
);
2037 /* Get the image bits of the source bitmap */
2038 GetDIBits(dc
, hnd
, 0, ds
.dsBm
.bmHeight
, bits
, bi
, DIB_RGB_COLORS
);
2040 /* Copy it to the destination bitmap */
2041 oldBmp
= SelectObject(dc
, res
);
2042 StretchDIBits(dc
, 0, 0, desiredx
, desiredy
,
2043 0, 0, ds
.dsBm
.bmWidth
, ds
.dsBm
.bmHeight
,
2044 bits
, bi
, DIB_RGB_COLORS
, SRCCOPY
);
2045 SelectObject(dc
, oldBmp
);
2047 HeapFree(GetProcessHeap(), 0, bits
);
2053 if (flags
& LR_COPYDELETEORG
)
2058 HeapFree(GetProcessHeap(), 0, bi
);
2062 return CURSORICON_ExtCopy(hnd
,type
, desiredx
, desiredy
, flags
);
2064 /* Should call CURSORICON_ExtCopy but more testing
2065 * needs to be done before we change this
2067 if (flags
) FIXME("Flags are ignored\n");
2068 return CopyCursor(hnd
);
2074 /******************************************************************************
2075 * LoadBitmapW (USER32.@) Loads bitmap from the executable file
2078 * Success: Handle to specified bitmap
2081 HBITMAP WINAPI
LoadBitmapW(
2082 HINSTANCE instance
, /* [in] Handle to application instance */
2083 LPCWSTR name
) /* [in] Address of bitmap resource name */
2085 return LoadImageW( instance
, name
, IMAGE_BITMAP
, 0, 0, 0 );
2088 /**********************************************************************
2089 * LoadBitmapA (USER32.@)
2093 HBITMAP WINAPI
LoadBitmapA( HINSTANCE instance
, LPCSTR name
)
2095 return LoadImageA( instance
, name
, IMAGE_BITMAP
, 0, 0, 0 );
2099 CursorIconToCursor(HICON hIcon
,
2100 BOOL SemiTransparent
)
2111 SetCursorPos(int X
, int Y
)
2113 return NtUserxSetCursorPos(X
,Y
);
2121 GetCursorPos(LPPOINT lpPoint
)
2124 /* Windows doesn't check if lpPoint == NULL, we do */
2127 SetLastError(ERROR_INVALID_PARAMETER
);
2131 res
= NtUserxGetCursorPos(lpPoint
);
2136 /* INTERNAL ******************************************************************/
2138 /* This callback routine is called directly after switching to gui mode */
2141 User32SetupDefaultCursors(PVOID Arguments
,
2142 ULONG ArgumentLength
)
2144 BOOL
*DefaultCursor
= (BOOL
*)Arguments
;
2145 LRESULT Result
= TRUE
;
2149 /* set default cursor */
2150 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
2154 /* FIXME load system cursor scheme */
2156 SetCursor(LoadCursorW(0, (LPCWSTR
)IDC_ARROW
));
2159 return(ZwCallbackReturn(&Result
, sizeof(LRESULT
), STATUS_SUCCESS
));
2162 BOOL
get_icon_size(HICON hIcon
, SIZE
*size
)
2167 if (!GetIconInfo(hIcon
, &info
)) return FALSE
;
2168 if (!GetObject(info
.hbmMask
, sizeof(bitmap
), &bitmap
)) return FALSE
;
2170 size
->cx
= bitmap
.bmWidth
;
2171 size
->cy
= bitmap
.bmHeight
;
2173 /* Black and white icons store both the XOR and AND bitmap in hbmMask */
2180 DeleteObject(info
.hbmColor
);
2183 DeleteObject(info
.hbmMask
);