5da0840e2e5d138d2f2bc5c40369c781b612308a
3 * Copyright (C) 1998, 1999, 2000, 2001 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /* $Id: bitmap.c,v 1.4 2002/09/08 10:23:11 chorns Exp $
21 * PROJECT: ReactOS user32.dll
22 * FILE: lib/user32/windows/input.c
24 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
26 * 09-05-2001 CSH Created
29 /* INCLUDES ******************************************************************/
35 /* FUNCTIONS *****************************************************************/
38 LoadImageA(HINSTANCE hinst
,
50 lpszWName
= User32ConvertString(lpszName
);
51 Handle
= LoadImageW(hinst
, lpszWName
, uType
, cxDesired
,
53 User32FreeString(lpszWName
);
57 Handle
= LoadImageW(hinst
, lpszWName
, uType
, cxDesired
,
64 LoadBitmapImage(HINSTANCE hInstance
, LPCWSTR lpszName
, UINT fuLoad
)
69 BITMAPINFO
* BitmapInfo
;
70 BITMAPINFO
* PrivateInfo
;
77 if (!(fuLoad
& LR_LOADFROMFILE
))
79 if (hInstance
== NULL
)
81 hInstance
= GetModuleHandle(L
"USER32");
83 hResource
= FindResourceW(hInstance
, lpszName
, RT_BITMAP
);
84 if (hResource
== NULL
)
88 hResource
= LoadResource(hInstance
, hResource
);
89 if (hResource
== NULL
)
93 BitmapInfo
= LockResource(hResource
);
94 if (BitmapInfo
== NULL
)
101 hFile
= CreateFile(lpszName
,
112 hSection
= CreateFileMapping(hFile
,
119 if (hSection
== NULL
)
123 BitmapInfo
= MapViewOfFile(hSection
,
128 CloseHandle(hSection
);
129 if (BitmapInfo
== NULL
)
135 if (BitmapInfo
->bmiHeader
.biSize
== sizeof(BITMAPCOREHEADER
))
137 BITMAPCOREHEADER
* Core
= (BITMAPCOREHEADER
*)BitmapInfo
;
138 ColourCount
= (Core
->bcBitCount
<= 8) ? (1 << Core
->bcBitCount
) : 0;
139 HeaderSize
= sizeof(BITMAPCOREHEADER
) + ColourCount
* sizeof(RGBTRIPLE
);
143 ColourCount
= BitmapInfo
->bmiHeader
.biClrUsed
;
144 if (ColourCount
== 0 && BitmapInfo
->bmiHeader
.biBitCount
<= 8)
146 ColourCount
= 1 << BitmapInfo
->bmiHeader
.biBitCount
;
148 HeaderSize
= sizeof(BITMAPINFOHEADER
) + ColourCount
* sizeof(RGBQUAD
);
150 Data
= (PVOID
)BitmapInfo
+ HeaderSize
;
152 PrivateInfo
= RtlAllocateHeap(RtlGetProcessHeap(), 0, HeaderSize
);
153 if (PrivateInfo
== NULL
)
155 if (fuLoad
& LR_LOADFROMFILE
)
157 UnmapViewOfFile(BitmapInfo
);
161 memcpy(PrivateInfo
, BitmapInfo
, HeaderSize
);
163 /* FIXME: Handle colour conversion and transparency. */
165 hScreenDc
= CreateDCW(L
"DISPLAY", NULL
, NULL
, NULL
);
166 if (hScreenDc
== NULL
)
168 if (fuLoad
& LR_LOADFROMFILE
)
170 UnmapViewOfFile(BitmapInfo
);
175 if (fuLoad
& LR_CREATEDIBSECTION
)
179 hBitmap
= CreateDIBSection(hScreenDc
, PrivateInfo
, DIB_RGB_COLORS
, NULL
,
181 GetObjectA(hBitmap
, sizeof(DIBSECTION
), &Dib
);
182 SetDIBits(hScreenDc
, hBitmap
, 0, Dib
.dsBm
.bmHeight
, Data
, BitmapInfo
,
187 hBitmap
= CreateDIBitmap(hScreenDc
, &PrivateInfo
->bmiHeader
, CBM_INIT
,
188 Data
, PrivateInfo
, DIB_RGB_COLORS
);
191 RtlFreeHeap(RtlGetProcessHeap(), 0, PrivateInfo
);
192 /*DeleteDC(hScreenDc);*/
193 if (fuLoad
& LR_LOADFROMFILE
)
195 UnmapViewOfFile(BitmapInfo
);
201 LoadImageW(HINSTANCE hinst
,
208 if (fuLoad
& LR_DEFAULTSIZE
)
210 if (uType
== IMAGE_ICON
)
214 cxDesired
= GetSystemMetrics(SM_CXICON
);
218 cyDesired
= GetSystemMetrics(SM_CYICON
);
221 else if (uType
== IMAGE_CURSOR
)
225 cxDesired
= GetSystemMetrics(SM_CXCURSOR
);
229 cyDesired
= GetSystemMetrics(SM_CYCURSOR
);
238 return(LoadBitmapImage(hinst
, lpszName
, fuLoad
));
242 DbgPrint("FIXME: Need support for loading cursors.\n");
254 LoadBitmapA(HINSTANCE hInstance
, LPCSTR lpBitmapName
)
256 return(LoadImageA(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0, 0));
260 LoadBitmapW(HINSTANCE hInstance
, LPCWSTR lpBitmapName
)
262 return(LoadImageW(hInstance
, lpBitmapName
, IMAGE_BITMAP
, 0, 0, 0));