[9796] | 1 | /* $Id: loadres.cpp,v 1.41 2003-02-13 13:10:49 sandervl Exp $ */
|
---|
[2469] | 2 |
|
---|
| 3 | /*
|
---|
| 4 | * Win32 resource API functions for OS/2
|
---|
| 5 | *
|
---|
| 6 | * Copyright 1998 Sander van Leeuwen
|
---|
| 7 | *
|
---|
| 8 | * Parts based on Wine code (objects\bitmap.c, loader\resource.c, objects\cursoricon.c):
|
---|
| 9 | *
|
---|
| 10 | * Copyright 1993 Alexandre Julliard
|
---|
| 11 | * 1993 Robert J. Amstadt
|
---|
| 12 | * 1996 Martin Von Loewis
|
---|
| 13 | * 1997 Alex Korobka
|
---|
| 14 | * 1998 Turchanov Sergey
|
---|
| 15 | * 1998 Huw D M Davies
|
---|
| 16 | *
|
---|
| 17 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
| 18 | *
|
---|
| 19 | */
|
---|
| 20 | #include <os2win.h>
|
---|
[21916] | 21 | #include "user32.h"
|
---|
[2469] | 22 | #include <heapstring.h>
|
---|
[21916] | 23 | #include "oslibres.h"
|
---|
| 24 | #include <win/virtual.h>
|
---|
[2469] | 25 | #include "dib.h"
|
---|
| 26 | #include "initterm.h"
|
---|
[3625] | 27 | #include <winres.h>
|
---|
[8112] | 28 | #include <custombuild.h>
|
---|
[5385] | 29 | #include "pmwindow.h"
|
---|
[2469] | 30 |
|
---|
[2857] | 31 | #define DBG_LOCALLOG DBG_loadres
|
---|
[2804] | 32 | #include "dbglocal.h"
|
---|
| 33 |
|
---|
[2469] | 34 | //******************************************************************************
|
---|
| 35 | //******************************************************************************
|
---|
| 36 | INT WIN32API LoadStringA(HINSTANCE instance, UINT resource_id,
|
---|
| 37 | LPSTR buffer, INT buflen )
|
---|
| 38 | {
|
---|
| 39 | INT retval;
|
---|
| 40 | LPWSTR buffer2 = NULL;
|
---|
| 41 |
|
---|
| 42 | if (buffer && buflen)
|
---|
| 43 | buffer2 = (LPWSTR)HeapAlloc( GetProcessHeap(), 0, buflen * 2 );
|
---|
| 44 |
|
---|
| 45 | retval = LoadStringW(instance,resource_id,buffer2,buflen);
|
---|
| 46 |
|
---|
| 47 | if (buffer2)
|
---|
| 48 | {
|
---|
| 49 | if (retval) {
|
---|
| 50 | lstrcpynWtoA( buffer, buffer2, buflen );
|
---|
| 51 | retval = lstrlenA( buffer );
|
---|
| 52 | }
|
---|
| 53 | else
|
---|
[6348] | 54 | *buffer = 0; //NT4, SP6 clears first character
|
---|
[2469] | 55 | HeapFree( GetProcessHeap(), 0, buffer2 );
|
---|
| 56 | }
|
---|
| 57 | return retval;
|
---|
| 58 | }
|
---|
| 59 | //******************************************************************************
|
---|
| 60 | //******************************************************************************
|
---|
| 61 | int WIN32API LoadStringW(HINSTANCE hinst, UINT wID, LPWSTR lpBuffer, int cchBuffer)
|
---|
| 62 | {
|
---|
| 63 | WCHAR *p;
|
---|
| 64 | int string_num;
|
---|
| 65 | int i = 0;
|
---|
[3625] | 66 | HRSRC hRes;
|
---|
[2469] | 67 |
|
---|
| 68 | /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out
|
---|
| 69 | * 20 - 31. */
|
---|
[3625] | 70 | hRes = FindResourceW(hinst, (LPWSTR)(((wID>>4)&0xffff)+1), RT_STRINGW);
|
---|
| 71 | if(hRes == NULL) {
|
---|
[21916] | 72 | dprintf(("LoadStringW NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
---|
[6348] | 73 | *lpBuffer = 0; //NT4, SP6 clears first character
|
---|
[2469] | 74 | return 0;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
[3625] | 77 | p = (LPWSTR)LockResource(LoadResource(hinst, hRes));
|
---|
[2469] | 78 | if(p) {
|
---|
| 79 | string_num = wID & 0x000f;
|
---|
| 80 | for (i = 0; i < string_num; i++)
|
---|
| 81 | p += *p + 1;
|
---|
| 82 |
|
---|
| 83 | if (lpBuffer == NULL) return *p;
|
---|
| 84 | i = min(cchBuffer - 1, *p);
|
---|
| 85 | if (i > 0) {
|
---|
| 86 | memcpy(lpBuffer, p + 1, i * sizeof (WCHAR));
|
---|
| 87 | lpBuffer[i] = (WCHAR) 0;
|
---|
| 88 | }
|
---|
| 89 | else {
|
---|
| 90 | if (cchBuffer > 1) {
|
---|
[6348] | 91 | lpBuffer[0] = (WCHAR) 0; //NT4, SP6 clears first character
|
---|
[2469] | 92 | return 0;
|
---|
| 93 | }
|
---|
| 94 | }
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | if(i) {
|
---|
[5391] | 98 | dprintf(("LoadStringW from %X, id %d %ls buffersize %d", hinst, wID, lpBuffer, cchBuffer));
|
---|
[2469] | 99 | }
|
---|
[5391] | 100 | else dprintf(("LoadStringW from %X, id %d buffersize %d", hinst, wID, cchBuffer));
|
---|
[2469] | 101 | return(i);
|
---|
| 102 | }
|
---|
| 103 | //******************************************************************************
|
---|
| 104 | //******************************************************************************
|
---|
[4573] | 105 | HICON WIN32API LoadIconA(HINSTANCE hinst, LPCSTR lpszIcon)
|
---|
[2469] | 106 | {
|
---|
[4573] | 107 | if(HIWORD(lpszIcon)) {
|
---|
| 108 | dprintf(("LoadIconA %x %s", hinst, lpszIcon));
|
---|
[2469] | 109 | }
|
---|
[4573] | 110 | else dprintf(("LoadIconA %x %x", hinst, lpszIcon));
|
---|
| 111 | return LoadImageA(hinst, lpszIcon, IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE);
|
---|
[2469] | 112 | }
|
---|
| 113 | //******************************************************************************
|
---|
| 114 | //******************************************************************************
|
---|
[3419] | 115 | HICON WIN32API LoadIconW(HINSTANCE hinst, LPCWSTR lpszIcon)
|
---|
| 116 | {
|
---|
[5391] | 117 | if(HIWORD(lpszIcon)) {
|
---|
| 118 | dprintf(("LoadIconW %x %ls", hinst, lpszIcon));
|
---|
| 119 | }
|
---|
| 120 | else dprintf(("LoadIconW %x %x", hinst, lpszIcon));
|
---|
[4573] | 121 | return LoadImageW(hinst, lpszIcon, IMAGE_ICON, 0, 0, LR_SHARED | LR_DEFAULTSIZE);
|
---|
[3419] | 122 | }
|
---|
| 123 | //******************************************************************************
|
---|
| 124 | //******************************************************************************
|
---|
| 125 | HCURSOR WIN32API LoadCursorA(HINSTANCE hinst, LPCSTR lpszCursor)
|
---|
| 126 | {
|
---|
[4573] | 127 | return LoadImageA(hinst, lpszCursor, IMAGE_CURSOR, 0, 0,
|
---|
| 128 | LR_SHARED | LR_DEFAULTSIZE );
|
---|
[3419] | 129 | }
|
---|
| 130 | //******************************************************************************
|
---|
| 131 | //******************************************************************************
|
---|
| 132 | HCURSOR WIN32API LoadCursorW(HINSTANCE hinst, LPCWSTR lpszCursor)
|
---|
| 133 | {
|
---|
[4573] | 134 | return LoadImageW(hinst, lpszCursor, IMAGE_CURSOR, 0, 0,
|
---|
| 135 | LR_SHARED | LR_DEFAULTSIZE );
|
---|
[3419] | 136 | }
|
---|
[4573] | 137 | /***********************************************************************
|
---|
| 138 | * LoadCursorFromFileW (USER32.361)
|
---|
| 139 | */
|
---|
| 140 | HCURSOR WIN32API LoadCursorFromFileW (LPCWSTR name)
|
---|
[2469] | 141 | {
|
---|
[4573] | 142 | return LoadImageW(0, name, IMAGE_CURSOR, 0, 0,
|
---|
| 143 | LR_LOADFROMFILE | LR_DEFAULTSIZE );
|
---|
[2469] | 144 | }
|
---|
[4573] | 145 | /***********************************************************************
|
---|
| 146 | * LoadCursorFromFileA (USER32.360)
|
---|
| 147 | */
|
---|
| 148 | HCURSOR WIN32API LoadCursorFromFileA (LPCSTR name)
|
---|
| 149 | {
|
---|
| 150 | return LoadImageA(0, name, IMAGE_CURSOR, 0, 0,
|
---|
| 151 | LR_LOADFROMFILE | LR_DEFAULTSIZE );
|
---|
| 152 | }
|
---|
[2469] | 153 | //******************************************************************************
|
---|
[4573] | 154 | //NOTE: LR_CREATEDIBSECTION flag doesn't work (crash in GDI32)! (still??)
|
---|
[2469] | 155 | //******************************************************************************
|
---|
[4573] | 156 | HANDLE LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszName, int cxDesired, int cyDesired,
|
---|
[2469] | 157 | UINT fuLoad)
|
---|
| 158 | {
|
---|
| 159 | HBITMAP hbitmap = 0;
|
---|
| 160 | HDC hdc;
|
---|
| 161 | HRSRC hRsrc;
|
---|
| 162 | HGLOBAL handle, hMapping = 0;
|
---|
| 163 | char *ptr = NULL;
|
---|
| 164 | BITMAPINFO *info, *fix_info=NULL;
|
---|
| 165 | HGLOBAL hFix;
|
---|
| 166 | int size;
|
---|
| 167 |
|
---|
[9437] | 168 | //if in OS/2 mode, then we must replace the standard button bitmaps
|
---|
| 169 | //(min, max, restore, close)
|
---|
[21303] | 170 | //(NOTE: if hBmpCloseButton present until WGSS has been updated)
|
---|
| 171 | if(fOS2Look && (hinst == hInstanceUser32 || !hinst) && hBmpCloseButton) {
|
---|
[9437] | 172 | switch((ULONG)lpszName) {
|
---|
| 173 | case OBM_CLOSE:
|
---|
| 174 | return CopyImage(hBmpCloseButton, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 175 | case OBM_CLOSED:
|
---|
| 176 | return CopyImage(hBmpCloseButtonDown, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 177 | case OBM_RESTORE:
|
---|
| 178 | return CopyImage(hBmpRestoreButton, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 179 | case OBM_RESTORED:
|
---|
| 180 | return CopyImage(hBmpRestoreButtonDown, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 181 | case OBM_REDUCE:
|
---|
| 182 | return CopyImage(hBmpMinButton, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 183 | case OBM_REDUCED:
|
---|
| 184 | return CopyImage(hBmpMinButtonDown, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 185 | case OBM_ZOOM:
|
---|
| 186 | return CopyImage(hBmpMaxButton, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 187 | case OBM_ZOOMD:
|
---|
| 188 | return CopyImage(hBmpMaxButtonDown, IMAGE_BITMAP, 0, 0, 0);
|
---|
| 189 | }
|
---|
| 190 | }
|
---|
[4573] | 191 | if (!(fuLoad & LR_LOADFROMFILE))
|
---|
| 192 | {
|
---|
| 193 | handle = 0;
|
---|
| 194 | if(!hinst)
|
---|
| 195 | {
|
---|
| 196 | hRsrc = FindResourceW( hInstanceUser32, lpszName, RT_BITMAPW );
|
---|
| 197 | if(hRsrc) {
|
---|
| 198 | handle = LoadResource( hInstanceUser32, hRsrc );
|
---|
| 199 | }
|
---|
| 200 | }
|
---|
| 201 | if(handle == 0)
|
---|
| 202 | {
|
---|
| 203 | if (!(hRsrc = FindResourceW( hinst, lpszName, RT_BITMAPW ))) return 0;
|
---|
| 204 | if (!(handle = LoadResource( hinst, hRsrc ))) return 0;
|
---|
| 205 | }
|
---|
[2469] | 206 |
|
---|
[4573] | 207 | if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
|
---|
[2469] | 208 | }
|
---|
| 209 | else
|
---|
| 210 | {
|
---|
[4573] | 211 | hMapping = VIRTUAL_MapFileW( lpszName, (LPVOID *)&ptr, TRUE);
|
---|
[4421] | 212 | if (hMapping == INVALID_HANDLE_VALUE) {
|
---|
[4573] | 213 | //TODO: last err set to ERROR_OPEN_FAILED if file not found; correct??
|
---|
| 214 | dprintf(("LoadBitmapW: failed to load file %x (lasterr=%x)", lpszName, GetLastError()));
|
---|
| 215 | return 0;
|
---|
| 216 | }
|
---|
[2469] | 217 | info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
|
---|
| 218 | }
|
---|
| 219 |
|
---|
| 220 | //TODO: This has to be removed once pe2lx stores win32 resources!!!
|
---|
| 221 | if (info->bmiHeader.biSize != sizeof(BITMAPCOREHEADER) &&
|
---|
| 222 | info->bmiHeader.biSize != sizeof(BITMAPINFOHEADER))
|
---|
| 223 | {//assume it contains a file header first
|
---|
| 224 | info = (BITMAPINFO *)((char *)info + sizeof(BITMAPFILEHEADER));
|
---|
| 225 | }
|
---|
| 226 |
|
---|
[4586] | 227 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
|
---|
| 228 | {//determine size of converted header
|
---|
| 229 | BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)info;
|
---|
[2469] | 230 |
|
---|
[4586] | 231 | int colors = 0;
|
---|
| 232 | if (core->bcBitCount <= 8) {
|
---|
| 233 | colors = (1 << core->bcBitCount);
|
---|
| 234 | }
|
---|
| 235 | size = sizeof(BITMAPINFOHEADER) + colors * sizeof(RGBQUAD);
|
---|
| 236 | }
|
---|
| 237 | else size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
|
---|
| 238 |
|
---|
[2469] | 239 | if ((hFix = GlobalAlloc(0, size)) != NULL) fix_info = (BITMAPINFO *)GlobalLock(hFix);
|
---|
[4586] | 240 | if (fix_info)
|
---|
| 241 | {
|
---|
[2469] | 242 | BYTE pix;
|
---|
| 243 |
|
---|
[4586] | 244 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
|
---|
| 245 | {//convert old bitmap header to new format
|
---|
| 246 | ULONG colors;
|
---|
| 247 | ULONG *p, *q;
|
---|
[2469] | 248 |
|
---|
[4586] | 249 | memset (fix_info, 0, sizeof (BITMAPINFOHEADER));
|
---|
| 250 | fix_info->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
|
---|
| 251 | fix_info->bmiHeader.biWidth = ((BITMAPCOREHEADER *)info)->bcWidth;
|
---|
| 252 | fix_info->bmiHeader.biHeight = ((BITMAPCOREHEADER *)info)->bcHeight;
|
---|
| 253 | fix_info->bmiHeader.biPlanes = ((BITMAPCOREHEADER *)info)->bcPlanes;
|
---|
| 254 | fix_info->bmiHeader.biBitCount = ((BITMAPCOREHEADER *)info)->bcBitCount;
|
---|
[2469] | 255 |
|
---|
[4586] | 256 | if(fix_info->bmiHeader.biBitCount <= 8)
|
---|
| 257 | {
|
---|
| 258 | p = (PULONG)((char *)info + sizeof(BITMAPCOREHEADER));
|
---|
| 259 | q = (PULONG)((char *)fix_info + sizeof(BITMAPINFOHEADER));
|
---|
| 260 | //convert RGBTRIPLE to RGBQUAD
|
---|
| 261 | for (colors = 1 << fix_info->bmiHeader.biBitCount; colors > 0; colors--) {
|
---|
| 262 | *q = *p & 0x00FFFFFFUL;
|
---|
| 263 | q++;
|
---|
| 264 | p = (PULONG)((char *)p + sizeof (RGBTRIPLE));
|
---|
| 265 | }
|
---|
| 266 | }
|
---|
| 267 | }
|
---|
| 268 | else {
|
---|
| 269 | memcpy(fix_info, info, size);
|
---|
| 270 | }
|
---|
[2469] | 271 |
|
---|
| 272 | size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
|
---|
[4586] | 273 |
|
---|
[2469] | 274 | pix = *((LPBYTE)info + size);
|
---|
| 275 | DIB_FixColorsToLoadflags(fix_info, fuLoad, pix);
|
---|
[5798] | 276 | if ((hdc = CreateCompatibleDC(0)) != 0)
|
---|
[4586] | 277 | {
|
---|
[2469] | 278 | char *bits = (char *)info + size;
|
---|
| 279 | if (fuLoad & LR_CREATEDIBSECTION) {
|
---|
| 280 | DIBSECTION dib;
|
---|
| 281 | hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
|
---|
| 282 | GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
|
---|
| 283 | SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
|
---|
| 284 | DIB_RGB_COLORS);
|
---|
| 285 | }
|
---|
[4586] | 286 | else
|
---|
| 287 | {
|
---|
| 288 | #if 0
|
---|
| 289 | if(fix_info->bmiHeader.biBitCount == 1) {
|
---|
| 290 | hbitmap = CreateBitmap(fix_info->bmiHeader.biWidth,
|
---|
| 291 | fix_info->bmiHeader.biHeight,
|
---|
| 292 | fix_info->bmiHeader.biPlanes,
|
---|
| 293 | fix_info->bmiHeader.biBitCount,
|
---|
| 294 | (PVOID)bits);
|
---|
| 295 | }
|
---|
| 296 | else {
|
---|
| 297 | #endif
|
---|
| 298 | hbitmap = CreateDIBitmap(hdc, &fix_info->bmiHeader, CBM_INIT,
|
---|
| 299 | bits, fix_info, DIB_RGB_COLORS );
|
---|
| 300 | // }
|
---|
| 301 | if(hbitmap == 0) {
|
---|
| 302 | dprintf(("LoadBitmapW: CreateDIBitmap failed!!"));
|
---|
| 303 | }
|
---|
[4573] | 304 | }
|
---|
[5798] | 305 | DeleteDC(hdc);
|
---|
[2469] | 306 | }
|
---|
| 307 | GlobalUnlock(hFix);
|
---|
| 308 | GlobalFree(hFix);
|
---|
| 309 | }
|
---|
[4573] | 310 | if(fuLoad & LR_LOADFROMFILE) {
|
---|
| 311 | UnmapViewOfFile(ptr);
|
---|
| 312 | CloseHandle(hMapping);
|
---|
| 313 | }
|
---|
[2469] | 314 | return hbitmap;
|
---|
| 315 | }
|
---|
| 316 | //******************************************************************************
|
---|
[4573] | 317 | //TODO: scale bitmap
|
---|
| 318 | //******************************************************************************
|
---|
| 319 | HANDLE CopyBitmap(HANDLE hBitmap, DWORD desiredx, DWORD desiredy)
|
---|
| 320 | {
|
---|
| 321 | HBITMAP res = 0;
|
---|
| 322 | BITMAP bm;
|
---|
| 323 |
|
---|
| 324 | if(GetObjectA(hBitmap, sizeof(BITMAP), &bm) == FALSE) {
|
---|
| 325 | dprintf(("CopyBitmap: GetObject failed!!"));
|
---|
| 326 | return 0;
|
---|
| 327 | }
|
---|
| 328 |
|
---|
[9437] | 329 | #ifdef __WIN32OS2__
|
---|
| 330 | BITMAPINFO* pInfo;
|
---|
| 331 | HBITMAP oldbmp;
|
---|
| 332 | HDC hdc;
|
---|
| 333 | int colortablesize, bmpsize, headersize;
|
---|
| 334 | char *pBitmapData;
|
---|
| 335 |
|
---|
| 336 | colortablesize = 0;
|
---|
| 337 |
|
---|
| 338 | if(bm.bmBitsPixel <= 8) {
|
---|
| 339 | colortablesize = sizeof(RGBQUAD)*(1<<bm.bmBitsPixel);
|
---|
| 340 | }
|
---|
| 341 | bmpsize = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, bm.bmBitsPixel);
|
---|
| 342 | headersize = sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD); //+ extra space for > 8bpp images
|
---|
| 343 |
|
---|
[21916] | 344 | pInfo = (BITMAPINFO *)malloc(headersize+bmpsize);
|
---|
[9437] | 345 | if(pInfo == NULL) {
|
---|
| 346 | DebugInt3();
|
---|
| 347 | return 0;
|
---|
| 348 | }
|
---|
| 349 | pBitmapData = (char*)((char *)pInfo + headersize);
|
---|
| 350 | memset(pInfo, 0, headersize+bmpsize);
|
---|
| 351 |
|
---|
| 352 | hdc = CreateCompatibleDC(0);
|
---|
| 353 |
|
---|
| 354 | pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
---|
| 355 | pInfo->bmiHeader.biPlanes = bm.bmPlanes;
|
---|
| 356 | pInfo->bmiHeader.biBitCount = bm.bmBitsPixel;
|
---|
| 357 | pInfo->bmiHeader.biWidth = bm.bmWidth;
|
---|
| 358 | pInfo->bmiHeader.biHeight = bm.bmHeight;
|
---|
| 359 |
|
---|
| 360 | GetDIBits(hdc, hBitmap, 0, bm.bmHeight, pBitmapData, pInfo, DIB_RGB_COLORS);
|
---|
| 361 |
|
---|
[21916] | 362 | res = CreateDIBitmap(hdc, &pInfo->bmiHeader, CBM_INIT, pBitmapData,
|
---|
[9437] | 363 | pInfo, DIB_RGB_COLORS );
|
---|
| 364 |
|
---|
| 365 | DeleteDC(hdc);
|
---|
| 366 | free(pInfo);
|
---|
| 367 | #else
|
---|
[4573] | 368 | bm.bmBits = NULL;
|
---|
| 369 | res = CreateBitmapIndirect(&bm);
|
---|
| 370 |
|
---|
| 371 | if(res)
|
---|
| 372 | {
|
---|
| 373 | char *buf = (char *)HeapAlloc( GetProcessHeap(), 0, bm.bmWidthBytes *
|
---|
| 374 | bm.bmHeight );
|
---|
| 375 | GetBitmapBits (hBitmap, bm.bmWidthBytes * bm.bmHeight, buf);
|
---|
| 376 | SetBitmapBits (res, bm.bmWidthBytes * bm.bmHeight, buf);
|
---|
| 377 | HeapFree( GetProcessHeap(), 0, buf );
|
---|
| 378 | }
|
---|
[9437] | 379 | #endif
|
---|
[4573] | 380 | return res;
|
---|
| 381 | }
|
---|
| 382 | //******************************************************************************
|
---|
[2469] | 383 | //TODO: No support for RT_NEWBITMAP
|
---|
| 384 | //******************************************************************************
|
---|
| 385 | HBITMAP WIN32API LoadBitmapA(HINSTANCE hinst, LPCSTR lpszBitmap)
|
---|
| 386 | {
|
---|
| 387 | HBITMAP hBitmap = 0;
|
---|
| 388 |
|
---|
[4573] | 389 | hBitmap = LoadImageA(hinst, lpszBitmap, IMAGE_BITMAP, 0, 0, 0);
|
---|
[2469] | 390 |
|
---|
[3625] | 391 | if(HIWORD(lpszBitmap)) {
|
---|
[4573] | 392 | dprintf(("LoadBitmapA %x %s returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
---|
[3625] | 393 | }
|
---|
| 394 | else dprintf(("LoadBitmapA %x %x returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
---|
[2469] | 395 |
|
---|
| 396 | return(hBitmap);
|
---|
| 397 | }
|
---|
| 398 | //******************************************************************************
|
---|
| 399 | //TODO: No support for RT_NEWBITMAP
|
---|
| 400 | //******************************************************************************
|
---|
| 401 | HBITMAP WIN32API LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszBitmap)
|
---|
| 402 | {
|
---|
| 403 | HBITMAP hBitmap = 0;
|
---|
| 404 |
|
---|
[4573] | 405 | hBitmap = LoadBitmapW((hinst == 0) ? hInstanceUser32:hinst, lpszBitmap, 0, 0, 0);
|
---|
[2469] | 406 |
|
---|
[3625] | 407 | if(HIWORD(lpszBitmap)) {
|
---|
[5391] | 408 | dprintf(("LoadBitmapW %x %ls returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
---|
[3625] | 409 | }
|
---|
| 410 | else dprintf(("LoadBitmapW %x %x returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
---|
[2469] | 411 |
|
---|
| 412 | return(hBitmap);
|
---|
| 413 | }
|
---|
| 414 | //******************************************************************************
|
---|
| 415 | //******************************************************************************
|
---|
[8112] | 416 | static PFNLOADIMAGEW pfnCustomLoadImageW = NULL;
|
---|
| 417 | //******************************************************************************
|
---|
| 418 | //Called by custom Odin builds to hook LoadImageW
|
---|
| 419 | //******************************************************************************
|
---|
| 420 | BOOL WIN32API SetCustomLoadImage(PFNLOADIMAGEW pfnLoadImageW)
|
---|
| 421 | {
|
---|
| 422 | pfnCustomLoadImageW = pfnLoadImageW;
|
---|
| 423 | return TRUE;
|
---|
| 424 | }
|
---|
| 425 | //******************************************************************************
|
---|
| 426 | //******************************************************************************
|
---|
[2469] | 427 | HANDLE WIN32API LoadImageA(HINSTANCE hinst, LPCSTR lpszName, UINT uType,
|
---|
| 428 | int cxDesired, int cyDesired, UINT fuLoad)
|
---|
| 429 | {
|
---|
[4573] | 430 | HANDLE res = 0;
|
---|
| 431 | LPCWSTR u_name;
|
---|
[2469] | 432 |
|
---|
| 433 | if(HIWORD(lpszName)) {
|
---|
[4573] | 434 | dprintf(("LoadImageA %x %s %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
|
---|
[2469] | 435 | }
|
---|
[4573] | 436 | else dprintf(("LoadImageA %x %x %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
|
---|
[2469] | 437 |
|
---|
[4573] | 438 | if (HIWORD(lpszName)) {
|
---|
| 439 | u_name = HEAP_strdupAtoW(GetProcessHeap(), 0, lpszName);
|
---|
[2469] | 440 | }
|
---|
[4573] | 441 | else u_name=(LPWSTR)lpszName;
|
---|
[2469] | 442 |
|
---|
[4573] | 443 | res = LoadImageW(hinst, u_name, uType, cxDesired, cyDesired, fuLoad);
|
---|
[2469] | 444 |
|
---|
[4573] | 445 | if (HIWORD(lpszName))
|
---|
| 446 | HeapFree(GetProcessHeap(), 0, (LPVOID)u_name);
|
---|
| 447 |
|
---|
| 448 | return res;
|
---|
[2469] | 449 | }
|
---|
| 450 | //******************************************************************************
|
---|
| 451 | //******************************************************************************
|
---|
| 452 | HANDLE WIN32API LoadImageW(HINSTANCE hinst, LPCWSTR lpszName, UINT uType,
|
---|
[4573] | 453 | int cxDesired, int cyDesired, UINT fuLoad)
|
---|
[2469] | 454 | {
|
---|
| 455 | HANDLE hRet = 0;
|
---|
| 456 |
|
---|
[8112] | 457 | if(pfnCustomLoadImageW) {
|
---|
| 458 | pfnCustomLoadImageW(&hinst, (LPWSTR *)&lpszName, &uType);
|
---|
| 459 | }
|
---|
| 460 |
|
---|
[5391] | 461 | if(HIWORD(lpszName)) {
|
---|
[8112] | 462 | dprintf(("LoadImageW %x %ls %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
|
---|
[5391] | 463 | }
|
---|
[8112] | 464 | else dprintf(("LoadImageW %x %x %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
|
---|
[2469] | 465 |
|
---|
| 466 | if (fuLoad & LR_DEFAULTSIZE) {
|
---|
| 467 | if (uType == IMAGE_ICON) {
|
---|
| 468 | if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXICON);
|
---|
| 469 | if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYICON);
|
---|
| 470 | }
|
---|
| 471 | else if (uType == IMAGE_CURSOR) {
|
---|
| 472 | if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXCURSOR);
|
---|
| 473 | if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYCURSOR);
|
---|
| 474 | }
|
---|
| 475 | }
|
---|
| 476 | if (fuLoad & LR_LOADFROMFILE) fuLoad &= ~LR_SHARED;
|
---|
| 477 |
|
---|
[4573] | 478 | switch (uType)
|
---|
| 479 | {
|
---|
[2469] | 480 | case IMAGE_BITMAP:
|
---|
[4573] | 481 | {
|
---|
| 482 | hRet = (HANDLE)LoadBitmapW(hinst, lpszName, cxDesired, cyDesired, fuLoad);
|
---|
| 483 | break;
|
---|
| 484 | }
|
---|
| 485 | case IMAGE_ICON:
|
---|
| 486 | {
|
---|
[5385] | 487 | #ifdef __WIN32OS2__
|
---|
| 488 | ULONG palEnts = (1 << ScreenBitsPerPel);
|
---|
| 489 | #else
|
---|
[4573] | 490 | HDC hdc = GetDC(0);
|
---|
| 491 | UINT palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
|
---|
| 492 | if (palEnts == 0)
|
---|
| 493 | palEnts = 256;
|
---|
| 494 | ReleaseDC(0, hdc);
|
---|
[5385] | 495 | #endif
|
---|
[4573] | 496 |
|
---|
| 497 | hRet = CURSORICON_Load(hinst, lpszName, cxDesired, cyDesired, palEnts, FALSE, fuLoad);
|
---|
| 498 | break;
|
---|
| 499 | }
|
---|
| 500 |
|
---|
[2469] | 501 | case IMAGE_CURSOR:
|
---|
[5385] | 502 | return CURSORICON_Load(hinst, lpszName, cxDesired, cyDesired, 1, TRUE, fuLoad);
|
---|
[4573] | 503 |
|
---|
[2469] | 504 | default:
|
---|
[5385] | 505 | dprintf(("LoadImageW: unsupported type %d!!", uType));
|
---|
| 506 | return 0;
|
---|
[2469] | 507 | }
|
---|
[3462] | 508 | dprintf(("LoadImageW returned %x\n", (int)hRet));
|
---|
[2469] | 509 |
|
---|
| 510 | return(hRet);
|
---|
| 511 | }
|
---|
| 512 | /******************************************************************************
|
---|
| 513 | * CopyImage32 [USER32.61] Creates new image and copies attributes to it
|
---|
| 514 | *
|
---|
| 515 | * PARAMS
|
---|
| 516 | * hnd [I] Handle to image to copy
|
---|
| 517 | * type [I] Type of image to copy
|
---|
| 518 | * desiredx [I] Desired width of new image
|
---|
| 519 | * desiredy [I] Desired height of new image
|
---|
| 520 | * flags [I] Copy flags
|
---|
| 521 | *
|
---|
| 522 | * RETURNS
|
---|
| 523 | * Success: Handle to newly created image
|
---|
| 524 | * Failure: NULL
|
---|
| 525 | *
|
---|
| 526 | * FIXME: implementation still lacks nearly all features, see LR_*
|
---|
| 527 | * defines in windows.h
|
---|
| 528 | *
|
---|
| 529 | */
|
---|
[4573] | 530 | HICON WINAPI CopyImage(HANDLE hnd, UINT type, INT desiredx,
|
---|
| 531 | INT desiredy, UINT flags )
|
---|
[2469] | 532 | {
|
---|
| 533 | dprintf(("CopyImage %x %d (%d,%d) %x", hnd, type, desiredx, desiredy, flags));
|
---|
| 534 | switch (type)
|
---|
| 535 | {
|
---|
[4573] | 536 | case IMAGE_BITMAP:
|
---|
| 537 | return CopyBitmap(hnd, desiredx, desiredy);
|
---|
[2469] | 538 | case IMAGE_ICON:
|
---|
[4573] | 539 | return (HANDLE)CURSORICON_ExtCopy(hnd, type, desiredx, desiredy, flags);
|
---|
[2469] | 540 | case IMAGE_CURSOR:
|
---|
[5385] | 541 | /* Should call CURSORICON_ExtCopy but more testing
|
---|
| 542 | * needs to be done before we change this
|
---|
| 543 | */
|
---|
| 544 | return CURSORICON_ExtCopy(hnd,type, desiredx, desiredy, flags);
|
---|
[2469] | 545 | default:
|
---|
| 546 | dprintf(("CopyImage: Unsupported type"));
|
---|
| 547 | }
|
---|
| 548 | return 0;
|
---|
| 549 | }
|
---|
| 550 | //******************************************************************************
|
---|
| 551 | //******************************************************************************
|
---|