Release 941210
[wine/multimedia.git] / loader / resource.c
blobadee0cf1a08a1a8c8cec06454186091895072503
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 "neexe.h"
16 #include "icon.h"
17 #include "menu.h"
18 #include "accel.h"
19 #include "dlls.h"
20 #include "resource.h"
21 #include "library.h"
22 #include "stddebug.h"
23 #include "debug.h"
24 #include "../rc/sysresbm.h"
26 #define MIN(a,b) ((a) < (b) ? (a) : (b))
28 RESOURCE *Top = NULL;
30 extern int NE_FindResource(HANDLE, LPSTR, LPSTR, RESOURCE *);
31 extern int PE_FindResource(HANDLE, LPSTR, LPSTR, RESOURCE *);
32 extern HBITMAP OBM_LoadOEMBitmap( WORD id ); /* objects/oembitmap.c */
34 #define PrintId(name) \
35 if (HIWORD((DWORD)name)) \
36 printf(", %s", name); \
37 else \
38 printf(", #%d", (int) name);
40 /**********************************************************************
41 * FindResource [KERNEL.60]
43 HANDLE FindResource(HANDLE instance, LPSTR name, LPSTR type)
45 int status;
46 RESOURCE *r;
47 HANDLE rh;
49 if(debugging_resource){
50 printf("FindResource(%04X", instance);
51 PrintId(name);
52 PrintId(type);
53 printf(")\n");
56 if (instance == (HANDLE)NULL)
57 instance = hSysRes;
59 /* FIXME: did we already find this one ? */
61 if ((rh = GlobalAlloc(GMEM_MOVEABLE, sizeof(RESOURCE))) == 0)
62 return 0;
64 r = (RESOURCE *)GlobalLock(rh);
65 r->next = Top;
66 Top = r;
67 r->info_mem = rh;
68 r->rsc_mem = 0;
69 r->count = 0;
70 if (HIWORD((DWORD)name))
71 r->name = strdup(name);
72 else
73 r->name = name;
75 if (HIWORD((DWORD)type))
76 r->type = strdup(type);
77 else
78 r->type = type;
80 r->wpnt = GetFileInfo(instance);
81 r->fd = dup(r->wpnt->fd);
82 if (r->wpnt->ne)
83 status = NE_FindResource(instance, name, type, r);
84 else
85 status = PE_FindResource(instance, name, type, r);
87 if (!status) {
88 if (HIWORD((DWORD)r->name))
89 free(r->name);
91 if (HIWORD((DWORD)r->type))
92 free(r->type);
93 close(r->fd);
95 Top = r->next;
96 GlobalUnlock(rh);
97 return 0;
98 } else
99 return rh;
102 /**********************************************************************
103 * AllocResource [KERNEL.66]
105 HANDLE AllocResource(HANDLE instance, HANDLE hResInfo, DWORD dwSize)
107 RESOURCE *r;
108 int image_size;
110 dprintf_resource(stddeb, "AllocResource(%04X, %04X, %08X);\n",
111 instance, hResInfo, (int) dwSize);
113 if (instance == (HANDLE)NULL)
114 instance = hSysRes;
116 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
117 return 0;
119 image_size = r->size;
121 if (dwSize == 0)
122 r->rsc_mem = GlobalAlloc(GMEM_MOVEABLE, image_size);
123 else
124 r->rsc_mem = GlobalAlloc(GMEM_MOVEABLE, dwSize);
126 GlobalUnlock(hResInfo);
128 return r->rsc_mem;
131 /**********************************************************************
132 * AccessResource [KERNEL.64]
134 int AccessResource(HANDLE instance, HANDLE hResInfo)
136 int fd;
137 RESOURCE *r;
139 dprintf_resource(stddeb, "AccessResource(%04X, %04X);\n",
140 instance, hResInfo);
142 if (instance == (HANDLE)NULL)
143 instance = hSysRes;
145 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
146 return -1;
148 fd = r->fd;
149 lseek(fd, r->offset, SEEK_SET);
150 GlobalUnlock(hResInfo);
152 return fd;
155 /**********************************************************************
156 * SizeofResource [KERNEL.65]
158 WORD SizeofResource(HANDLE instance, HANDLE hResInfo)
160 RESOURCE *r;
161 int size;
163 dprintf_resource(stddeb, "SizeofResource(%04X, %04X);\n",
164 instance, hResInfo);
166 if (instance == (HANDLE)NULL)
167 instance = hSysRes;
169 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
170 return 0;
172 size = r->size;
173 GlobalUnlock(hResInfo);
175 return size;
178 /**********************************************************************
179 * LoadResource [KERNEL.61]
181 HANDLE LoadResource(HANDLE instance, HANDLE hResInfo)
183 RESOURCE *r;
184 int image_size, fd;
185 void *image;
186 HANDLE h;
188 dprintf_resource(stddeb, "LoadResource(%04X, %04X);\n", instance, hResInfo);
190 if (instance == (HANDLE)NULL)
191 instance = hSysRes;
193 if ((r = (RESOURCE *)GlobalLock(hResInfo)) == NULL)
194 return 0;
196 h = r->rsc_mem = AllocResource(instance, hResInfo, 0);
197 image = GlobalLinearLock(h);
198 image_size = r->size;
199 fd = AccessResource(instance, hResInfo);
201 if (image == NULL || read(fd, image, image_size) != image_size) {
202 GlobalFree(h);
203 GlobalUnlock(hResInfo);
204 return 0;
206 r->count++;
207 close(fd);
208 GlobalLinearUnlock(h);
209 GlobalUnlock(hResInfo);
210 return h;
213 /**********************************************************************
214 * LockResource [KERNEL.62]
216 LPSTR LockResource(HANDLE hResData)
218 return GlobalLock(hResData);
221 /**********************************************************************
222 * FreeResource [KERNEL.63]
224 HANDLE FreeResource(HANDLE hResData)
226 RESOURCE *r, *rp;
228 dprintf_resource(stddeb, "FreeResource: handle %04x\n", hResData);
230 for (r = rp = Top; r ; r = r->next) {
231 if (r->rsc_mem == hResData) {
232 if (r->count == 0) {
233 if (rp != r)
234 rp->next = r->next;
235 else
236 Top = r->next;
238 if (HIWORD((DWORD)r->name))
239 free(r->name);
240 if (HIWORD((DWORD)r->type))
241 free(r->type);
242 GlobalFree(r->rsc_mem);
243 GlobalFree(r->info_mem);
244 return 0;
245 } else
246 r->count--;
248 rp = r;
250 return hResData;
253 /**********************************************************************
254 * ConvertCoreBitmap
256 HBITMAP ConvertCoreBitmap( HDC hdc, BITMAPCOREHEADER * image )
258 BITMAPINFO * bmpInfo;
259 HBITMAP hbitmap;
260 char * bits;
261 int i, size, n_colors;
263 n_colors = 1 << image->bcBitCount;
264 if (image->bcBitCount < 24)
266 size = sizeof(BITMAPINFOHEADER) + n_colors * sizeof(RGBQUAD);
267 bits = (char *) (image + 1) + (n_colors * sizeof(RGBTRIPLE));
269 else
271 size = sizeof(BITMAPINFOHEADER);
272 bits = (char *) (image + 1);
274 bmpInfo = (BITMAPINFO *) malloc( size );
276 bmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
277 bmpInfo->bmiHeader.biWidth = image->bcWidth;
278 bmpInfo->bmiHeader.biHeight = image->bcHeight;
279 bmpInfo->bmiHeader.biPlanes = image->bcPlanes;
280 bmpInfo->bmiHeader.biBitCount = image->bcBitCount;
281 bmpInfo->bmiHeader.biCompression = 0;
282 bmpInfo->bmiHeader.biSizeImage = 0;
283 bmpInfo->bmiHeader.biXPelsPerMeter = 0;
284 bmpInfo->bmiHeader.biYPelsPerMeter = 0;
285 bmpInfo->bmiHeader.biClrUsed = 0;
286 bmpInfo->bmiHeader.biClrImportant = 0;
288 if (image->bcBitCount < 24)
290 RGBTRIPLE * oldMap = (RGBTRIPLE *)(image + 1);
291 RGBQUAD * newMap = bmpInfo->bmiColors;
292 for (i = 0; i < n_colors; i++, oldMap++, newMap++)
294 newMap->rgbRed = oldMap->rgbtRed;
295 newMap->rgbGreen = oldMap->rgbtGreen;
296 newMap->rgbBlue = oldMap->rgbtBlue;
297 newMap->rgbReserved = 0;
301 hbitmap = CreateDIBitmap( hdc, &bmpInfo->bmiHeader, CBM_INIT,
302 bits, bmpInfo, DIB_RGB_COLORS );
303 free( bmpInfo );
304 return hbitmap;
307 /**********************************************************************
308 * ConvertInfoBitmap
310 HBITMAP ConvertInfoBitmap( HDC hdc, BITMAPINFO * image )
312 char * bits = ((char *)image) + DIB_BitmapInfoSize(image, DIB_RGB_COLORS);
313 return CreateDIBitmap( hdc, &image->bmiHeader, CBM_INIT,
314 bits, image, DIB_RGB_COLORS );
317 /**********************************************************************
318 * RSC_LoadResource
320 HANDLE
321 RSC_LoadResource(int instance, LPSTR rsc_name, LPSTR type, int *image_size_ret)
323 HANDLE hResInfo;
324 RESOURCE *r;
326 if (instance == (HANDLE)NULL)
327 instance = hSysRes;
329 dprintf_resource(stddeb, "RSC_LoadResource: instance = %04x, name = %08x, type = %08x\n",
330 instance, (int) rsc_name, (int) type);
332 if ((hResInfo = FindResource(instance, rsc_name, (LPSTR) type)) == (HANDLE) NULL) {
333 return (HANDLE)NULL;
335 r = (RESOURCE *)GlobalLock(hResInfo);
336 if (image_size_ret)
337 *image_size_ret = r->size;
338 r->count++;
339 GlobalUnlock(hResInfo);
340 return LoadResource(instance, hResInfo);
343 /**********************************************************************
344 * LoadIcon [USER.174]
346 HICON LoadIcon(HANDLE instance, LPSTR icon_name)
348 HICON hIcon;
349 HANDLE rsc_mem;
350 WORD *lp;
351 ICONDESCRIP *lpicodesc;
352 ICONALLOC *lpico;
353 int width, height;
354 BITMAPINFO *bmi;
355 BITMAPINFOHEADER *bih;
356 RGBQUAD *rgbq;
357 HDC hMemDC;
358 HDC hMemDC2;
359 HDC hdc;
360 int image_size;
361 HBITMAP hbmpOld1, hbmpOld2;
363 if(debugging_resource){
364 printf("LoadIcon(%04X", instance);
365 PrintId(icon_name);
366 printf(")\n");
369 if (!(hdc = GetDC(GetDesktopWindow()))) return 0;
370 rsc_mem = RSC_LoadResource(instance, icon_name, (LPSTR) NE_RSCTYPE_GROUP_ICON,
371 &image_size);
372 if (rsc_mem == (HANDLE)NULL) {
373 printf("LoadIcon / Icon %04X not Found !\n", (int) icon_name);
374 ReleaseDC(GetDesktopWindow(), hdc);
375 return 0;
377 lp = (WORD *)GlobalLock(rsc_mem);
378 if (lp == NULL) {
379 GlobalFree(rsc_mem);
380 ReleaseDC(GetDesktopWindow(), hdc);
381 return 0;
383 lpicodesc = (ICONDESCRIP *)(lp + 3);
384 hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
385 if (hIcon == (HICON)NULL) {
386 GlobalFree(rsc_mem);
387 ReleaseDC(GetDesktopWindow(), hdc);
388 return 0;
390 lpico = (ICONALLOC *)GlobalLock(hIcon);
391 lpico->descriptor = *lpicodesc;
392 width = lpicodesc->Width;
393 height = lpicodesc->Height;
394 GlobalUnlock(rsc_mem);
395 GlobalFree(rsc_mem);
396 rsc_mem = RSC_LoadResource(instance,
397 MAKEINTRESOURCE(lpicodesc->icoDIBOffset),
398 (LPSTR) NE_RSCTYPE_ICON, &image_size);
399 if (rsc_mem == (HANDLE)NULL) {
400 printf("LoadIcon / Icon %04X Bitmaps not Found !\n", (int) icon_name);
401 ReleaseDC(GetDesktopWindow(), hdc);
402 return 0;
404 lp = (WORD *)GlobalLock(rsc_mem);
405 if (lp == NULL) {
406 GlobalFree(rsc_mem);
407 ReleaseDC(GetDesktopWindow(), hdc);
408 return 0;
410 bmi = (BITMAPINFO *)lp;
411 bih = (BITMAPINFOHEADER *)lp;
412 rgbq = &bmi->bmiColors[0];
413 bih->biHeight = bih->biHeight / 2;
415 printf("LoadIcon / image_size=%d width=%d height=%d bih->biBitCount=%d bih->biSizeImage=%ld\n",
416 image_size, width, height, bih->biBitCount, bih->biSizeImage);
418 if (bih->biSize == sizeof(BITMAPINFOHEADER))
419 lpico->hBitmap = ConvertInfoBitmap(hdc, (BITMAPINFO *)bih);
420 else
421 lpico->hBitmap = 0;
422 bih->biBitCount = 1;
423 bih->biClrUsed = bih->biClrImportant = 2;
424 rgbq[0].rgbBlue = 0xFF;
425 rgbq[0].rgbGreen = 0xFF;
426 rgbq[0].rgbRed = 0xFF;
427 rgbq[0].rgbReserved = 0x00;
428 rgbq[1].rgbBlue = 0x00;
429 rgbq[1].rgbGreen = 0x00;
430 rgbq[1].rgbRed = 0x00;
431 rgbq[1].rgbReserved = 0x00;
432 if (bih->biSizeImage == 0) {
433 if (bih->biCompression != BI_RGB) {
434 fprintf(stderr,"Unknown size for compressed Icon bitmap.\n");
435 GlobalFree(rsc_mem);
436 ReleaseDC(GetDesktopWindow(), hdc);
437 return 0;
439 bih->biSizeImage = (bih->biWidth * bih->biHeight * bih->biBitCount
440 + 7) / 8;
442 lpico->hBitMask = CreateDIBitmap(hdc, bih, CBM_INIT,
443 (LPSTR)lp + bih->biSizeImage - sizeof(BITMAPINFOHEADER) / 2 - 4,
444 (BITMAPINFO *)bih, DIB_RGB_COLORS );
445 GlobalUnlock(rsc_mem);
446 GlobalFree(rsc_mem);
447 hMemDC = CreateCompatibleDC(hdc);
448 hMemDC2 = CreateCompatibleDC(hdc);
449 hbmpOld1 = SelectObject(hMemDC, lpico->hBitmap);
450 hbmpOld2 = SelectObject(hMemDC2, lpico->hBitMask);
451 BitBlt(hMemDC, 0, 0, bih->biWidth, bih->biHeight, hMemDC2, 0, 0,SRCINVERT);
452 SelectObject( hMemDC, hbmpOld1 );
453 SelectObject( hMemDC2, hbmpOld2 );
454 DeleteDC(hMemDC);
455 DeleteDC(hMemDC2);
456 ReleaseDC(GetDesktopWindow(), hdc);
457 GlobalUnlock(hIcon);
458 dprintf_resource(stddeb,"LoadIcon Alloc hIcon=%X\n", hIcon);
459 return hIcon;
462 /**********************************************************************
463 * CreateIcon [USER.407]
465 HICON CreateIcon(HANDLE hInstance, int nWidth, int nHeight,
466 BYTE nPlanes, BYTE nBitsPixel, LPSTR lpANDbits,
467 LPSTR lpXORbits)
469 HICON hIcon;
470 ICONALLOC *lpico;
472 dprintf_resource(stddeb, "CreateIcon: hInstance = %04x, nWidth = %08x, nHeight = %08x \n",
473 hInstance, nWidth, nHeight);
474 dprintf_resource(stddeb, " nPlanes = %04x, nBitsPixel = %04x,",nPlanes, nBitsPixel);
475 dprintf_resource(stddeb, " lpANDbits= %04x, lpXORbits = %04x, \n", (int)lpANDbits,
476 (int)lpXORbits);
478 if (hInstance == (HANDLE)NULL) {
479 printf("CreateIcon / hInstance %04x not Found!\n",hInstance);
480 return 0;
482 hIcon = GlobalAlloc(GMEM_MOVEABLE, sizeof(ICONALLOC) + 1024);
483 if (hIcon == (HICON)NULL) {
484 printf("Can't allocate memory for Icon in CreateIcon\n");
485 return 0;
487 lpico= (ICONALLOC *)GlobalLock(hIcon);
489 lpico->descriptor.Width=nWidth;
490 lpico->descriptor.Height=nHeight;
491 lpico->descriptor.ColorCount=16; /* Dummy Value */
492 lpico->descriptor.Reserved1=0;
493 lpico->descriptor.Reserved2=nPlanes;
494 lpico->descriptor.Reserved3=nWidth*nHeight;
496 /* either nPlanes and/or nBitCount is set to one */
497 lpico->descriptor.icoDIBSize=nWidth*nHeight*nPlanes*nBitsPixel;
498 lpico->descriptor.icoDIBOffset=0;
500 if( !(lpico->hBitmap=CreateBitmap(nWidth, nHeight, nPlanes, nBitsPixel,
501 lpXORbits)) ) {
502 printf("CreateIcon: couldn't create the XOR bitmap\n");
503 return(0);
506 /* the AND BitMask is always monochrome */
507 if( !(lpico->hBitMask=CreateBitmap(nWidth, nHeight, 1, 1, lpANDbits)) ) {
508 printf("CreateIcon: couldn't create the AND bitmap\n");
509 return(0);
512 GlobalUnlock(hIcon);
513 dprintf_resource(stddeb, "CreateIcon Alloc hIcon=%X\n", hIcon);
514 return hIcon;
517 /**********************************************************************
518 * DestroyIcon [USER.457]
520 BOOL DestroyIcon(HICON hIcon)
522 ICONALLOC *lpico;
524 if (hIcon == (HICON)NULL)
525 return FALSE;
526 lpico = (ICONALLOC *)GlobalLock(hIcon);
527 if (lpico->hBitmap != (HBITMAP)NULL)
528 DeleteObject(lpico->hBitmap);
529 GlobalFree(hIcon);
530 return TRUE;
533 /**********************************************************************
534 * LoadAccelerators [USER.177]
536 HANDLE LoadAccelerators(HANDLE instance, LPSTR lpTableName)
538 HANDLE hAccel;
539 HANDLE rsc_mem;
540 BYTE *lp;
541 ACCELHEADER *lpAccelTbl;
542 int i, image_size, n;
544 if(debugging_accel){
545 printf("LoadAccelerators(%04X", instance);
546 PrintId(lpTableName);
547 printf(")\n");
550 rsc_mem = RSC_LoadResource(instance, lpTableName, (LPSTR) NE_RSCTYPE_ACCELERATOR,
551 &image_size);
552 if (rsc_mem == (HANDLE)NULL) {
553 printf("LoadAccelerators(%04X", instance);
554 PrintId(lpTableName);
555 printf(") not found !\n");
556 return 0;
558 lp = (BYTE *)GlobalLock(rsc_mem);
559 if (lp == NULL) {
560 GlobalFree(rsc_mem);
561 return 0;
563 dprintf_accel(stddeb,"LoadAccelerators / image_size=%d\n", image_size);
564 n = image_size/5;
565 hAccel = GlobalAlloc(GMEM_MOVEABLE,
566 sizeof(ACCELHEADER) + (n + 1)*sizeof(ACCELENTRY));
567 lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
568 lpAccelTbl->wCount = 0;
569 for (i = 0; i < n; i++) {
570 lpAccelTbl->tbl[i].type = *(lp++);
571 lpAccelTbl->tbl[i].wEvent = *((WORD *)lp);
572 lp += 2;
573 lpAccelTbl->tbl[i].wIDval = *((WORD *)lp);
574 lp += 2;
575 if (lpAccelTbl->tbl[i].wEvent == 0) break;
576 dprintf_accel(stddeb,
577 "Accelerator #%u / event=%04X id=%04X type=%02X \n",
578 i, lpAccelTbl->tbl[i].wEvent, lpAccelTbl->tbl[i].wIDval,
579 lpAccelTbl->tbl[i].type);
580 lpAccelTbl->wCount++;
582 GlobalUnlock(hAccel);
583 GlobalUnlock(rsc_mem);
584 GlobalFree(rsc_mem);
585 return hAccel;
588 /**********************************************************************
589 * TranslateAccelerator [USER.178]
591 int TranslateAccelerator(HWND hWnd, HANDLE hAccel, LPMSG msg)
593 ACCELHEADER *lpAccelTbl;
594 int i;
596 if (hAccel == 0 || msg == NULL) return 0;
597 if (msg->message != WM_KEYDOWN &&
598 msg->message != WM_KEYUP &&
599 msg->message != WM_CHAR) return 0;
601 dprintf_accel(stddeb, "TranslateAccelerators hAccel=%04X !\n", hAccel);
603 lpAccelTbl = (LPACCELHEADER)GlobalLock(hAccel);
604 for (i = 0; i < lpAccelTbl->wCount; i++) {
605 if (lpAccelTbl->tbl[i].type & VIRTKEY_ACCEL) {
606 if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
607 msg->message == WM_KEYDOWN) {
608 if ((lpAccelTbl->tbl[i].type & SHIFT_ACCEL) &&
609 !(GetKeyState(VK_SHIFT) & 0xf)) {
610 GlobalUnlock(hAccel);
611 return 0;
613 if ((lpAccelTbl->tbl[i].type & CONTROL_ACCEL) &&
614 !(GetKeyState(VK_CONTROL) & 0xf)) {
615 GlobalUnlock(hAccel);
616 return 0;
618 if ((lpAccelTbl->tbl[i].type & ALT_ACCEL) &&
619 !(GetKeyState(VK_MENU) & 0xf)) {
620 GlobalUnlock(hAccel);
621 return 0;
623 SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
624 GlobalUnlock(hAccel);
625 return 1;
627 if (msg->message == WM_KEYUP) return 1;
629 else {
630 if (msg->wParam == lpAccelTbl->tbl[i].wEvent &&
631 msg->message == WM_CHAR) {
632 SendMessage(hWnd, WM_COMMAND, lpAccelTbl->tbl[i].wIDval, 0x00010000L);
633 GlobalUnlock(hAccel);
634 return 1;
638 GlobalUnlock(hAccel);
639 return 0;
642 /**********************************************************************
643 * LoadString
646 LoadString(HANDLE instance, WORD resource_id, LPSTR buffer, int buflen)
648 HANDLE hmem;
649 int rsc_size;
650 unsigned char *p;
651 int string_num;
652 int i;
654 dprintf_resource(stddeb, "LoadString: instance = %04x, id = %d, buffer = %08x, "
655 "length = %d\n", instance, resource_id, (int) buffer, buflen);
657 hmem = RSC_LoadResource(instance, (char *) ((resource_id >> 4) + 1),
658 (LPSTR) NE_RSCTYPE_STRING, &rsc_size);
659 if (hmem == 0)
660 return 0;
662 p = GlobalLock(hmem);
663 string_num = resource_id & 0x000f;
664 for (i = 0; i < string_num; i++)
665 p += *p + 1;
667 i = MIN(buflen - 1, *p);
668 if (i > 0) {
669 memcpy(buffer, p + 1, i);
670 buffer[i] = '\0';
672 else {
673 if (buflen > 1) {
674 buffer[0] = '\0';
675 return 0;
677 fprintf(stderr,"LoadString // I dont know why , but caller give buflen=%d *p=%d !\n", buflen, *p);
678 fprintf(stderr,"LoadString // and try to obtain string '%s'\n", p + 1);
680 GlobalFree(hmem);
682 dprintf_resource(stddeb,"LoadString // '%s' copied !\n", buffer);
683 return i;
686 /**********************************************************************
687 * LoadMenu [USER.150]
689 HMENU LoadMenu(HINSTANCE instance, char *menu_name)
691 HMENU hMenu;
692 HANDLE hMenu_desc;
693 MENU_HEADER *menu_desc;
695 if(debugging_menu){
696 printf("LoadMenu(%04X", instance);
697 PrintId(menu_name);
698 printf(")\n");
700 if (menu_name == NULL)
701 return 0;
703 if ((hMenu_desc = RSC_LoadResource(instance, menu_name, (LPSTR) NE_RSCTYPE_MENU, NULL)) == (HANDLE) NULL)
704 return 0;
706 menu_desc = (MENU_HEADER *) GlobalLock(hMenu_desc);
707 hMenu = LoadMenuIndirect((LPSTR)menu_desc);
708 return hMenu;
711 /**********************************************************************
712 * LoadBitmap
714 HBITMAP
715 LoadBitmap(HANDLE instance, LPSTR bmp_name)
717 HBITMAP hbitmap;
718 HANDLE rsc_mem;
719 HDC hdc;
720 long *lp;
721 int image_size;
722 int size;
724 if(debugging_resource){
725 printf("LoadBitmap(%04X", instance);
726 PrintId(bmp_name);
727 printf(")\n");
730 if (!instance) {
731 struct ResourceTable *it;
732 hbitmap = OBM_LoadOEMBitmap(((int) bmp_name) & 0xffff);
733 if (hbitmap)
734 return hbitmap;
735 /* Load from sysresbm */
736 dprintf_resource(stddeb,"Searching for %d\n", (int) bmp_name);
737 for(it=sysresbmTable;it->value;it++){
738 if(it->type==NE_RSCTYPE_BITMAP)
739 if((((int)bmp_name & 0xFFFF0000) == 0))
740 {if(it->id==(int)bmp_name)break;}
741 else if(!strcmp(it->name,bmp_name))break;
743 if(!it->value)return 0;
744 dprintf_resource(stddeb,"Found %s\n",it->name);
745 lp=it->value;
746 rsc_mem=(HANDLE)NULL;
747 } else { /* Load from file - indent this code properly later */
749 rsc_mem = RSC_LoadResource(instance, bmp_name, (LPSTR) NE_RSCTYPE_BITMAP,
750 &image_size);
751 if (rsc_mem == (HANDLE)NULL) {
752 printf("LoadBitmap(%04X", instance);
753 PrintId(bmp_name);
754 printf(") NOT found!\n");
755 return 0;
757 lp = (long *) GlobalLinearLock(rsc_mem);
758 if (lp == NULL)
760 GlobalFree(rsc_mem);
761 return 0;
763 } /* Load from file */
764 if (!(hdc = GetDC(0))) lp = NULL;
765 size = CONV_LONG (*lp);
766 if (size == sizeof(BITMAPCOREHEADER)){
767 CONV_BITMAPCOREHEADER (lp);
768 hbitmap = ConvertCoreBitmap( hdc, (BITMAPCOREHEADER *) lp );
769 } else if (size == sizeof(BITMAPINFOHEADER)){
770 CONV_BITMAPINFO (lp);
771 hbitmap = ConvertInfoBitmap( hdc, (BITMAPINFO *) lp );
772 } else hbitmap = 0;
773 GlobalFree(rsc_mem);
774 ReleaseDC( 0, hdc );
775 return hbitmap;