Release 950109
[wine/multimedia.git] / loader / resource.c
blobe09927b7ab7d382e41760c65c31dfbe5e3b53325
1 /*
2 static char RCSId[] = "$Id: resource.c,v 1.4 1993/07/04 04:04:21 root Exp root $";
3 static char Copyright[] = "Copyright Robert J. Amstadt, 1993";
4 */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <sys/stat.h>
10 #include <fcntl.h>
11 #include <unistd.h>
12 #include "arch.h"
13 #include "windows.h"
14 #include "gdi.h"
15 #include "bitmap.h"
16 #include "neexe.h"
17 #include "icon.h"
18 #include "menu.h"
19 #include "accel.h"
20 #include "dlls.h"
21 #include "resource.h"
22 #include "library.h"
23 #include "stddebug.h"
24 #include "debug.h"
25 #include "../rc/sysresbm.h"
27 #define MIN(a,b) ((a) < (b) ? (a) : (b))
29 RESOURCE *Top = NULL;
31 extern int NE_FindResource(HANDLE, LPSTR, LPSTR, RESOURCE *);
32 extern int PE_FindResource(HANDLE, LPSTR, LPSTR, RESOURCE *);
33 extern HBITMAP OBM_LoadOEMBitmap( WORD id ); /* objects/oembitmap.c */
35 #define PrintId(name) \
36 if (HIWORD((DWORD)name)) \
37 printf(", %s", name); \
38 else \
39 printf(", #%d", (int) name);
41 /**********************************************************************
42 * FindResource [KERNEL.60]
44 HANDLE FindResource(HANDLE instance, LPSTR name, LPSTR type)
46 int status;
47 RESOURCE *r;
48 HANDLE rh;
50 if(debugging_resource){
51 printf("FindResource(%04X", instance);
52 PrintId(name);
53 PrintId(type);
54 printf(")\n");
57 if (instance == (HANDLE)NULL)
58 instance = hSysRes;
60 /* FIXME: did we already find this one ? */
62 if ((rh = GlobalAlloc(GMEM_MOVEABLE, sizeof(RESOURCE))) == 0)
63 return 0;
65 r = (RESOURCE *)GlobalLock(rh);
66 r->next = Top;
67 Top = r;
68 r->info_mem = rh;
69 r->rsc_mem = 0;
70 r->count = 0;
71 if (HIWORD((DWORD)name))
72 r->name = strdup(name);
73 else
74 r->name = name;
76 if (HIWORD((DWORD)type))
77 r->type = strdup(type);
78 else
79 r->type = type;
81 r->wpnt = GetFileInfo(instance);
82 r->fd = dup(r->wpnt->fd);
83 if (r->wpnt->ne)
84 status = NE_FindResource(instance, name, type, r);
85 else
86 status = PE_FindResource(instance, name, type, r);
88 if (!status) {
89 if (HIWORD((DWORD)r->name))
90 free(r->name);
92 if (HIWORD((DWORD)r->type))
93 free(r->type);
94 close(r->fd);
96 Top = r->next;
97 GlobalUnlock(rh);
98 return 0;
99 } else
100 return rh;
103 /**********************************************************************
104 * AllocResource [KERNEL.66]
106 HANDLE AllocResource(HANDLE instance, HANDLE hResInfo, DWORD dwSize)
108 RESOURCE *r;
109 int image_size;
111 dprintf_resource(stddeb, "AllocResource(%04X, %04X, %08X);\n",
112 instance, hResInfo, (int) dwSize);
114 if (instance == (HANDLE)NULL)
115 instance = hSysRes;
117 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
118 return 0;
120 image_size = r->size;
122 if (dwSize == 0)
123 r->rsc_mem = GlobalAlloc(GMEM_MOVEABLE, image_size);
124 else
125 r->rsc_mem = GlobalAlloc(GMEM_MOVEABLE, dwSize);
127 GlobalUnlock(hResInfo);
129 return r->rsc_mem;
132 /**********************************************************************
133 * AccessResource [KERNEL.64]
135 int AccessResource(HANDLE instance, HANDLE hResInfo)
137 int fd;
138 RESOURCE *r;
140 dprintf_resource(stddeb, "AccessResource(%04X, %04X);\n",
141 instance, hResInfo);
143 if (instance == (HANDLE)NULL)
144 instance = hSysRes;
146 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
147 return -1;
149 fd = r->fd;
150 lseek(fd, r->offset, SEEK_SET);
151 GlobalUnlock(hResInfo);
153 return fd;
156 /**********************************************************************
157 * SizeofResource [KERNEL.65]
159 WORD SizeofResource(HANDLE instance, HANDLE hResInfo)
161 RESOURCE *r;
162 int size;
164 dprintf_resource(stddeb, "SizeofResource(%04X, %04X);\n",
165 instance, hResInfo);
167 if (instance == (HANDLE)NULL)
168 instance = hSysRes;
170 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
171 return 0;
173 size = r->size;
174 GlobalUnlock(hResInfo);
176 return size;
179 /**********************************************************************
180 * LoadResource [KERNEL.61]
182 HANDLE LoadResource(HANDLE instance, HANDLE hResInfo)
184 RESOURCE *r;
185 int image_size, fd;
186 void *image;
187 HANDLE h;
189 dprintf_resource(stddeb, "LoadResource(%04X, %04X);\n", instance, hResInfo);
191 if (instance == (HANDLE)NULL)
192 instance = hSysRes;
194 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
195 return 0;
197 h = r->rsc_mem = AllocResource(instance, hResInfo, 0);
198 image = GlobalLinearLock(h);
199 image_size = r->size;
200 fd = AccessResource(instance, hResInfo);
202 if (image == NULL || read(fd, image, image_size) != image_size) {
203 GlobalFree(h);
204 GlobalUnlock(hResInfo);
205 return 0;
207 r->count++;
208 close(fd);
209 GlobalLinearUnlock(h);
210 GlobalUnlock(hResInfo);
211 return h;
214 /**********************************************************************
215 * LockResource [KERNEL.62]
217 LPSTR LockResource(HANDLE hResData)
219 return GlobalLock(hResData);
222 /**********************************************************************
223 * FreeResource [KERNEL.63]
225 HANDLE FreeResource(HANDLE hResData)
227 RESOURCE *r, *rp;
229 dprintf_resource(stddeb, "FreeResource: handle %04x\n", hResData);
231 for (r = rp = Top; r ; r = r->next) {
232 if (r->rsc_mem == hResData) {
233 if (r->count == 0) {
234 if (rp != r)
235 rp->next = r->next;
236 else
237 Top = r->next;
239 if (HIWORD((DWORD)r->name))
240 free(r->name);
241 if (HIWORD((DWORD)r->type))
242 free(r->type);
243 GlobalFree(r->rsc_mem);
244 GlobalFree(r->info_mem);
245 return 0;
246 } else
247 r->count--;
249 rp = r;
251 return hResData;
254 /**********************************************************************
255 * ConvertCoreBitmap
257 HBITMAP ConvertCoreBitmap( HDC hdc, BITMAPCOREHEADER * image )
259 BITMAPINFO * bmpInfo;
260 HBITMAP hbitmap;
261 char * bits;
262 int i, size, n_colors;
264 n_colors = 1 << image->bcBitCount;
265 if (image->bcBitCount < 24)
267 size = sizeof(BITMAPINFOHEADER) + n_colors * sizeof(RGBQUAD);
268 bits = (char *) (image + 1) + (n_colors * sizeof(RGBTRIPLE));
270 else
272 size = sizeof(BITMAPINFOHEADER);
273 bits = (char *) (image + 1);
275 bmpInfo = (BITMAPINFO *) malloc( size );
277 bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
278 bmpInfo->bmiHeader.biWidth = image->bcWidth;
279 bmpInfo->bmiHeader.biHeight = image->bcHeight;
280 bmpInfo->bmiHeader.biPlanes = image->bcPlanes;
281 bmpInfo->bmiHeader.biBitCount = image->bcBitCount;
282 bmpInfo->bmiHeader.biCompression = 0;
283 bmpInfo->bmiHeader.biSizeImage = 0;
284 bmpInfo->bmiHeader.biXPelsPerMeter = 0;
285 bmpInfo->bmiHeader.biYPelsPerMeter = 0;
286 bmpInfo->bmiHeader.biClrUsed = 0;
287 bmpInfo->bmiHeader.biClrImportant = 0;
289 if (image->bcBitCount < 24)
291 RGBTRIPLE * oldMap = (RGBTRIPLE *)(image + 1);
292 RGBQUAD * newMap = bmpInfo->bmiColors;
293 for (i = 0; i < n_colors; i++, oldMap++, newMap++)
295 newMap->rgbRed = oldMap->rgbtRed;
296 newMap->rgbGreen = oldMap->rgbtGreen;
297 newMap->rgbBlue = oldMap->rgbtBlue;
298 newMap->rgbReserved = 0;
302 hbitmap = CreateDIBitmap( hdc, &bmpInfo->bmiHeader, CBM_INIT,
303 bits, bmpInfo, DIB_RGB_COLORS );
304 free( bmpInfo );
305 return hbitmap;
308 /**********************************************************************
309 * ConvertInfoBitmap
311 HBITMAP ConvertInfoBitmap( HDC hdc, BITMAPINFO * image )
313 char * bits = ((char *)image) + DIB_BitmapInfoSize(image, DIB_RGB_COLORS);
314 return CreateDIBitmap( hdc, &image->bmiHeader, CBM_INIT,
315 bits, image, DIB_RGB_COLORS );
318 /**********************************************************************
319 * RSC_LoadResource
321 HANDLE
322 RSC_LoadResource(int instance, LPSTR rsc_name, LPSTR type, int *image_size_ret)
324 HANDLE hResInfo;
325 RESOURCE *r;
327 if (instance == (HANDLE)NULL)
328 instance = hSysRes;
330 dprintf_resource(stddeb, "RSC_LoadResource: instance = %04x, name = %08x, type = %08x\n",
331 instance, (int) rsc_name, (int) type);
333 if ((hResInfo = FindResource(instance, rsc_name, (LPSTR) type)) == (HANDLE) NULL) {
334 return (HANDLE)NULL;
336 r = (RESOURCE *)GlobalLock(hResInfo);
337 if (image_size_ret)
338 *image_size_ret = r->size;
339 r->count++;
340 GlobalUnlock(hResInfo);
341 return LoadResource(instance, hResInfo);
344 /**********************************************************************
345 * LoadIcon [USER.174]
347 HICON LoadIcon(HANDLE instance, LPSTR icon_name)
349 HICON hIcon;
350 HANDLE rsc_mem;
351 WORD *lp;
352 ICONDESCRIP *lpicodesc;
353 ICONALLOC *lpico;
354 int width, height;
355 BITMAPINFO *bmi;
356 BITMAPINFOHEADER *bih;
357 RGBQUAD *rgbq;
358 HDC hMemDC;
359 HDC hMemDC2;
360 HDC hdc;
361 int image_size;
362 HBITMAP hbmpOld1, hbmpOld2;
364 if(debugging_resource){
365 printf("LoadIcon(%04X", instance);
366 PrintId(icon_name);
367 printf(")\n");
370 if (!(hdc = GetDC(GetDesktopWindow()))) return 0;
371 rsc_mem = RSC_LoadResource(instance, icon_name, (LPSTR) NE_RSCTYPE_GROUP_ICON,
372 &image_size);
373 if (rsc_mem == (HANDLE)NULL) {
374 printf("LoadIcon / Icon %04X not Found !\n", (int) icon_name);
375 ReleaseDC(GetDesktopWindow(), hdc);
376 return 0;
378 lp = (WORD *)GlobalLock(rsc_mem);
379 if (lp == NULL) {
380 GlobalFree(rsc_mem);
381 ReleaseDC(GetDesktopWindow(), hdc);
382 return 0;
384 lpicodesc = (ICONDESCRIP *)(lp + 3);
385 hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
386 if (hIcon == (HICON)NULL) {
387 GlobalFree(rsc_mem);
388 ReleaseDC(GetDesktopWindow(), hdc);
389 return 0;
391 lpico = (ICONALLOC *)GlobalLock(hIcon);
392 lpico->descriptor = *lpicodesc;
393 width = lpicodesc->Width;
394 height = lpicodesc->Height;
395 GlobalUnlock(rsc_mem);
396 GlobalFree(rsc_mem);
397 rsc_mem = RSC_LoadResource(instance,
398 MAKEINTRESOURCE(lpicodesc->icoDIBOffset),
399 (LPSTR) NE_RSCTYPE_ICON, &image_size);
400 if (rsc_mem == (HANDLE)NULL) {
401 printf("LoadIcon / Icon %04X Bitmaps not Found !\n", (int) icon_name);
402 ReleaseDC(GetDesktopWindow(), hdc);
403 return 0;
405 lp = (WORD *)GlobalLock(rsc_mem);
406 if (lp == NULL) {
407 GlobalFree(rsc_mem);
408 ReleaseDC(GetDesktopWindow(), hdc);
409 return 0;
411 bmi = (BITMAPINFO *)lp;
412 bih = (BITMAPINFOHEADER *)lp;
413 rgbq = &bmi->bmiColors[0];
414 bih->biHeight = bih->biHeight / 2;
416 printf("LoadIcon / image_size=%d width=%d height=%d bih->biBitCount=%d bih->biSizeImage=%ld\n",
417 image_size, width, height, bih->biBitCount, bih->biSizeImage);
419 if (bih->biSize == sizeof(BITMAPINFOHEADER))
420 lpico->hBitmap = ConvertInfoBitmap(hdc, (BITMAPINFO *)bih);
421 else
422 lpico->hBitmap = 0;
423 bih->biBitCount = 1;
424 bih->biClrUsed = bih->biClrImportant = 2;
425 rgbq[0].rgbBlue = 0xFF;
426 rgbq[0].rgbGreen = 0xFF;
427 rgbq[0].rgbRed = 0xFF;
428 rgbq[0].rgbReserved = 0x00;
429 rgbq[1].rgbBlue = 0x00;
430 rgbq[1].rgbGreen = 0x00;
431 rgbq[1].rgbRed = 0x00;
432 rgbq[1].rgbReserved = 0x00;
433 if (bih->biSizeImage == 0) {
434 if (bih->biCompression != BI_RGB) {
435 fprintf(stderr,"Unknown size for compressed Icon bitmap.\n");
436 GlobalFree(rsc_mem);
437 ReleaseDC(GetDesktopWindow(), hdc);
438 return 0;
440 bih->biSizeImage = (bih->biWidth * bih->biHeight * bih->biBitCount
441 + 7) / 8;
443 lpico->hBitMask = CreateDIBitmap(hdc, bih, CBM_INIT,
444 (LPSTR)lp + bih->biSizeImage - sizeof(BITMAPINFOHEADER) / 2 - 4,
445 (BITMAPINFO *)bih, DIB_RGB_COLORS );
446 GlobalUnlock(rsc_mem);
447 GlobalFree(rsc_mem);
448 hMemDC = CreateCompatibleDC(hdc);
449 hMemDC2 = CreateCompatibleDC(hdc);
450 hbmpOld1 = SelectObject(hMemDC, lpico->hBitmap);
451 hbmpOld2 = SelectObject(hMemDC2, lpico->hBitMask);
452 BitBlt(hMemDC, 0, 0, bih->biWidth, bih->biHeight, hMemDC2, 0, 0,SRCINVERT);
453 SelectObject( hMemDC, hbmpOld1 );
454 SelectObject( hMemDC2, hbmpOld2 );
455 DeleteDC(hMemDC);
456 DeleteDC(hMemDC2);
457 ReleaseDC(GetDesktopWindow(), hdc);
458 GlobalUnlock(hIcon);
459 dprintf_resource(stddeb,"LoadIcon Alloc hIcon=%X\n", hIcon);
460 return hIcon;
463 /**********************************************************************
464 * CreateIcon [USER.407]
466 HICON CreateIcon(HANDLE hInstance, int nWidth, int nHeight,
467 BYTE nPlanes, BYTE nBitsPixel, LPSTR lpANDbits,
468 LPSTR lpXORbits)
470 HICON hIcon;
471 ICONALLOC *lpico;
473 dprintf_resource(stddeb, "CreateIcon: hInstance = %04x, nWidth = %08x, nHeight = %08x \n",
474 hInstance, nWidth, nHeight);
475 dprintf_resource(stddeb, " nPlanes = %04x, nBitsPixel = %04x,",nPlanes, nBitsPixel);
476 dprintf_resource(stddeb, " lpANDbits= %04x, lpXORbits = %04x, \n", (int)lpANDbits,
477 (int)lpXORbits);
479 if (hInstance == (HANDLE)NULL) {
480 printf("CreateIcon / hInstance %04x not Found!\n",hInstance);
481 return 0;
483 hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
484 if (hIcon == (HICON)NULL) {
485 printf("Can't allocate memory for Icon in CreateIcon\n");
486 return 0;
488 lpico= (ICONALLOC *)GlobalLock(hIcon);
490 lpico->descriptor.Width=nWidth;
491 lpico->descriptor.Height=nHeight;
492 lpico->descriptor.ColorCount=16; /* Dummy Value */
493 lpico->descriptor.Reserved1=0;
494 lpico->descriptor.Reserved2=nPlanes;
495 lpico->descriptor.Reserved3=nWidth*nHeight;
497 /* either nPlanes and/or nBitCount is set to one */
498 lpico->descriptor.icoDIBSize=nWidth*nHeight*nPlanes*nBitsPixel;
499 lpico->descriptor.icoDIBOffset=0;
501 if( !(lpico->hBitmap=CreateBitmap(nWidth, nHeight, nPlanes, nBitsPixel,
502 lpXORbits)) ) {
503 printf("CreateIcon: couldn't create the XOR bitmap\n");
504 return(0);
507 /* the AND BitMask is always monochrome */
508 if( !(lpico->hBitMask=CreateBitmap(nWidth, nHeight, 1, 1, lpANDbits)) ) {
509 printf("CreateIcon: couldn't create the AND bitmap\n");
510 return(0);
513 GlobalUnlock(hIcon);
514 dprintf_resource(stddeb, "CreateIcon Alloc hIcon=%X\n", hIcon);
515 return hIcon;
518 /**********************************************************************
519 * DestroyIcon [USER.457]
521 BOOL DestroyIcon(HICON hIcon)
523 ICONALLOC *lpico;
525 if (hIcon == (HICON)NULL)
526 return FALSE;
527 lpico = (ICONALLOC *)GlobalLock(hIcon);
528 if (lpico->hBitmap != (HBITMAP)NULL)
529 DeleteObject(lpico->hBitmap);
530 GlobalFree(hIcon);
531 return TRUE;
534 /**********************************************************************
535 * LoadAccelerators [USER.177]
537 HANDLE LoadAccelerators(HANDLE instance, LPSTR lpTableName)
539 HANDLE hAccel;
540 HANDLE rsc_mem;
541 BYTE *lp;
542 ACCELHEADER *lpAccelTbl;
543 int i, image_size, n;
545 if(debugging_accel){
546 printf("LoadAccelerators(%04X", instance);
547 PrintId(lpTableName);
548 printf(")\n");
551 rsc_mem = RSC_LoadResource(instance, lpTableName, (LPSTR) NE_RSCTYPE_ACCELERATOR,
552 &image_size);
553 if (rsc_mem == (HANDLE)NULL) {
554 printf("LoadAccelerators(%04X", instance);
555 PrintId(lpTableName);
556 printf(") not found !\n");
557 return 0;
559 lp = (BYTE *)GlobalLock(rsc_mem);
560 if (lp == NULL) {
561 GlobalFree(rsc_mem);
562 return 0;
564 dprintf_accel(stddeb,"LoadAccelerators / image_size=%d\n", image_size);
565 n = image_size/5;
566 hAccel = GlobalAlloc(GMEM_MOVEABLE,
567 sizeof(ACCELHEADER) + (n + 1)*sizeof(ACCELENTRY));
568 lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
569 lpAccelTbl->wCount = 0;
570 for (i = 0; i < n; i++) {
571 lpAccelTbl->tbl[i].type = *(lp++);
572 lpAccelTbl->tbl[i].wEvent = *((WORD *)lp);
573 lp += 2;
574 lpAccelTbl->tbl[i].wIDval = *((WORD *)lp);
575 lp += 2;
576 if (lpAccelTbl->tbl[i].wEvent == 0) break;
577 dprintf_accel(stddeb,
578 "Accelerator #%u / event=%04X id=%04X type=%02X \n",
579 i, lpAccelTbl->tbl[i].wEvent, lpAccelTbl->tbl[i].wIDval,
580 lpAccelTbl->tbl[i].type);
581 lpAccelTbl->wCount++;
583 GlobalUnlock(hAccel);
584 GlobalUnlock(rsc_mem);
585 GlobalFree(rsc_mem);
586 return hAccel;
589 /**********************************************************************
590 * TranslateAccelerator [USER.178]
592 int TranslateAccelerator(HWND hWnd, HANDLE hAccel, LPMSG msg)
594 ACCELHEADER *lpAccelTbl;
595 int i;
597 if (hAccel == 0 || msg == NULL) return 0;
598 if (msg->message != WM_KEYDOWN &&
599 msg->message != WM_KEYUP &&
600 msg->message != WM_CHAR) return 0;
602 dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04X !\n", hAccel);
604 lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
605 for (i = 0; i < lpAccelTbl->wCount; i++) {
606 if (lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) {
607 if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
608 msg->message == WM_KEYDOWN) {
609 if ((lpAccelTbl->tbl[i].type & SHIFT_ACCEL) &&
610 !(GetKeyState(VK_SHIFT) & 0xf)) {
611 GlobalUnlock(hAccel);
612 return 0;
614 if ((lpAccelTbl->tbl[i].type & CONTROL_ACCEL) &&
615 !(GetKeyState(VK_CONTROL) & 0xf)) {
616 GlobalUnlock(hAccel);
617 return 0;
619 if ((lpAccelTbl->tbl[i].type & ALT_ACCEL) &&
620 !(GetKeyState(VK_MENU) & 0xf)) {
621 GlobalUnlock(hAccel);
622 return 0;
624 SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
625 GlobalUnlock(hAccel);
626 return 1;
628 if (msg->message == WM_KEYUP) return 1;
630 else {
631 if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
632 msg->message == WM_CHAR) {
633 SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
634 GlobalUnlock(hAccel);
635 return 1;
639 GlobalUnlock(hAccel);
640 return 0;
643 /**********************************************************************
644 * LoadString
647 LoadString(HANDLE instance, WORD resource_id, LPSTR buffer, int buflen)
649 HANDLE hmem;
650 int rsc_size;
651 unsigned char *p;
652 int string_num;
653 int i;
655 dprintf_resource(stddeb, "LoadString: instance = %04x, id = %d, buffer = %08x, "
656 "length = %d\n", instance, resource_id, (int) buffer, buflen);
658 hmem = RSC_LoadResource(instance, (char *) ((resource_id >> 4) + 1),
659 (LPSTR) NE_RSCTYPE_STRING, &rsc_size);
660 if (hmem == 0)
661 return 0;
663 p = GlobalLock(hmem);
664 string_num = resource_id & 0x000f;
665 for (i = 0; i < string_num; i++)
666 p += *p + 1;
668 i = MIN(buflen - 1, *p);
669 if (i > 0) {
670 memcpy(buffer, p + 1, i);
671 buffer[i] = '\0';
673 else {
674 if (buflen > 1) {
675 buffer[0] = '\0';
676 return 0;
678 fprintf(stderr,"LoadString // I dont know why , but caller give buflen=%d *p=%d !\n", buflen, *p);
679 fprintf(stderr,"LoadString // and try to obtain string '%s'\n", p + 1);
681 GlobalFree(hmem);
683 dprintf_resource(stddeb,"LoadString // '%s' copied !\n", buffer);
684 return i;
687 /**********************************************************************
688 * LoadMenu [USER.150]
690 HMENU LoadMenu(HINSTANCE instance, char *menu_name)
692 HMENU hMenu;
693 HANDLE hMenu_desc;
694 MENU_HEADER *menu_desc;
696 if(debugging_menu){
697 printf("LoadMenu(%04X", instance);
698 PrintId(menu_name);
699 printf(")\n");
701 if (menu_name == NULL)
702 return 0;
704 if ((hMenu_desc = RSC_LoadResource(instance, menu_name, (LPSTR) NE_RSCTYPE_MENU, NULL)) == (HANDLE) NULL)
705 return 0;
707 menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc);
708 hMenu = LoadMenuIndirect((LPSTR)menu_desc);
709 return hMenu;
712 /**********************************************************************
713 * LoadBitmap
715 HBITMAP
716 LoadBitmap(HANDLE instance, LPSTR bmp_name)
718 HBITMAP hbitmap;
719 HANDLE rsc_mem;
720 HDC hdc;
721 long *lp;
722 int image_size;
723 int size;
725 if(debugging_resource){
726 printf("LoadBitmap(%04X", instance);
727 PrintId(bmp_name);
728 printf(")\n");
731 if (!instance) {
732 struct ResourceTable *it;
733 hbitmap = OBM_LoadOEMBitmap(((int) bmp_name) & 0xffff);
734 if (hbitmap)
735 return hbitmap;
736 /* Load from sysresbm */
737 dprintf_resource(stddeb,"Searching for %d\n", (int) bmp_name);
738 for(it=sysresbmTable;it->value;it++){
739 if(it->type==NE_RSCTYPE_BITMAP)
740 if((((int)bmp_name & 0xFFFF0000) == 0))
741 {if(it->id==(int)bmp_name)break;}
742 else if(!strcmp(it->name,bmp_name))break;
744 if(!it->value)return 0;
745 dprintf_resource(stddeb,"Found %s\n",it->name);
746 lp=(long *)it->value;
747 rsc_mem=(HANDLE)NULL;
748 } else { /* Load from file - indent this code properly later */
750 rsc_mem = RSC_LoadResource(instance, bmp_name, (LPSTR) NE_RSCTYPE_BITMAP,
751 &image_size);
752 if (rsc_mem == (HANDLE)NULL) {
753 printf("LoadBitmap(%04X", instance);
754 PrintId(bmp_name);
755 printf(") NOT found!\n");
756 return 0;
758 lp = (long *) GlobalLinearLock(rsc_mem);
759 if (lp == NULL)
761 GlobalFree(rsc_mem);
762 return 0;
764 } /* Load from file */
765 if (!(hdc = GetDC(0))) lp = NULL;
766 size = CONV_LONG (*lp);
767 if (size == sizeof(BITMAPCOREHEADER)){
768 CONV_BITMAPCOREHEADER (lp);
769 hbitmap = ConvertCoreBitmap( hdc, (BITMAPCOREHEADER *) lp );
770 } else if (size == sizeof(BITMAPINFOHEADER)){
771 CONV_BITMAPINFO (lp);
772 hbitmap = ConvertInfoBitmap( hdc, (BITMAPINFO *) lp );
773 } else hbitmap = 0;
774 GlobalFree(rsc_mem);
775 ReleaseDC( 0, hdc );
776 return hbitmap;