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.
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 ******************************************************************/
36 /* FUNCTIONS *****************************************************************/
39 LoadImageA(HINSTANCE hinst,
48 UNICODE_STRING NameString;
52 RtlCreateUnicodeStringFromAsciiz(&NameString, (LPSTR)lpszName);
53 lpszWName = NameString.Buffer;
54 Handle = LoadImageW(hinst, lpszWName, uType, cxDesired,
56 RtlFreeUnicodeString(&NameString);
60 Handle = LoadImageW(hinst, lpszWName, uType, cxDesired,
67 LoadBitmapImage(HINSTANCE hInstance, LPCWSTR lpszName, UINT fuLoad)
72 BITMAPINFO* BitmapInfo;
73 BITMAPINFO* PrivateInfo;
80 if (!(fuLoad & LR_LOADFROMFILE))
82 if (hInstance == NULL)
84 hInstance = GetModuleHandle(L"USER32");
86 hResource = FindResourceW(hInstance, lpszName, RT_BITMAP);
87 if (hResource == NULL)
91 hResource = LoadResource(hInstance, hResource);
92 if (hResource == NULL)
96 BitmapInfo = LockResource(hResource);
97 if (BitmapInfo == NULL)
104 hFile = CreateFile(lpszName,
115 hSection = CreateFileMapping(hFile,
122 if (hSection == NULL)
126 BitmapInfo = MapViewOfFile(hSection,
131 CloseHandle(hSection);
132 if (BitmapInfo == NULL)
138 if (BitmapInfo->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
140 BITMAPCOREHEADER* Core = (BITMAPCOREHEADER*)BitmapInfo;
141 ColourCount = (Core->bcBitCount <= 8) ? (1 << Core->bcBitCount) : 0;
142 HeaderSize = sizeof(BITMAPCOREHEADER) + ColourCount * sizeof(RGBTRIPLE);
146 ColourCount = BitmapInfo->bmiHeader.biClrUsed;
147 if (ColourCount == 0 && BitmapInfo->bmiHeader.biBitCount <= 8)
149 ColourCount = 1 << BitmapInfo->bmiHeader.biBitCount;
151 HeaderSize = sizeof(BITMAPINFOHEADER) + ColourCount * sizeof(RGBQUAD);
153 Data = (PVOID)BitmapInfo + HeaderSize;
155 PrivateInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, HeaderSize);
156 if (PrivateInfo == NULL)
158 if (fuLoad & LR_LOADFROMFILE)
160 UnmapViewOfFile(BitmapInfo);
164 memcpy(PrivateInfo, BitmapInfo, HeaderSize);
166 /* FIXME: Handle colour conversion and transparency. */
168 hScreenDc = CreateDCW(L"DISPLAY", NULL, NULL, NULL);
169 if (hScreenDc == NULL)
171 if (fuLoad & LR_LOADFROMFILE)
173 UnmapViewOfFile(BitmapInfo);
178 if (fuLoad & LR_CREATEDIBSECTION)
182 hBitmap = CreateDIBSection(hScreenDc, PrivateInfo, DIB_RGB_COLORS, NULL,
184 GetObjectA(hBitmap, sizeof(DIBSECTION), &Dib);
185 SetDIBits(hScreenDc, hBitmap, 0, Dib.dsBm.bmHeight, Data, BitmapInfo,
190 hBitmap = CreateDIBitmap(hScreenDc, &PrivateInfo->bmiHeader, CBM_INIT,
191 Data, PrivateInfo, DIB_RGB_COLORS);
194 RtlFreeHeap(RtlGetProcessHeap(), 0, PrivateInfo);
195 /*DeleteDC(hScreenDc);*/
196 if (fuLoad & LR_LOADFROMFILE)
198 UnmapViewOfFile(BitmapInfo);
204 LoadImageW(HINSTANCE hinst,
211 if (fuLoad & LR_DEFAULTSIZE)
213 if (uType == IMAGE_ICON)
217 cxDesired = GetSystemMetrics(SM_CXICON);
221 cyDesired = GetSystemMetrics(SM_CYICON);
224 else if (uType == IMAGE_CURSOR)
228 cxDesired = GetSystemMetrics(SM_CXCURSOR);
232 cyDesired = GetSystemMetrics(SM_CYCURSOR);
241 return(LoadBitmapImage(hinst, lpszName, fuLoad));
245 DbgPrint("FIXME: Need support for loading cursors.\n");
257 LoadBitmapA(HINSTANCE hInstance, LPCSTR lpBitmapName)
259 return(LoadImageA(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0, 0));
263 LoadBitmapW(HINSTANCE hInstance, LPCWSTR lpBitmapName)
265 return(LoadImageW(hInstance, lpBitmapName, IMAGE_BITMAP, 0, 0, 0));