Changeset 1196 for trunk/src/user32/loadres.cpp
- Timestamp:
- Oct 8, 1999, 9:34:25 PM (26 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/user32/loadres.cpp
r1042 r1196 1 /* $Id: loadres.cpp,v 1. 7 1999-09-25 14:15:54 sandervlExp $ */1 /* $Id: loadres.cpp,v 1.8 1999-10-08 19:34:25 dengert Exp $ */ 2 2 3 3 /* … … 9 9 * 10 10 * Copyright 1993 Alexandre Julliard 11 * 11 * 1998 Huw D M Davies 12 12 * 13 13 * Project Odin Software License can be found in LICENSE.TXT … … 29 29 Win32Resource *winres; 30 30 LPWSTR resstring; 31 int 31 int resstrlen = 0; 32 32 33 33 winres = (Win32Resource *)FindResourceA(hinst, (LPSTR)wID, RT_STRINGA); 34 34 if(winres == NULL) { 35 36 35 dprintf(("LoadStringA NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer)); 36 return 0; 37 37 } 38 38 39 39 resstring = (LPWSTR)winres->lockResource(); 40 40 if(resstring) { 41 42 43 44 45 41 resstrlen = min(lstrlenW(resstring)+1, cchBuffer); 42 lstrcpynWtoA(lpBuffer, resstring, resstrlen); 43 lpBuffer[resstrlen-1] = 0; 44 resstrlen--; 45 dprintf(("LoadStringA (%d) %s", resstrlen, lpBuffer)); 46 46 } 47 47 delete winres; … … 56 56 Win32Resource *winres; 57 57 LPWSTR resstring; 58 int 58 int resstrlen = 0; 59 59 60 60 winres = (Win32Resource *)FindResourceW(hinst, (LPWSTR)wID, RT_STRINGW); 61 61 if(winres == NULL) { 62 63 62 dprintf(("LoadStringW NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer)); 63 return 0; 64 64 } 65 65 66 66 resstring = (LPWSTR)winres->lockResource(); 67 67 if(resstring) { 68 69 70 71 68 resstrlen = min(lstrlenW(resstring)+1, cchBuffer); 69 lstrcpynW(lpBuffer, resstring, resstrlen); 70 lpBuffer[resstrlen-1] = 0; 71 resstrlen--; 72 72 } 73 73 delete winres; … … 81 81 { 82 82 Win32Resource *winres; 83 HICON 83 HICON hIcon; 84 84 85 85 hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon); 86 86 if(hIcon == 0) {//not a system icon 87 88 89 90 91 92 93 94 87 winres = (Win32Resource *)FindResourceA(hinst, lpszIcon, RT_ICONA); 88 if(winres == 0) { 89 winres = (Win32Resource *)FindResourceA(hinst, lpszIcon, RT_GROUP_ICONA); 90 } 91 if(winres) { 92 hIcon = OSLibWinCreateIcon(winres->lockOS2Resource()); 93 delete winres; 94 } 95 95 } 96 96 dprintf(("LoadIconA (%X) returned %x\n", hinst, hIcon)); … … 103 103 { 104 104 Win32Resource *winres; 105 HICON 105 HICON hIcon; 106 106 107 107 hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon); 108 108 if(hIcon == 0) {//not a system icon 109 110 111 112 113 114 115 116 109 winres = (Win32Resource *)FindResourceW(hinst, lpszIcon, RT_ICONW); 110 if(winres == 0) { 111 winres = (Win32Resource *)FindResourceW(hinst, lpszIcon, RT_GROUP_ICONW); 112 } 113 if(winres) { 114 hIcon = OSLibWinCreateIcon(winres->lockOS2Resource()); 115 delete winres; 116 } 117 117 } 118 118 dprintf(("LoadIconW (%X) returned %x\n", hinst, hIcon)); … … 125 125 { 126 126 Win32Resource *winres; 127 HCURSOR 127 HCURSOR hCursor; 128 128 129 129 hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor); 130 130 if(hCursor == 0) {//not a system pointer 131 132 133 134 135 136 137 138 131 winres = (Win32Resource *)FindResourceA(hinst, lpszCursor, RT_CURSORA); 132 if(winres == 0) { 133 winres = (Win32Resource *)FindResourceA(hinst, lpszCursor, RT_GROUP_CURSORA); 134 } 135 if(winres) { 136 hCursor = OSLibWinCreatePointer(winres->lockOS2Resource()); 137 delete winres; 138 } 139 139 } 140 140 if(HIWORD(lpszCursor)) { 141 141 dprintf(("LoadCursorA %s from %x returned %x\n", lpszCursor, hinst, hCursor)); 142 142 } 143 143 else dprintf(("LoadCursorA %x from %x returned %x\n", lpszCursor, hinst, hCursor)); … … 150 150 { 151 151 Win32Resource *winres; 152 HCURSOR 152 HCURSOR hCursor; 153 153 154 154 hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor); 155 155 if(hCursor == 0) {//not a system pointer 156 157 158 159 160 161 162 163 156 winres = (Win32Resource *)FindResourceW(hinst, lpszCursor, RT_CURSORW); 157 if(winres == 0) { 158 winres = (Win32Resource *)FindResourceW(hinst, lpszCursor, RT_GROUP_CURSORW); 159 } 160 if(winres) { 161 hCursor = OSLibWinCreatePointer(winres->lockOS2Resource()); 162 delete winres; 163 } 164 164 } 165 165 dprintf(("LoadCursorW (%X) returned %x\n", hinst, hCursor)); … … 173 173 switch(*id) 174 174 { 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 175 case OBM_UPARROW_W: 176 case OBM_DNARROW_W: 177 case OBM_RGARROW_W: 178 case OBM_LFARROW_W: 179 case OBM_RESTORE_W: 180 case OBM_RESTORED_W: 181 case OBM_UPARROWD_W: 182 case OBM_DNARROWD_W: 183 case OBM_RGARROWD_W: 184 case OBM_LFARROWD_W: 185 case OBM_OLD_UPARROW_W: 186 case OBM_OLD_DNARROW_W: 187 case OBM_OLD_RGARROW_W: 188 case OBM_OLD_LFARROW_W: 189 case OBM_CHECK_W: 190 case OBM_CHECKBOXES_W: 191 case OBM_BTNCORNERS_W: 192 case OBM_COMBO_W: 193 case OBM_REDUCE_W: 194 case OBM_REDUCED_W: 195 case OBM_ZOOM_W: 196 case OBM_ZOOMD_W: 197 case OBM_SIZE_W: 198 case OBM_CLOSE_W: 199 case OBM_MNARROW_W: 200 case OBM_UPARROWI_W: 201 case OBM_DNARROWI_W: 202 case OBM_RGARROWI_W: 203 case OBM_LFARROWI_W: 204 return TRUE; 205 206 //TODO: Not supported by Open32. Replacement may not be accurate 207 case OBM_OLD_CLOSE_W: 208 *id = OBM_CLOSE_W; 209 return TRUE; 210 211 case OBM_BTSIZE_W: 212 *id = OBM_SIZE_W; 213 return TRUE; 214 215 case OBM_OLD_REDUCE_W: 216 *id = OBM_REDUCE_W; 217 return TRUE; 218 219 case OBM_OLD_ZOOM_W: 220 *id = OBM_ZOOM_W; 221 return TRUE; 222 223 case OBM_OLD_RESTORE_W: 224 *id = OBM_RESTORE_W; 225 return TRUE; 226 227 default: 228 return FALSE; 229 229 } 230 230 } … … 233 233 //****************************************************************************** 234 234 HANDLE LoadBitmapA(HINSTANCE hinst, LPCSTR lpszName, int cxDesired, int cyDesired, 235 235 UINT fuLoad) 236 236 { 237 237 HBITMAP hbitmap = 0; … … 252 252 else 253 253 { 254 255 254 if (!(hMapping = VIRTUAL_MapFileA( lpszName, (LPVOID *)&ptr ))) return 0; 255 info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER)); 256 256 } 257 257 258 258 //TODO: This has to be removed once pe2lx stores win32 resources!!! 259 259 if (info->bmiHeader.biSize != sizeof(BITMAPCOREHEADER) && 260 260 info->bmiHeader.biSize != sizeof(BITMAPINFOHEADER)) 261 261 {//assume it contains a file header first 262 info = (BITMAPINFO *)((char *)info + sizeof(BITMAPFILEHEADER)); 263 } 264 265 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS); 262 info = (BITMAPINFO *)((char *)info + sizeof(BITMAPFILEHEADER)); 263 } 264 265 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) { 266 size = sizeof(BITMAPINFOHEADER) + 267 (sizeof (RGBTRIPLE) << ((BITMAPCOREHEADER *)info)->bcBitCount); 268 } else 269 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS); 270 266 271 if ((hFix = GlobalAlloc(0, size)) != NULL) fix_info = (BITMAPINFO *)GlobalLock(hFix); 267 272 if (fix_info) { 268 273 BYTE pix; 269 274 270 memcpy(fix_info, info, size); 271 pix = *((LPBYTE)info+DIB_BitmapInfoSize(info, DIB_RGB_COLORS)); 275 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) { 276 ULONG colors; 277 ULONG *p, *q; 278 279 memset (fix_info, 0, sizeof (BITMAPINFOHEADER)); 280 fix_info->bmiHeader.biSize = sizeof (BITMAPINFOHEADER); 281 fix_info->bmiHeader.biWidth = ((BITMAPCOREHEADER *)info)->bcWidth; 282 fix_info->bmiHeader.biHeight = ((BITMAPCOREHEADER *)info)->bcHeight; 283 fix_info->bmiHeader.biPlanes = ((BITMAPCOREHEADER *)info)->bcPlanes; 284 fix_info->bmiHeader.biBitCount = ((BITMAPCOREHEADER *)info)->bcBitCount; 285 286 p = (PULONG)((char *)info + sizeof(BITMAPCOREHEADER)); 287 q = (PULONG)((char *)fix_info + sizeof(BITMAPINFOHEADER)); 288 for (colors = 1 << fix_info->bmiHeader.biBitCount; colors > 0; colors--) { 289 *q = *p & 0x00FFFFFFUL; 290 q++; 291 p = (PULONG)((char *)p + sizeof (RGBTRIPLE)); 292 } 293 } else 294 memcpy(fix_info, info, size); 295 296 size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS); 297 pix = *((LPBYTE)info + size); 272 298 DIB_FixColorsToLoadflags(fix_info, fuLoad, pix); 273 299 if ((hdc = GetDC(0)) != 0) { 274 275 276 277 278 279 280 281 282 283 284 285 286 300 char *bits = (char *)info + size; 301 if (fuLoad & LR_CREATEDIBSECTION) { 302 DIBSECTION dib; 303 hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0); 304 GetObjectA(hbitmap, sizeof(DIBSECTION), &dib); 305 SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info, 306 DIB_RGB_COLORS); 307 } 308 else { 309 hbitmap = CreateDIBitmap( hdc, &fix_info->bmiHeader, CBM_INIT, 310 bits, fix_info, DIB_RGB_COLORS ); 311 } 312 ReleaseDC( 0, hdc ); 287 313 } 288 314 GlobalUnlock(hFix); … … 300 326 301 327 if(IsSystemBitmap((ULONG *)&lpszBitmap)) { 302 328 hBitmap = O32_LoadBitmap(hinst, lpszBitmap); 303 329 } 304 330 else { 305 331 hBitmap = LoadBitmapA(hinst, lpszBitmap, 0, 0, 0); 306 332 } 307 333 dprintf(("LoadBitmapA returned %08xh\n", hBitmap)); … … 317 343 318 344 if(IsSystemBitmap((ULONG *)&lpszBitmap)) { 319 345 hBitmap = O32_LoadBitmap(hinst, (LPCSTR)lpszBitmap); 320 346 } 321 347 else { 322 323 324 325 348 if(HIWORD(lpszBitmap) != 0) { 349 lpszBitmap = (LPWSTR)UnicodeToAsciiString((LPWSTR)lpszBitmap); 350 } 351 hBitmap = LoadBitmapA(hinst, (LPSTR)lpszBitmap, 0, 0, 0); 326 352 } 327 353 328 354 if(HIWORD(lpszBitmap) != 0) 329 355 FreeAsciiString((LPSTR)lpszBitmap); 330 356 331 357 dprintf(("LoadBitmapW returned %08xh\n", hBitmap)); … … 338 364 //****************************************************************************** 339 365 HANDLE WIN32API LoadImageA(HINSTANCE hinst, LPCSTR lpszName, UINT uType, 340 366 int cxDesired, int cyDesired, UINT fuLoad) 341 367 { 342 368 HANDLE hRet = 0; … … 345 371 346 372 if (fuLoad & LR_DEFAULTSIZE) { 347 348 349 350 351 352 353 354 373 if (uType == IMAGE_ICON) { 374 if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXICON); 375 if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYICON); 376 } 377 else if (uType == IMAGE_CURSOR) { 378 if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXCURSOR); 379 if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYCURSOR); 380 } 355 381 } 356 382 if (fuLoad & LR_LOADFROMFILE) fuLoad &= ~LR_SHARED; 357 383 358 384 switch(uType) { 359 360 361 362 363 364 365 366 367 368 369 370 385 case IMAGE_BITMAP: 386 hRet = (HANDLE)LoadBitmapA(hinst, lpszName, cxDesired, cyDesired, fuLoad); 387 break; 388 case IMAGE_CURSOR: 389 hRet = (HANDLE)LoadCursorA(hinst, lpszName); 390 break; 391 case IMAGE_ICON: 392 hRet = (HANDLE)LoadIconA(hinst, lpszName); 393 break; 394 default: 395 dprintf(("LoadImageA: unsupported type %d!!", uType)); 396 return 0; 371 397 } 372 398 dprintf(("LoadImageA returned %d\n", (int)hRet)); … … 377 403 //****************************************************************************** 378 404 HANDLE WIN32API LoadImageW(HINSTANCE hinst, LPCWSTR lpszName, UINT uType, 379 405 int cxDesired, int cyDesired, UINT fuLoad) 380 406 { 381 407 HANDLE hRet = 0; … … 384 410 385 411 if (fuLoad & LR_DEFAULTSIZE) { 386 387 388 389 390 391 392 393 412 if (uType == IMAGE_ICON) { 413 if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXICON); 414 if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYICON); 415 } 416 else if (uType == IMAGE_CURSOR) { 417 if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXCURSOR); 418 if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYCURSOR); 419 } 394 420 } 395 421 if (fuLoad & LR_LOADFROMFILE) fuLoad &= ~LR_SHARED; 396 422 397 423 switch(uType) { 398 399 400 401 402 403 404 405 406 407 408 409 424 case IMAGE_BITMAP: 425 hRet = (HANDLE)LoadBitmapW(hinst, lpszName); 426 break; 427 case IMAGE_CURSOR: 428 hRet = (HANDLE)LoadCursorW(hinst, lpszName); 429 break; 430 case IMAGE_ICON: 431 hRet = (HANDLE)LoadIconW(hinst, lpszName); 432 break; 433 default: 434 dprintf(("LoadImageW: unsupported type %d!!", uType)); 435 return 0; 410 436 } 411 437 dprintf(("LoadImageW returned %d\n", (int)hRet));
Note:
See TracChangeset
for help on using the changeset viewer.