| 1 | /* $Id: loadres.cpp,v 1.29 2000-05-28 16:43:45 sandervl Exp $ */
|
|---|
| 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>
|
|---|
| 21 | #include <user32.h>
|
|---|
| 22 | #include <heapstring.h>
|
|---|
| 23 | #include <oslibres.h>
|
|---|
| 24 | #include <win\virtual.h>
|
|---|
| 25 | #include "dib.h"
|
|---|
| 26 | #include "initterm.h"
|
|---|
| 27 | #include <win\cursoricon.h>
|
|---|
| 28 | #include <winres.h>
|
|---|
| 29 |
|
|---|
| 30 | #define DBG_LOCALLOG DBG_loadres
|
|---|
| 31 | #include "dbglocal.h"
|
|---|
| 32 |
|
|---|
| 33 | //******************************************************************************
|
|---|
| 34 | //******************************************************************************
|
|---|
| 35 | INT WIN32API LoadStringA(HINSTANCE instance, UINT resource_id,
|
|---|
| 36 | LPSTR buffer, INT buflen )
|
|---|
| 37 | {
|
|---|
| 38 | INT retval;
|
|---|
| 39 | LPWSTR buffer2 = NULL;
|
|---|
| 40 |
|
|---|
| 41 | if (buffer && buflen)
|
|---|
| 42 | buffer2 = (LPWSTR)HeapAlloc( GetProcessHeap(), 0, buflen * 2 );
|
|---|
| 43 |
|
|---|
| 44 | retval = LoadStringW(instance,resource_id,buffer2,buflen);
|
|---|
| 45 |
|
|---|
| 46 | if (buffer2)
|
|---|
| 47 | {
|
|---|
| 48 | if (retval) {
|
|---|
| 49 | lstrcpynWtoA( buffer, buffer2, buflen );
|
|---|
| 50 | retval = lstrlenA( buffer );
|
|---|
| 51 | }
|
|---|
| 52 | else
|
|---|
| 53 | *buffer = 0;
|
|---|
| 54 | HeapFree( GetProcessHeap(), 0, buffer2 );
|
|---|
| 55 | }
|
|---|
| 56 | return retval;
|
|---|
| 57 | }
|
|---|
| 58 | //******************************************************************************
|
|---|
| 59 | //******************************************************************************
|
|---|
| 60 | int WIN32API LoadStringW(HINSTANCE hinst, UINT wID, LPWSTR lpBuffer, int cchBuffer)
|
|---|
| 61 | {
|
|---|
| 62 | WCHAR *p;
|
|---|
| 63 | int string_num;
|
|---|
| 64 | int i = 0;
|
|---|
| 65 | HRSRC hRes;
|
|---|
| 66 |
|
|---|
| 67 | /* Use bits 4 - 19 (incremented by 1) as resourceid, mask out
|
|---|
| 68 | * 20 - 31. */
|
|---|
| 69 | hRes = FindResourceW(hinst, (LPWSTR)(((wID>>4)&0xffff)+1), RT_STRINGW);
|
|---|
| 70 | if(hRes == NULL) {
|
|---|
| 71 | dprintf(("LoadStringW NOT FOUND from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
|---|
| 72 | *lpBuffer = 0;
|
|---|
| 73 | return 0;
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | p = (LPWSTR)LockResource(LoadResource(hinst, hRes));
|
|---|
| 77 | if(p) {
|
|---|
| 78 | string_num = wID & 0x000f;
|
|---|
| 79 | for (i = 0; i < string_num; i++)
|
|---|
| 80 | p += *p + 1;
|
|---|
| 81 |
|
|---|
| 82 | if (lpBuffer == NULL) return *p;
|
|---|
| 83 | i = min(cchBuffer - 1, *p);
|
|---|
| 84 | if (i > 0) {
|
|---|
| 85 | memcpy(lpBuffer, p + 1, i * sizeof (WCHAR));
|
|---|
| 86 | lpBuffer[i] = (WCHAR) 0;
|
|---|
| 87 | }
|
|---|
| 88 | else {
|
|---|
| 89 | if (cchBuffer > 1) {
|
|---|
| 90 | lpBuffer[0] = (WCHAR) 0;
|
|---|
| 91 | return 0;
|
|---|
| 92 | }
|
|---|
| 93 | }
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | #ifdef DEBUG_ENABLELOG_LEVEL2
|
|---|
| 97 | if(i) {
|
|---|
| 98 | char *astring = (char *)HEAP_strdupWtoA(GetProcessHeap(), 0, lpBuffer);
|
|---|
| 99 | dprintf(("LoadStringW from %X, id %d %s\n", hinst, wID, astring));
|
|---|
| 100 | HEAP_free(astring);
|
|---|
| 101 | }
|
|---|
| 102 | #else
|
|---|
| 103 | dprintf(("LoadStringW from %X, id %d buffersize %d\n", hinst, wID, cchBuffer));
|
|---|
| 104 | #endif
|
|---|
| 105 | return(i);
|
|---|
| 106 | }
|
|---|
| 107 | //******************************************************************************
|
|---|
| 108 | //******************************************************************************
|
|---|
| 109 | HICON LoadIconA(HINSTANCE hinst, LPCSTR lpszIcon, DWORD cxDesired,
|
|---|
| 110 | DWORD cyDesired, DWORD fuLoad)
|
|---|
| 111 | {
|
|---|
| 112 | HICON hIcon;
|
|---|
| 113 | HANDLE hMapping = 0;
|
|---|
| 114 | char *ptr = NULL;
|
|---|
| 115 | HRSRC hRes;
|
|---|
| 116 | LPSTR restype = RT_ICONA;
|
|---|
| 117 |
|
|---|
| 118 | if(fuLoad & LR_LOADFROMFILE)
|
|---|
| 119 | {
|
|---|
| 120 | hMapping = VIRTUAL_MapFileA( lpszIcon, (LPVOID *)&ptr, TRUE);
|
|---|
| 121 | if(hMapping == INVALID_HANDLE_VALUE)
|
|---|
| 122 | return 0;
|
|---|
| 123 | hIcon = OSLibWinCreatePointer(ptr);
|
|---|
| 124 | CloseHandle(hMapping);
|
|---|
| 125 | }
|
|---|
| 126 | else
|
|---|
| 127 | {
|
|---|
| 128 | if(!hinst)
|
|---|
| 129 | {
|
|---|
| 130 | hRes = FindResourceA(hInstanceUser32,lpszIcon,RT_ICONA);
|
|---|
| 131 | if(!hRes) {
|
|---|
| 132 | hRes = FindResourceA(hInstanceUser32,lpszIcon,RT_GROUP_ICONA);
|
|---|
| 133 | restype = RT_GROUP_ICONA;
|
|---|
| 134 | }
|
|---|
| 135 | if(hRes)
|
|---|
| 136 | {
|
|---|
| 137 | hIcon = OSLibWinCreateIcon(ConvertResourceToOS2(hInstanceUser32, restype, hRes));
|
|---|
| 138 | }
|
|---|
| 139 | else hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON));
|
|---|
| 140 | }
|
|---|
| 141 | else
|
|---|
| 142 | { //not a system icon
|
|---|
| 143 | hRes = FindResourceA(hinst,lpszIcon,RT_ICONA);
|
|---|
| 144 | if(!hRes) {
|
|---|
| 145 | hRes = FindResourceA(hinst,lpszIcon,RT_GROUP_ICONA);
|
|---|
| 146 | restype = RT_GROUP_ICONA;
|
|---|
| 147 | }
|
|---|
| 148 | if(hRes) {
|
|---|
| 149 | hIcon = OSLibWinCreateIcon(ConvertResourceToOS2(hinst, restype, hRes));
|
|---|
| 150 | }
|
|---|
| 151 | else hIcon = 0;
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | dprintf(("LoadIconA (%X) returned %x\n", hinst, hIcon));
|
|---|
| 155 |
|
|---|
| 156 | return(hIcon);
|
|---|
| 157 | }
|
|---|
| 158 | //******************************************************************************
|
|---|
| 159 | //******************************************************************************
|
|---|
| 160 | HICON LoadIconW(HINSTANCE hinst, LPCWSTR lpszIcon, DWORD cxDesired,
|
|---|
| 161 | DWORD cyDesired, DWORD fuLoad)
|
|---|
| 162 | {
|
|---|
| 163 | HICON hIcon;
|
|---|
| 164 | HANDLE hMapping = 0;
|
|---|
| 165 | char *ptr = NULL;
|
|---|
| 166 | HRSRC hRes;
|
|---|
| 167 | LPSTR restype = RT_ICONA;
|
|---|
| 168 |
|
|---|
| 169 | if(fuLoad & LR_LOADFROMFILE)
|
|---|
| 170 | {
|
|---|
| 171 | hMapping = VIRTUAL_MapFileW( lpszIcon, (LPVOID *)&ptr, TRUE);
|
|---|
| 172 | if(hMapping == INVALID_HANDLE_VALUE)
|
|---|
| 173 | return 0;
|
|---|
| 174 | hIcon = OSLibWinCreatePointer(ptr);
|
|---|
| 175 | CloseHandle(hMapping);
|
|---|
| 176 | }
|
|---|
| 177 | else
|
|---|
| 178 | {
|
|---|
| 179 | if (!hinst)
|
|---|
| 180 | {
|
|---|
| 181 | hRes = FindResourceW(hInstanceUser32,lpszIcon,RT_ICONW);
|
|---|
| 182 | if(!hRes) {
|
|---|
| 183 | hRes = FindResourceW(hInstanceUser32,lpszIcon,RT_GROUP_ICONW);
|
|---|
| 184 | restype = RT_GROUP_ICONA;
|
|---|
| 185 | }
|
|---|
| 186 | if(hRes)
|
|---|
| 187 | {
|
|---|
| 188 | hIcon = OSLibWinCreateIcon(ConvertResourceToOS2(hInstanceUser32, restype, hRes));
|
|---|
| 189 | }
|
|---|
| 190 | else hIcon = OSLibWinQuerySysIcon((ULONG)lpszIcon,GetSystemMetrics(SM_CXICON),GetSystemMetrics(SM_CYICON));
|
|---|
| 191 | }
|
|---|
| 192 | else
|
|---|
| 193 | {//not a system icon
|
|---|
| 194 | hRes = FindResourceW(hinst,lpszIcon,RT_ICONW);
|
|---|
| 195 | if(!hRes) {
|
|---|
| 196 | hRes = FindResourceW(hinst,lpszIcon,RT_GROUP_ICONW);
|
|---|
| 197 | restype = RT_GROUP_ICONA;
|
|---|
| 198 | }
|
|---|
| 199 | if(hRes) {
|
|---|
| 200 | hIcon = OSLibWinCreateIcon(ConvertResourceToOS2(hinst, restype, hRes));
|
|---|
| 201 | }
|
|---|
| 202 | else hIcon = 0;
|
|---|
| 203 | }
|
|---|
| 204 | }
|
|---|
| 205 | dprintf(("LoadIconW (%X) returned %x\n", hinst, hIcon));
|
|---|
| 206 |
|
|---|
| 207 | return(hIcon);
|
|---|
| 208 | }
|
|---|
| 209 | //******************************************************************************
|
|---|
| 210 | //******************************************************************************
|
|---|
| 211 | HICON WIN32API LoadIconA(HINSTANCE hinst, LPCSTR lpszIcon)
|
|---|
| 212 | {
|
|---|
| 213 | return LoadIconA(hinst, lpszIcon, 0, 0, 0);
|
|---|
| 214 | }
|
|---|
| 215 | //******************************************************************************
|
|---|
| 216 | //******************************************************************************
|
|---|
| 217 | HICON WIN32API LoadIconW(HINSTANCE hinst, LPCWSTR lpszIcon)
|
|---|
| 218 | {
|
|---|
| 219 | return LoadIconW(hinst, lpszIcon, 0, 0, 0);
|
|---|
| 220 | }
|
|---|
| 221 | //******************************************************************************
|
|---|
| 222 | //******************************************************************************
|
|---|
| 223 | HCURSOR LoadCursorA(HINSTANCE hinst, LPCSTR lpszCursor, DWORD cxDesired,
|
|---|
| 224 | DWORD cyDesired, DWORD fuLoad)
|
|---|
| 225 | {
|
|---|
| 226 | HCURSOR hCursor;
|
|---|
| 227 | HANDLE hMapping = 0;
|
|---|
| 228 | char *ptr = NULL;
|
|---|
| 229 | HRSRC hRes;
|
|---|
| 230 | LPSTR restype = RT_CURSORA;
|
|---|
| 231 |
|
|---|
| 232 | if(fuLoad & LR_LOADFROMFILE)
|
|---|
| 233 | {
|
|---|
| 234 | hMapping = VIRTUAL_MapFileA( lpszCursor, (LPVOID *)&ptr, TRUE);
|
|---|
| 235 | if(hMapping == INVALID_HANDLE_VALUE)
|
|---|
| 236 | return 0;
|
|---|
| 237 | hCursor = OSLibWinCreatePointer(ptr);
|
|---|
| 238 | CloseHandle(hMapping);
|
|---|
| 239 | }
|
|---|
| 240 | else
|
|---|
| 241 | {
|
|---|
| 242 | if(!hinst)
|
|---|
| 243 | {
|
|---|
| 244 | hRes = FindResourceA(hInstanceUser32,lpszCursor,RT_CURSORA);
|
|---|
| 245 | if(!hRes) {
|
|---|
| 246 | hRes = FindResourceA(hInstanceUser32,lpszCursor,RT_GROUP_CURSORA);
|
|---|
| 247 | restype = RT_GROUP_CURSORA;
|
|---|
| 248 | }
|
|---|
| 249 | if(hRes)
|
|---|
| 250 | {
|
|---|
| 251 | hCursor = OSLibWinCreatePointer(ConvertResourceToOS2(hInstanceUser32, restype, hRes));
|
|---|
| 252 | }
|
|---|
| 253 | else hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor,GetSystemMetrics(SM_CXCURSOR),GetSystemMetrics(SM_CYCURSOR));
|
|---|
| 254 | }
|
|---|
| 255 | else
|
|---|
| 256 | { //not a system icon
|
|---|
| 257 | hRes = FindResourceA(hinst,lpszCursor,RT_CURSORA);
|
|---|
| 258 | if(!hRes) {
|
|---|
| 259 | hRes = FindResourceA(hinst,lpszCursor,RT_GROUP_CURSORA);
|
|---|
| 260 | restype = RT_GROUP_CURSORA;
|
|---|
| 261 | }
|
|---|
| 262 | if(hRes) {
|
|---|
| 263 | hCursor = OSLibWinCreatePointer(ConvertResourceToOS2(hinst, restype, hRes));
|
|---|
| 264 | }
|
|---|
| 265 | else hCursor = 0;
|
|---|
| 266 | }
|
|---|
| 267 | }
|
|---|
| 268 | if(HIWORD(lpszCursor)) {
|
|---|
| 269 | dprintf(("LoadCursorA %s from %x returned %x\n", lpszCursor, hinst, hCursor));
|
|---|
| 270 | }
|
|---|
| 271 | else dprintf(("LoadCursorA %x from %x returned %x\n", lpszCursor, hinst, hCursor));
|
|---|
| 272 |
|
|---|
| 273 | return(hCursor);
|
|---|
| 274 | }
|
|---|
| 275 | //******************************************************************************
|
|---|
| 276 | //******************************************************************************
|
|---|
| 277 | HCURSOR LoadCursorW(HINSTANCE hinst, LPCWSTR lpszCursor, DWORD cxDesired,
|
|---|
| 278 | DWORD cyDesired, DWORD fuLoad)
|
|---|
| 279 | {
|
|---|
| 280 | HCURSOR hCursor;
|
|---|
| 281 | HANDLE hMapping = 0;
|
|---|
| 282 | char *ptr = NULL;
|
|---|
| 283 | HRSRC hRes;
|
|---|
| 284 | LPSTR restype = RT_CURSORA;
|
|---|
| 285 |
|
|---|
| 286 | if(fuLoad & LR_LOADFROMFILE)
|
|---|
| 287 | {
|
|---|
| 288 | hMapping = VIRTUAL_MapFileW( lpszCursor, (LPVOID *)&ptr, TRUE);
|
|---|
| 289 | if(hMapping == INVALID_HANDLE_VALUE)
|
|---|
| 290 | return 0;
|
|---|
| 291 | hCursor = OSLibWinCreatePointer(ptr);
|
|---|
| 292 | CloseHandle(hMapping);
|
|---|
| 293 | }
|
|---|
| 294 | else
|
|---|
| 295 | {
|
|---|
| 296 | if(!hinst)
|
|---|
| 297 | {
|
|---|
| 298 | hRes = FindResourceW(hInstanceUser32,lpszCursor,RT_CURSORW);
|
|---|
| 299 | if(!hRes) {
|
|---|
| 300 | hRes = FindResourceW(hInstanceUser32,lpszCursor,RT_GROUP_CURSORW);
|
|---|
| 301 | restype = RT_GROUP_CURSORA;
|
|---|
| 302 | }
|
|---|
| 303 | if(hRes)
|
|---|
| 304 | {
|
|---|
| 305 | hCursor = OSLibWinCreatePointer(ConvertResourceToOS2(hInstanceUser32, restype, hRes));
|
|---|
| 306 | }
|
|---|
| 307 | else hCursor = OSLibWinQuerySysPointer((ULONG)lpszCursor,GetSystemMetrics(SM_CXCURSOR),GetSystemMetrics(SM_CYCURSOR));
|
|---|
| 308 | }
|
|---|
| 309 | else
|
|---|
| 310 | { //not a system icon
|
|---|
| 311 | hRes = FindResourceW(hinst,lpszCursor,RT_CURSORW);
|
|---|
| 312 | if(!hRes) {
|
|---|
| 313 | hRes = FindResourceW(hinst,lpszCursor,RT_GROUP_CURSORW);
|
|---|
| 314 | restype = RT_GROUP_CURSORA;
|
|---|
| 315 | }
|
|---|
| 316 | if(hRes) {
|
|---|
| 317 | hCursor = OSLibWinCreatePointer(ConvertResourceToOS2(hinst, restype, hRes));
|
|---|
| 318 | }
|
|---|
| 319 | else hCursor = 0;
|
|---|
| 320 | }
|
|---|
| 321 | }
|
|---|
| 322 | dprintf(("LoadCursorW (%X) returned %x\n", hinst, hCursor));
|
|---|
| 323 |
|
|---|
| 324 | return(hCursor);
|
|---|
| 325 | }
|
|---|
| 326 | //******************************************************************************
|
|---|
| 327 | //******************************************************************************
|
|---|
| 328 | HCURSOR WIN32API LoadCursorA(HINSTANCE hinst, LPCSTR lpszCursor)
|
|---|
| 329 | {
|
|---|
| 330 | return LoadCursorA(hinst, lpszCursor, 0, 0, 0);
|
|---|
| 331 | }
|
|---|
| 332 | //******************************************************************************
|
|---|
| 333 | //******************************************************************************
|
|---|
| 334 | HCURSOR WIN32API LoadCursorW(HINSTANCE hinst, LPCWSTR lpszCursor)
|
|---|
| 335 | {
|
|---|
| 336 | return LoadCursorW(hinst, lpszCursor, 0, 0, 0);
|
|---|
| 337 | }
|
|---|
| 338 | //******************************************************************************
|
|---|
| 339 | //******************************************************************************
|
|---|
| 340 | BOOL IsSystemBitmap(ULONG id)
|
|---|
| 341 | {
|
|---|
| 342 | switch(id)
|
|---|
| 343 | {
|
|---|
| 344 | case OBM_UPARROW:
|
|---|
| 345 | case OBM_DNARROW:
|
|---|
| 346 | case OBM_RGARROW:
|
|---|
| 347 | case OBM_LFARROW:
|
|---|
| 348 | case OBM_RESTORE:
|
|---|
| 349 | case OBM_RESTORED:
|
|---|
| 350 | case OBM_UPARROWD:
|
|---|
| 351 | case OBM_DNARROWD:
|
|---|
| 352 | case OBM_RGARROWD:
|
|---|
| 353 | case OBM_LFARROWD:
|
|---|
| 354 | case OBM_OLD_UPARROW:
|
|---|
| 355 | case OBM_OLD_DNARROW:
|
|---|
| 356 | case OBM_OLD_RGARROW:
|
|---|
| 357 | case OBM_OLD_LFARROW:
|
|---|
| 358 | case OBM_CHECK:
|
|---|
| 359 | case OBM_RADIOCHECK:
|
|---|
| 360 | case OBM_CHECKBOXES:
|
|---|
| 361 | case OBM_BTNCORNERS:
|
|---|
| 362 | case OBM_COMBO:
|
|---|
| 363 | case OBM_REDUCE:
|
|---|
| 364 | case OBM_REDUCED:
|
|---|
| 365 | case OBM_ZOOM:
|
|---|
| 366 | case OBM_ZOOMD:
|
|---|
| 367 | case OBM_SIZE:
|
|---|
| 368 | case OBM_CLOSE:
|
|---|
| 369 | case OBM_MNARROW:
|
|---|
| 370 | case OBM_UPARROWI:
|
|---|
| 371 | case OBM_DNARROWI:
|
|---|
| 372 | case OBM_RGARROWI:
|
|---|
| 373 | case OBM_LFARROWI:
|
|---|
| 374 | case OBM_CLOSED:
|
|---|
| 375 | case OBM_OLD_CLOSE:
|
|---|
| 376 | case OBM_BTSIZE:
|
|---|
| 377 | case OBM_OLD_REDUCE:
|
|---|
| 378 | case OBM_OLD_ZOOM:
|
|---|
| 379 | case OBM_OLD_RESTORE:
|
|---|
| 380 | case OBM_CONTEXTHELP:
|
|---|
| 381 | case OBM_CONTEXTHELPD:
|
|---|
| 382 | return TRUE;
|
|---|
| 383 |
|
|---|
| 384 | default:
|
|---|
| 385 | return FALSE;
|
|---|
| 386 | }
|
|---|
| 387 | }
|
|---|
| 388 | //******************************************************************************
|
|---|
| 389 | //NOTE: LR_CREATEDIBSECTION flag doesn't work (crash in GDI32)!
|
|---|
| 390 | //******************************************************************************
|
|---|
| 391 | HANDLE LoadBitmapA(HINSTANCE hinst, LPCSTR lpszName, int cxDesired, int cyDesired,
|
|---|
| 392 | UINT fuLoad)
|
|---|
| 393 | {
|
|---|
| 394 | HBITMAP hbitmap = 0;
|
|---|
| 395 | HDC hdc;
|
|---|
| 396 | HRSRC hRsrc;
|
|---|
| 397 | HGLOBAL handle, hMapping = 0;
|
|---|
| 398 | char *ptr = NULL;
|
|---|
| 399 | BITMAPINFO *info, *fix_info=NULL;
|
|---|
| 400 | HGLOBAL hFix;
|
|---|
| 401 | int size;
|
|---|
| 402 |
|
|---|
| 403 | if (!(fuLoad & LR_LOADFROMFILE)) {
|
|---|
| 404 | if (!(hRsrc = FindResourceA( hinst, lpszName, RT_BITMAPA ))) return 0;
|
|---|
| 405 | if (!(handle = LoadResource( hinst, hRsrc ))) return 0;
|
|---|
| 406 |
|
|---|
| 407 | if ((info = (BITMAPINFO *)LockResource( handle )) == NULL) return 0;
|
|---|
| 408 | }
|
|---|
| 409 | else
|
|---|
| 410 | {
|
|---|
| 411 | hMapping = VIRTUAL_MapFileA( lpszName, (LPVOID *)&ptr, TRUE);
|
|---|
| 412 | if (hMapping == INVALID_HANDLE_VALUE) return 0;
|
|---|
| 413 | info = (BITMAPINFO *)(ptr + sizeof(BITMAPFILEHEADER));
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | //TODO: This has to be removed once pe2lx stores win32 resources!!!
|
|---|
| 417 | if (info->bmiHeader.biSize != sizeof(BITMAPCOREHEADER) &&
|
|---|
| 418 | info->bmiHeader.biSize != sizeof(BITMAPINFOHEADER))
|
|---|
| 419 | {//assume it contains a file header first
|
|---|
| 420 | info = (BITMAPINFO *)((char *)info + sizeof(BITMAPFILEHEADER));
|
|---|
| 421 | }
|
|---|
| 422 |
|
|---|
| 423 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) {
|
|---|
| 424 | size = sizeof(BITMAPINFOHEADER) +
|
|---|
| 425 | (sizeof (RGBTRIPLE) << ((BITMAPCOREHEADER *)info)->bcBitCount);
|
|---|
| 426 | } else
|
|---|
| 427 | size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
|
|---|
| 428 |
|
|---|
| 429 | if ((hFix = GlobalAlloc(0, size)) != NULL) fix_info = (BITMAPINFO *)GlobalLock(hFix);
|
|---|
| 430 | if (fix_info) {
|
|---|
| 431 | BYTE pix;
|
|---|
| 432 |
|
|---|
| 433 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER)) {
|
|---|
| 434 | ULONG colors;
|
|---|
| 435 | ULONG *p, *q;
|
|---|
| 436 |
|
|---|
| 437 | memset (fix_info, 0, sizeof (BITMAPINFOHEADER));
|
|---|
| 438 | fix_info->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
|
|---|
| 439 | fix_info->bmiHeader.biWidth = ((BITMAPCOREHEADER *)info)->bcWidth;
|
|---|
| 440 | fix_info->bmiHeader.biHeight = ((BITMAPCOREHEADER *)info)->bcHeight;
|
|---|
| 441 | fix_info->bmiHeader.biPlanes = ((BITMAPCOREHEADER *)info)->bcPlanes;
|
|---|
| 442 | fix_info->bmiHeader.biBitCount = ((BITMAPCOREHEADER *)info)->bcBitCount;
|
|---|
| 443 |
|
|---|
| 444 | p = (PULONG)((char *)info + sizeof(BITMAPCOREHEADER));
|
|---|
| 445 | q = (PULONG)((char *)fix_info + sizeof(BITMAPINFOHEADER));
|
|---|
| 446 | for (colors = 1 << fix_info->bmiHeader.biBitCount; colors > 0; colors--) {
|
|---|
| 447 | *q = *p & 0x00FFFFFFUL;
|
|---|
| 448 | q++;
|
|---|
| 449 | p = (PULONG)((char *)p + sizeof (RGBTRIPLE));
|
|---|
| 450 | }
|
|---|
| 451 | } else
|
|---|
| 452 | memcpy(fix_info, info, size);
|
|---|
| 453 |
|
|---|
| 454 | size = DIB_BitmapInfoSize(info, DIB_RGB_COLORS);
|
|---|
| 455 | pix = *((LPBYTE)info + size);
|
|---|
| 456 | DIB_FixColorsToLoadflags(fix_info, fuLoad, pix);
|
|---|
| 457 | if ((hdc = GetDC(0)) != 0) {
|
|---|
| 458 | char *bits = (char *)info + size;
|
|---|
| 459 | if (fuLoad & LR_CREATEDIBSECTION) {
|
|---|
| 460 | DIBSECTION dib;
|
|---|
| 461 | hbitmap = CreateDIBSection(hdc, fix_info, DIB_RGB_COLORS, NULL, 0, 0);
|
|---|
| 462 | GetObjectA(hbitmap, sizeof(DIBSECTION), &dib);
|
|---|
| 463 | SetDIBits(hdc, hbitmap, 0, dib.dsBm.bmHeight, bits, info,
|
|---|
| 464 | DIB_RGB_COLORS);
|
|---|
| 465 | }
|
|---|
| 466 | else {
|
|---|
| 467 | // if(fix_info->bmiHeader.biBitCount == 1) {
|
|---|
| 468 | // hbitmap = CreateBitmap(fix_info->bmiHeader.biWidth,
|
|---|
| 469 | // fix_info->bmiHeader.biHeight,
|
|---|
| 470 | // fix_info->bmiHeader.biPlanes,
|
|---|
| 471 | // fix_info->bmiHeader.biBitCount,
|
|---|
| 472 | // (PVOID)bits);
|
|---|
| 473 | // }
|
|---|
| 474 | // else {
|
|---|
| 475 | hbitmap = CreateDIBitmap(hdc, &fix_info->bmiHeader, CBM_INIT,
|
|---|
| 476 | bits, fix_info, DIB_RGB_COLORS );
|
|---|
| 477 | if(hbitmap == 0) {
|
|---|
| 478 | dprintf(("LoadBitmapA: CreateDIBitmap failed!!"));
|
|---|
| 479 | }
|
|---|
| 480 | // }
|
|---|
| 481 | }
|
|---|
| 482 | ReleaseDC( 0, hdc );
|
|---|
| 483 | }
|
|---|
| 484 | GlobalUnlock(hFix);
|
|---|
| 485 | GlobalFree(hFix);
|
|---|
| 486 | }
|
|---|
| 487 | if (fuLoad & LR_LOADFROMFILE) CloseHandle( hMapping );
|
|---|
| 488 | return hbitmap;
|
|---|
| 489 | }
|
|---|
| 490 | //******************************************************************************
|
|---|
| 491 | //TODO: No support for RT_NEWBITMAP
|
|---|
| 492 | //******************************************************************************
|
|---|
| 493 | HBITMAP WIN32API LoadBitmapA(HINSTANCE hinst, LPCSTR lpszBitmap)
|
|---|
| 494 | {
|
|---|
| 495 | HBITMAP hBitmap = 0;
|
|---|
| 496 |
|
|---|
| 497 | if (!hinst)
|
|---|
| 498 | {
|
|---|
| 499 | if(IsSystemBitmap((ULONG)lpszBitmap))
|
|---|
| 500 | {
|
|---|
| 501 | hBitmap = LoadBitmapA(hInstanceUser32, lpszBitmap, 0, 0, 0);
|
|---|
| 502 | }
|
|---|
| 503 | }
|
|---|
| 504 | if(!hBitmap)
|
|---|
| 505 | hBitmap = LoadBitmapA(hinst, lpszBitmap, 0, 0, 0);
|
|---|
| 506 |
|
|---|
| 507 | if(HIWORD(lpszBitmap)) {
|
|---|
| 508 | dprintf(("LoadBitmapA %x %s returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
|---|
| 509 | }
|
|---|
| 510 | else dprintf(("LoadBitmapA %x %x returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
|---|
| 511 |
|
|---|
| 512 | return(hBitmap);
|
|---|
| 513 | }
|
|---|
| 514 | //******************************************************************************
|
|---|
| 515 | //TODO: No support for RT_NEWBITMAP
|
|---|
| 516 | //******************************************************************************
|
|---|
| 517 | HBITMAP WIN32API LoadBitmapW(HINSTANCE hinst, LPCWSTR lpszBitmap)
|
|---|
| 518 | {
|
|---|
| 519 | HBITMAP hBitmap = 0;
|
|---|
| 520 |
|
|---|
| 521 | if(HIWORD(lpszBitmap) != 0)
|
|---|
| 522 | lpszBitmap = (LPWSTR)UnicodeToAsciiString((LPWSTR)lpszBitmap);
|
|---|
| 523 |
|
|---|
| 524 | hBitmap = LoadBitmapA((hinst == 0) ? hInstanceUser32:hinst, (LPSTR)lpszBitmap, 0, 0, 0);
|
|---|
| 525 |
|
|---|
| 526 | if(HIWORD(lpszBitmap) != 0)
|
|---|
| 527 | FreeAsciiString((LPSTR)lpszBitmap);
|
|---|
| 528 |
|
|---|
| 529 | if(HIWORD(lpszBitmap)) {
|
|---|
| 530 | dprintf(("LoadBitmapW %x %s returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
|---|
| 531 | }
|
|---|
| 532 | else dprintf(("LoadBitmapW %x %x returned %08xh\n", hinst, lpszBitmap, hBitmap));
|
|---|
| 533 |
|
|---|
| 534 | return(hBitmap);
|
|---|
| 535 | }
|
|---|
| 536 | //******************************************************************************
|
|---|
| 537 | //TODO: Far from complete, but works for loading resources from exe
|
|---|
| 538 | //fuLoad flag ignored
|
|---|
| 539 | //******************************************************************************
|
|---|
| 540 | HANDLE WIN32API LoadImageA(HINSTANCE hinst, LPCSTR lpszName, UINT uType,
|
|---|
| 541 | int cxDesired, int cyDesired, UINT fuLoad)
|
|---|
| 542 | {
|
|---|
| 543 | HANDLE hRet = 0;
|
|---|
| 544 |
|
|---|
| 545 | if(HIWORD(lpszName)) {
|
|---|
| 546 | dprintf(("LoadImageA NOT COMPLETE %x %s %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
|
|---|
| 547 | }
|
|---|
| 548 | else dprintf(("LoadImageA NOT COMPLETE %x %x %d (%d,%d)\n", hinst, lpszName, uType, cxDesired, cyDesired));
|
|---|
| 549 |
|
|---|
| 550 | if(fuLoad & LR_DEFAULTSIZE) {
|
|---|
| 551 | if (uType == IMAGE_ICON) {
|
|---|
| 552 | if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXICON);
|
|---|
| 553 | if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYICON);
|
|---|
| 554 | }
|
|---|
| 555 | else if (uType == IMAGE_CURSOR) {
|
|---|
| 556 | if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXCURSOR);
|
|---|
| 557 | if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYCURSOR);
|
|---|
| 558 | }
|
|---|
| 559 | }
|
|---|
| 560 | if (fuLoad & LR_LOADFROMFILE) fuLoad &= ~LR_SHARED;
|
|---|
| 561 |
|
|---|
| 562 | switch(uType) {
|
|---|
| 563 | case IMAGE_BITMAP:
|
|---|
| 564 | hRet = (HANDLE)LoadBitmapA(hinst, lpszName, cxDesired, cyDesired, fuLoad);
|
|---|
| 565 | break;
|
|---|
| 566 | case IMAGE_CURSOR:
|
|---|
| 567 | hRet = (HANDLE)LoadCursorA(hinst, lpszName, cxDesired, cyDesired, fuLoad);
|
|---|
| 568 | break;
|
|---|
| 569 | case IMAGE_ICON:
|
|---|
| 570 | hRet = (HANDLE)LoadIconA(hinst, lpszName, cxDesired, cyDesired, fuLoad);
|
|---|
| 571 | break;
|
|---|
| 572 | default:
|
|---|
| 573 | dprintf(("LoadImageA: unsupported type %d!!", uType));
|
|---|
| 574 | return 0;
|
|---|
| 575 | }
|
|---|
| 576 | dprintf(("LoadImageA returned %x\n", (int)hRet));
|
|---|
| 577 |
|
|---|
| 578 | return(hRet);
|
|---|
| 579 | }
|
|---|
| 580 | //******************************************************************************
|
|---|
| 581 | //******************************************************************************
|
|---|
| 582 | HANDLE WIN32API LoadImageW(HINSTANCE hinst, LPCWSTR lpszName, UINT uType,
|
|---|
| 583 | int cxDesired, int cyDesired, UINT fuLoad)
|
|---|
| 584 | {
|
|---|
| 585 | HANDLE hRet = 0;
|
|---|
| 586 |
|
|---|
| 587 | dprintf(("LoadImageW NOT COMPLETE (%d,%d)\n", cxDesired, cyDesired));
|
|---|
| 588 |
|
|---|
| 589 | if (fuLoad & LR_DEFAULTSIZE) {
|
|---|
| 590 | if (uType == IMAGE_ICON) {
|
|---|
| 591 | if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXICON);
|
|---|
| 592 | if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYICON);
|
|---|
| 593 | }
|
|---|
| 594 | else if (uType == IMAGE_CURSOR) {
|
|---|
| 595 | if (!cxDesired) cxDesired = GetSystemMetrics(SM_CXCURSOR);
|
|---|
| 596 | if (!cyDesired) cyDesired = GetSystemMetrics(SM_CYCURSOR);
|
|---|
| 597 | }
|
|---|
| 598 | }
|
|---|
| 599 | if (fuLoad & LR_LOADFROMFILE) fuLoad &= ~LR_SHARED;
|
|---|
| 600 |
|
|---|
| 601 | switch(uType) {
|
|---|
| 602 | case IMAGE_BITMAP:
|
|---|
| 603 | hRet = (HANDLE)LoadBitmapW(hinst, lpszName);
|
|---|
| 604 | break;
|
|---|
| 605 | case IMAGE_CURSOR:
|
|---|
| 606 | hRet = (HANDLE)LoadCursorW(hinst, lpszName, cxDesired, cyDesired, fuLoad);
|
|---|
| 607 | break;
|
|---|
| 608 | case IMAGE_ICON:
|
|---|
| 609 | hRet = (HANDLE)LoadIconW(hinst, lpszName, cxDesired, cyDesired, fuLoad);
|
|---|
| 610 | break;
|
|---|
| 611 | default:
|
|---|
| 612 | dprintf(("LoadImageW: unsupported type %d!!", uType));
|
|---|
| 613 | return 0;
|
|---|
| 614 | }
|
|---|
| 615 | dprintf(("LoadImageW returned %x\n", (int)hRet));
|
|---|
| 616 |
|
|---|
| 617 | return(hRet);
|
|---|
| 618 | }
|
|---|
| 619 | /******************************************************************************
|
|---|
| 620 | * CopyImage32 [USER32.61] Creates new image and copies attributes to it
|
|---|
| 621 | *
|
|---|
| 622 | * PARAMS
|
|---|
| 623 | * hnd [I] Handle to image to copy
|
|---|
| 624 | * type [I] Type of image to copy
|
|---|
| 625 | * desiredx [I] Desired width of new image
|
|---|
| 626 | * desiredy [I] Desired height of new image
|
|---|
| 627 | * flags [I] Copy flags
|
|---|
| 628 | *
|
|---|
| 629 | * RETURNS
|
|---|
| 630 | * Success: Handle to newly created image
|
|---|
| 631 | * Failure: NULL
|
|---|
| 632 | *
|
|---|
| 633 | * FIXME: implementation still lacks nearly all features, see LR_*
|
|---|
| 634 | * defines in windows.h
|
|---|
| 635 | *
|
|---|
| 636 | */
|
|---|
| 637 | HICON WINAPI CopyImage( HANDLE hnd, UINT type, INT desiredx,
|
|---|
| 638 | INT desiredy, UINT flags )
|
|---|
| 639 | {
|
|---|
| 640 | dprintf(("CopyImage %x %d (%d,%d) %x", hnd, type, desiredx, desiredy, flags));
|
|---|
| 641 | switch (type)
|
|---|
| 642 | {
|
|---|
| 643 | // case IMAGE_BITMAP:
|
|---|
| 644 | // return BITMAP_CopyBitmap(hnd);
|
|---|
| 645 | case IMAGE_ICON:
|
|---|
| 646 | return CopyIcon(hnd);
|
|---|
| 647 | case IMAGE_CURSOR:
|
|---|
| 648 | return CopyCursor(hnd);
|
|---|
| 649 | // return CopyCursorIcon(hnd,type, desiredx, desiredy, flags);
|
|---|
| 650 | default:
|
|---|
| 651 | dprintf(("CopyImage: Unsupported type"));
|
|---|
| 652 | }
|
|---|
| 653 | return 0;
|
|---|
| 654 | }
|
|---|
| 655 | //******************************************************************************
|
|---|
| 656 | //******************************************************************************
|
|---|