1 static char RCSId
[] = "$Id: resource.c,v 1.4 1993/07/04 04:04:21 root Exp root $";
2 static char Copyright
[] = "Copyright Robert J. Amstadt, 1993";
13 #include "prototypes.h"
20 /* #define DEBUG_RESOURCE */
22 #define MIN(a,b) ((a) < (b) ? (a) : (b))
24 typedef struct resource_s
26 struct resource_s
*next
;
29 struct resource_nameinfo_s nameinfo
;
33 static int ResourceFd
= -1;
34 static HANDLE ResourceInst
= 0;
35 static struct w_files
*ResourceFileInfo
= NULL
;
36 static RESOURCE
*Top
= NULL
;
37 extern HINSTANCE hSysRes
;
39 HANDLE
RSC_LoadResource(int instance
, char *rsc_name
, int type
,
41 void RSC_LoadNameTable(void);
43 extern char *ProgramName
;
46 /**********************************************************************
53 struct resource_typeinfo_s typeinfo
;
54 struct resource_nameinfo_s nameinfo
;
55 unsigned short size_shift
;
67 * Move to beginning of resource table.
69 rtoff
= (ResourceFileInfo
->mz_header
->ne_offset
+
70 ResourceFileInfo
->ne_header
->resource_tab_offset
);
71 lseek(ResourceFd
, rtoff
, SEEK_SET
);
76 if (read(ResourceFd
, &size_shift
, sizeof(size_shift
)) !=
81 size_shift
= CONV_SHORT(size_shift
);
86 typeinfo
.type_id
= 0xffff;
87 while (typeinfo
.type_id
!= 0)
89 if (!load_typeinfo (ResourceFd
, &typeinfo
))
92 if (typeinfo
.type_id
== 0)
94 if (typeinfo
.type_id
== 0x800f)
96 for (i
= 0; i
< typeinfo
.count
; i
++)
98 if (read(ResourceFd
, &nameinfo
, sizeof(nameinfo
)) !=
104 saved_pos
= lseek(ResourceFd
, 0, SEEK_CUR
);
105 lseek(ResourceFd
, (long) nameinfo
.offset
<< size_shift
,
107 read(ResourceFd
, &len
, sizeof(len
));
110 new = (RESNAMTAB
*) GlobalQuickAlloc(sizeof(*new));
114 read(ResourceFd
, &new->type_ord
, 2);
115 read(ResourceFd
, &new->id_ord
, 2);
116 read(ResourceFd
, read_buf
, len
- 6);
118 p
= read_buf
+ strlen(read_buf
) + 1;
119 strncpy(new->id
, p
, MAX_NAME_LENGTH
);
120 new->id
[MAX_NAME_LENGTH
- 1] = '\0';
122 read(ResourceFd
, &len
, sizeof(len
));
125 lseek(ResourceFd
, saved_pos
, SEEK_SET
);
131 lseek(ResourceFd
, (typeinfo
.count
* sizeof(nameinfo
)), SEEK_CUR
);
135 ResourceFileInfo
->resnamtab
= top
;
139 /**********************************************************************
143 OpenResourceFile(HANDLE instance
)
148 if (ResourceInst
== instance
)
151 w
= GetFileInfo(instance
);
154 ResourceFileInfo
= w
;
155 res_file
= w
->filename
;
160 ResourceInst
= instance
;
161 ResourceFd
= open (res_file
, O_RDONLY
);
164 if (w
->resnamtab
== (RESNAMTAB
*) -1)
171 #ifdef DEBUG_RESOURCE
172 printf("OpenResourceFile(%04X) // file='%s' hFile=%04X !\n",
173 instance
, w
->filename
, ResourceFd
);
178 /**********************************************************************
182 ConvertCoreBitmap( HDC hdc
, BITMAPCOREHEADER
* image
)
184 BITMAPINFO
* bmpInfo
;
187 int i
, size
, n_colors
;
189 n_colors
= 1 << image
->bcBitCount
;
191 if (image
->bcBitCount
< 24)
193 size
= sizeof(BITMAPINFOHEADER
) + n_colors
* sizeof(RGBQUAD
);
194 bits
= (char *) (image
+ 1) + (n_colors
* sizeof(RGBTRIPLE
));
198 size
= sizeof(BITMAPINFOHEADER
);
199 bits
= (char *) (image
+ 1);
201 bmpInfo
= (BITMAPINFO
*) malloc( size
);
203 bmpInfo
->bmiHeader
.biSize
= sizeof(BITMAPINFOHEADER
);
204 bmpInfo
->bmiHeader
.biWidth
= image
->bcWidth
;
205 bmpInfo
->bmiHeader
.biHeight
= image
->bcHeight
;
206 bmpInfo
->bmiHeader
.biPlanes
= image
->bcPlanes
;
207 bmpInfo
->bmiHeader
.biBitCount
= image
->bcBitCount
;
208 bmpInfo
->bmiHeader
.biCompression
= 0;
209 bmpInfo
->bmiHeader
.biSizeImage
= 0;
210 bmpInfo
->bmiHeader
.biXPelsPerMeter
= 0;
211 bmpInfo
->bmiHeader
.biYPelsPerMeter
= 0;
212 bmpInfo
->bmiHeader
.biClrUsed
= 0;
213 bmpInfo
->bmiHeader
.biClrImportant
= 0;
215 if (image
->bcBitCount
< 24)
217 RGBTRIPLE
* oldMap
= (RGBTRIPLE
*)(image
+ 1);
218 RGBQUAD
* newMap
= bmpInfo
->bmiColors
;
219 for (i
= 0; i
< n_colors
; i
++, oldMap
++, newMap
++)
221 newMap
->rgbRed
= oldMap
->rgbtRed
;
222 newMap
->rgbGreen
= oldMap
->rgbtGreen
;
223 newMap
->rgbBlue
= oldMap
->rgbtBlue
;
224 newMap
->rgbReserved
= 0;
228 hbitmap
= CreateDIBitmap( hdc
, &bmpInfo
->bmiHeader
, CBM_INIT
,
229 bits
, bmpInfo
, DIB_RGB_COLORS
);
234 /**********************************************************************
238 ConvertInfoBitmap( HDC hdc
, BITMAPINFO
* image
)
240 char * bits
= ((char *)image
) + DIB_BitmapInfoSize(image
, DIB_RGB_COLORS
);
241 return CreateDIBitmap( hdc
, &image
->bmiHeader
, CBM_INIT
,
242 bits
, image
, DIB_RGB_COLORS
);
246 load_typeinfo (int fd
, struct resource_typeinfo_s
*typeinfo
)
248 return read (fd
, typeinfo
, sizeof (*typeinfo
)) == sizeof (*typeinfo
);
251 /**********************************************************************
252 * FindResourceByNumber
255 FindResourceByNumber(struct resource_nameinfo_s
*result_p
,
256 int type_id
, int resource_id
)
258 struct resource_typeinfo_s typeinfo
;
259 struct resource_nameinfo_s nameinfo
;
260 unsigned short size_shift
;
265 * Move to beginning of resource table.
267 rtoff
= (ResourceFileInfo
->mz_header
->ne_offset
+
268 ResourceFileInfo
->ne_header
->resource_tab_offset
);
269 lseek(ResourceFd
, rtoff
, SEEK_SET
);
274 if (read(ResourceFd
, &size_shift
, sizeof(size_shift
)) !=
277 printf("FindResourceByNumber (%s) bad block size !\n", resource_id
);
280 size_shift
= CONV_SHORT(size_shift
);
284 typeinfo
.type_id
= 0xffff;
285 while (typeinfo
.type_id
!= 0) {
286 if (!load_typeinfo (ResourceFd
, &typeinfo
)){
287 printf("FindResourceByNumber (%X) bad typeinfo size !\n", resource_id
);
290 #ifdef DEBUG_RESOURCE
291 printf("FindResourceByNumber type=%X count=%d searched=%d \n",
292 typeinfo
.type_id
, typeinfo
.count
, type_id
);
294 if (typeinfo
.type_id
== 0) break;
295 if (typeinfo
.type_id
== type_id
|| type_id
== -1) {
296 for (i
= 0; i
< typeinfo
.count
; i
++) {
298 if (read(ResourceFd
, &nameinfo
, sizeof(nameinfo
)) !=
301 if (!load_nameinfo (ResourceFd
, &nameinfo
))
304 printf("FindResourceByNumber (%X) bad nameinfo size !\n", resource_id
);
307 #ifdef DEBUG_RESOURCE
308 printf("FindResource: search type=%X id=%X // type=%X id=%X\n",
309 type_id
, resource_id
, typeinfo
.type_id
, nameinfo
.id
);
311 if (nameinfo
.id
== resource_id
) {
312 memcpy(result_p
, &nameinfo
, sizeof(nameinfo
));
318 lseek(ResourceFd
, (typeinfo
.count
* sizeof(nameinfo
)), SEEK_CUR
);
324 /**********************************************************************
328 FindResourceByName(struct resource_nameinfo_s
*result_p
,
329 int type_id
, char *resource_name
)
331 struct resource_typeinfo_s typeinfo
;
332 struct resource_nameinfo_s nameinfo
;
333 unsigned short size_shift
;
334 off_t old_pos
, new_pos
;
335 unsigned char nbytes
;
341 * Check for loaded name table.
343 if (ResourceFileInfo
->resnamtab
!= NULL
)
347 for (e
= ResourceFileInfo
->resnamtab
; e
!= NULL
; e
= e
->next
)
349 if (e
->type_ord
== (type_id
& 0x000f) &&
350 strcasecmp(e
->id
, resource_name
) == 0)
352 return FindResourceByNumber(result_p
, type_id
, e
->id_ord
);
360 * Move to beginning of resource table.
362 rtoff
= (ResourceFileInfo
->mz_header
->ne_offset
+
363 ResourceFileInfo
->ne_header
->resource_tab_offset
);
364 lseek(ResourceFd
, rtoff
, SEEK_SET
);
369 if (read(ResourceFd
, &size_shift
, sizeof(size_shift
)) !=
372 printf("FindResourceByName (%s) bad block size !\n", resource_name
);
375 size_shift
= CONV_SHORT (size_shift
);
380 typeinfo
.type_id
= 0xffff;
381 while (typeinfo
.type_id
!= 0)
383 if (!load_typeinfo (ResourceFd
, &typeinfo
))
385 printf("FindResourceByName (%s) bad typeinfo size !\n", resource_name
);
388 #ifdef DEBUG_RESOURCE
389 printf("FindResourceByName typeinfo.type_id=%X count=%d type_id=%X\n",
390 typeinfo
.type_id
, typeinfo
.count
, type_id
);
392 if (typeinfo
.type_id
== 0) break;
393 if (typeinfo
.type_id
== type_id
|| type_id
== -1)
395 for (i
= 0; i
< typeinfo
.count
; i
++)
398 if (read(ResourceFd
, &nameinfo
, sizeof(nameinfo
)) !=
401 if (!load_nameinfo (ResourceFd
, &nameinfo
))
404 printf("FindResourceByName (%s) bad nameinfo size !\n", resource_name
);
408 if ((nameinfo.id & 0x8000) != 0) continue;
410 #ifdef DEBUG_RESOURCE
411 printf("FindResourceByName // nameinfo.id=%04X !\n", nameinfo
.id
);
413 old_pos
= lseek(ResourceFd
, 0, SEEK_CUR
);
414 new_pos
= rtoff
+ nameinfo
.id
;
415 lseek(ResourceFd
, new_pos
, SEEK_SET
);
416 read(ResourceFd
, &nbytes
, 1);
417 #ifdef DEBUG_RESOURCE
418 printf("FindResourceByName // namesize=%d !\n", nbytes
);
420 nbytes
= CONV_CHAR_TO_LONG (nbytes
);
421 read(ResourceFd
, name
, nbytes
);
422 lseek(ResourceFd
, old_pos
, SEEK_SET
);
424 #ifdef DEBUG_RESOURCE
425 printf("FindResourceByName type_id=%X (%d of %d) name='%s' resource_name='%s'\n",
426 typeinfo
.type_id
, i
+ 1, typeinfo
.count
,
427 name
, resource_name
);
429 if (strcasecmp(name
, resource_name
) == 0)
431 memcpy(result_p
, &nameinfo
, sizeof(nameinfo
));
437 lseek(ResourceFd
, (typeinfo
.count
* sizeof(nameinfo
)), SEEK_CUR
);
444 /**********************************************************************
445 * LoadIcon [USER.174]
447 HICON
LoadIcon(HANDLE instance
, LPSTR icon_name
)
452 ICONDESCRIP
*lpicodesc
;
456 BITMAPINFOHEADER
*bih
;
462 int i
, j
, image_size
;
463 #ifdef DEBUG_RESOURCE
464 printf("LoadIcon: instance = %04x, name = %08x\n",
465 instance
, icon_name
);
468 if (!(hdc
= GetDC(GetDesktopWindow()))) return 0;
469 if (instance
== (HANDLE
)NULL
) instance
= hSysRes
;
470 rsc_mem
= RSC_LoadResource(instance
, icon_name
, NE_RSCTYPE_GROUP_ICON
,
472 if (rsc_mem
== (HANDLE
)NULL
) {
473 printf("LoadIcon / Icon %04X not Found !\n", icon_name
);
474 ReleaseDC(GetDesktopWindow(), hdc
);
477 lp
= (WORD
*)GlobalLock(rsc_mem
);
480 ReleaseDC(GetDesktopWindow(), hdc
);
483 lpicodesc
= (ICONDESCRIP
*)(lp
+ 3);
484 hIcon
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(ICONALLOC
) + 1024);
485 if (hIcon
== (HICON
)NULL
) {
487 ReleaseDC(GetDesktopWindow(), hdc
);
490 lpico
= (ICONALLOC
*)GlobalLock(hIcon
);
491 lpico
->descriptor
= *lpicodesc
;
492 width
= lpicodesc
->Width
;
493 height
= lpicodesc
->Height
;
494 GlobalUnlock(rsc_mem
);
496 rsc_mem
= RSC_LoadResource(instance
,
497 MAKEINTRESOURCE(lpicodesc
->icoDIBOffset
),
498 NE_RSCTYPE_ICON
, &image_size
);
499 if (rsc_mem
== (HANDLE
)NULL
) {
500 printf("LoadIcon / Icon %04X Bitmaps not Found !\n", icon_name
);
501 ReleaseDC(GetDesktopWindow(), hdc
);
504 lp
= (WORD
*)GlobalLock(rsc_mem
);
507 ReleaseDC(GetDesktopWindow(), hdc
);
510 bmi
= (BITMAPINFO
*)lp
;
511 bih
= (BITMAPINFOHEADER
*)lp
;
512 rgbq
= &bmi
->bmiColors
[0];
513 bih
->biHeight
= bih
->biHeight
/ 2;
515 printf("LoadIcon / image_size=%d width=%d height=%d bih->biBitCount=%d bih->biSizeImage=%ld\n",
516 image_size, width, height, bih->biBitCount, bih->biSizeImage);
518 if (bih
->biSize
== sizeof(BITMAPINFOHEADER
))
519 lpico
->hBitmap
= ConvertInfoBitmap(hdc
, (BITMAPINFO
*)bih
);
523 bih
->biClrUsed
= bih
->biClrImportant
= 2;
524 rgbq
[0].rgbBlue
= 0xFF;
525 rgbq
[0].rgbGreen
= 0xFF;
526 rgbq
[0].rgbRed
= 0xFF;
527 rgbq
[0].rgbReserved
= 0x00;
528 rgbq
[1].rgbBlue
= 0x00;
529 rgbq
[1].rgbGreen
= 0x00;
530 rgbq
[1].rgbRed
= 0x00;
531 rgbq
[1].rgbReserved
= 0x00;
532 lpico
->hBitMask
= CreateDIBitmap(hdc
, bih
, CBM_INIT
,
533 (LPSTR
)lp
+ bih
->biSizeImage
- sizeof(BITMAPINFOHEADER
) / 2 - 4,
534 (BITMAPINFO
*)bih
, DIB_RGB_COLORS
);
535 GlobalUnlock(rsc_mem
);
537 hMemDC
= CreateCompatibleDC(hdc
);
538 hMemDC2
= CreateCompatibleDC(hdc
);
539 SelectObject(hMemDC
, lpico
->hBitmap
);
540 SelectObject(hMemDC2
, lpico
->hBitMask
);
541 BitBlt(hMemDC
, 0, 0, bih
->biWidth
, bih
->biHeight
, hMemDC2
, 0, 0, SRCINVERT
);
544 ReleaseDC(GetDesktopWindow(), hdc
);
546 #ifdef DEBUG_RESOURCE
547 printf("LoadIcon Alloc hIcon=%X\n", hIcon
);
553 /**********************************************************************
554 * DestroyIcon [USER.457]
556 BOOL
DestroyIcon(HICON hIcon
)
559 if (hIcon
== (HICON
)NULL
) return FALSE
;
560 lpico
= (ICONALLOC
*)GlobalLock(hIcon
);
561 if (lpico
->hBitmap
!= (HBITMAP
)NULL
) DeleteObject(lpico
->hBitmap
);
567 /**********************************************************************
568 * LoadAccelerators [USER.177]
570 HANDLE
LoadAccelerators(HANDLE instance
, LPSTR lpTableName
)
575 ACCELHEADER
*lpAccelTbl
;
578 if (((LONG
)lpTableName
& 0xFFFF0000L
) == 0L)
579 printf("LoadAccelerators: instance = %04X, name = %08X\n",
580 instance
, lpTableName
);
582 printf("LoadAccelerators: instance = %04X, name = '%s'\n",
583 instance
, lpTableName
);
585 if (instance
== (HANDLE
)NULL
) instance
= hSysRes
;
586 rsc_mem
= RSC_LoadResource(instance
, lpTableName
, NE_RSCTYPE_ACCELERATOR
,
588 if (rsc_mem
== (HANDLE
)NULL
) {
589 printf("LoadAccelerators / AccelTable %04X not Found !\n", lpTableName
);
592 lp
= (BYTE
*)GlobalLock(rsc_mem
);
598 printf("LoadAccelerators / image_size=%d\n", image_size
);
600 hAccel
= GlobalAlloc(GMEM_MOVEABLE
,
601 sizeof(ACCELHEADER
) + sizeof(ACCELENTRY
) + image_size
);
602 lpAccelTbl
= (LPACCELHEADER
)GlobalLock(hAccel
);
603 lpAccelTbl
->wCount
= 0;
605 lpAccelTbl
->tbl
[i
].type
= *(lp
++);
606 lpAccelTbl
->tbl
[i
].wEvent
= *((WORD
*)lp
);
608 lpAccelTbl
->tbl
[i
].wIDval
= *((WORD
*)lp
);
610 if (lpAccelTbl
->tbl
[i
].wEvent
== 0) break;
612 printf("Accelerator #%u / event=%04X id=%04X type=%02X \n",
613 i
, lpAccelTbl
->tbl
[i
].wEvent
, lpAccelTbl
->tbl
[i
].wIDval
,
614 lpAccelTbl
->tbl
[i
].type
);
616 lpAccelTbl
->wCount
++;
618 GlobalUnlock(hAccel
);
619 GlobalUnlock(rsc_mem
);
624 /**********************************************************************
625 * TranslateAccelerator [USER.178]
627 int TranslateAccelerator(HWND hWnd
, HANDLE hAccel
, LPMSG msg
)
629 ACCELHEADER
*lpAccelTbl
;
631 if (hAccel
== 0 || msg
== NULL
) return 0;
632 if (msg
->message
!= WM_KEYDOWN
&&
633 msg
->message
!= WM_KEYUP
&&
634 msg
->message
!= WM_CHAR
) return 0;
636 printf("TranslateAccelerators hAccel=%04X !\n", hAccel
);
638 lpAccelTbl
= (LPACCELHEADER
)GlobalLock(hAccel
);
639 for (i
= 0; i
< lpAccelTbl
->wCount
; i
++) {
640 /* if (lpAccelTbl->tbl[i].type & SHIFT_ACCEL) { */
641 /* if (lpAccelTbl->tbl[i].type & CONTROL_ACCEL) { */
642 if (lpAccelTbl
->tbl
[i
].type
& VIRTKEY_ACCEL
) {
643 if (msg
->wParam
== lpAccelTbl
->tbl
[i
].wEvent
&&
644 msg
->message
== WM_KEYDOWN
) {
645 SendMessage(hWnd
, WM_COMMAND
, lpAccelTbl
->tbl
[i
].wIDval
, 0x00010000L
);
648 if (msg
->message
== WM_KEYUP
) return 1;
651 if (msg
->wParam
== lpAccelTbl
->tbl
[i
].wEvent
&&
652 msg
->message
== WM_CHAR
) {
653 SendMessage(hWnd
, WM_COMMAND
, lpAccelTbl
->tbl
[i
].wIDval
, 0x00010000L
);
658 GlobalUnlock(hAccel
);
662 /**********************************************************************
663 * FindResource [KERNEL.60]
665 HANDLE
FindResource(HANDLE instance
, LPSTR resource_name
, LPSTR type_name
)
673 #ifdef DEBUG_RESOURCE
674 printf("FindResource hInst=%04X typename=%08X resname=%08X\n",
675 instance
, type_name
, resource_name
);
677 if (OpenResourceFile(instance
) < 0)
680 rh
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(*r
));
683 r
= (RESOURCE
*)GlobalLock(rh
);
690 if (((int) resource_name
& 0xffff0000) == 0)
692 r
->size_shift
= FindResourceByNumber(&r
->nameinfo
, (int)type_name
,
693 (int) resource_name
| 0x8000);
697 r
->size_shift
= FindResourceByName(&r
->nameinfo
, (int)type_name
,
701 if (r
->size_shift
== -1)
710 /**********************************************************************
711 * LoadResource [KERNEL.61]
713 HANDLE
LoadResource(HANDLE instance
, HANDLE hResInfo
)
723 if (OpenResourceFile(instance
) < 0)
726 r
= (RESOURCE
*)GlobalLock(hResInfo
);
730 image_size
= r
->nameinfo
.length
<< r
->size_shift
;
732 h
= r
->rsc_mem
= GlobalAlloc(GMEM_MOVEABLE
, image_size
);
733 image
= GlobalLock(h
);
735 lseek(ResourceFd
, ((int) r
->nameinfo
.offset
<< r
->size_shift
), SEEK_SET
);
737 if (image
== NULL
|| read(ResourceFd
, image
, image_size
) != image_size
)
740 GlobalUnlock(hResInfo
);
745 GlobalUnlock(hResInfo
);
749 /**********************************************************************
750 * LockResource [KERNEL.62]
752 LPSTR
LockResource(HANDLE hResData
)
754 return GlobalLock(hResData
);
757 /**********************************************************************
758 * FreeResource [KERNEL.63]
760 HANDLE
FreeResource(HANDLE hResData
)
764 for (r
= rp
= Top
; r
!= NULL
; r
= r
->next
)
766 if (r
->info_mem
== hResData
)
773 GlobalFree(r
->rsc_mem
);
774 GlobalFree(r
->info_mem
);
782 /**********************************************************************
783 * AccessResource [KERNEL.64]
785 int AccessResource(HANDLE instance
, HANDLE hResInfo
)
788 #ifdef DEBUG_RESOURCE
789 printf("AccessResource(%04X, %04X);\n", instance
, hResInfo
);
792 resfile = OpenResourceFile(instance);
800 /**********************************************************************
804 RSC_LoadResource(int instance
, char *rsc_name
, int type
, int *image_size_ret
)
806 struct resource_nameinfo_s nameinfo
;
819 else if (OpenResourceFile(instance
) < 0)
823 * Get resource by ordinal
825 if (((int) rsc_name
& 0xffff0000) == 0)
827 size_shift
= FindResourceByNumber(&nameinfo
, type
,
828 (int) rsc_name
| 0x8000);
831 * Get resource by name
835 size_shift
= FindResourceByName(&nameinfo
, type
, rsc_name
);
837 if (size_shift
== -1) {
838 if ((LONG
)rsc_name
>= 0x00010000L
)
839 printf("RSC_LoadResource / Resource '%s' not Found !\n", rsc_name
);
841 printf("RSC_LoadResource / Resource '%X' not Found !\n", rsc_name
);
847 lseek(ResourceFd
, ((int) nameinfo
.offset
<< size_shift
), SEEK_SET
);
849 image_size
= nameinfo
.length
<< size_shift
;
850 if (image_size_ret
!= NULL
)
851 *image_size_ret
= image_size
;
852 hmem
= GlobalAlloc(GMEM_MOVEABLE
, image_size
);
853 image
= GlobalLock(hmem
);
854 if (image
== NULL
|| read(ResourceFd
, image
, image_size
) != image_size
)
864 /**********************************************************************
868 LoadString(HANDLE instance
, WORD resource_id
, LPSTR buffer
, int buflen
)
876 #ifdef DEBUG_RESOURCE
877 printf("LoadString: instance = %04x, id = %d, "
878 "buffer = %08x, length = %d\n",
879 instance
, resource_id
, buffer
, buflen
);
882 hmem
= RSC_LoadResource(instance
, (char *) ((resource_id
>> 4) + 1),
883 NE_RSCTYPE_STRING
, &rsc_size
);
887 p
= GlobalLock(hmem
);
888 string_num
= resource_id
& 0x000f;
889 for (i
= 0; i
< string_num
; i
++)
892 i
= MIN(buflen
- 1, *p
);
893 memcpy(buffer
, p
+ 1, i
);
898 #ifdef DEBUG_RESOURCE
899 printf(" '%s'\n", buffer
);
904 /**********************************************************************
908 RSC_LoadMenu(HANDLE instance
, LPSTR menu_name
)
910 #ifdef DEBUG_RESOURCE
911 printf("RSC_LoadMenu: instance = %04x, name = '%s'\n",
912 instance
, menu_name
);
914 return RSC_LoadResource(instance
, menu_name
, NE_RSCTYPE_MENU
, NULL
);
917 /**********************************************************************
921 LoadBitmap(HANDLE instance
, LPSTR bmp_name
)
930 #ifdef DEBUG_RESOURCE
931 printf("LoadBitmap: instance = %04x, name = %08x\n",
934 if (instance
== (HANDLE
)NULL
) instance
= hSysRes
;
935 if (!(hdc
= GetDC(GetDesktopWindow()))) return 0;
937 rsc_mem
= RSC_LoadResource(instance
, bmp_name
, NE_RSCTYPE_BITMAP
,
939 if (rsc_mem
== (HANDLE
)NULL
) {
940 printf("LoadBitmap / BitMap %04X not Found !\n", bmp_name
);
943 lp
= (long *) GlobalLock(rsc_mem
);
949 size
= CONV_LONG (*lp
);
950 if (size
== sizeof(BITMAPCOREHEADER
)){
951 CONV_BITMAPCOREHEADER (lp
);
952 hbitmap
= ConvertCoreBitmap( hdc
, (BITMAPCOREHEADER
*) lp
);
953 } else if (size
== sizeof(BITMAPINFOHEADER
)){
954 CONV_BITMAPINFO (lp
);
955 hbitmap
= ConvertInfoBitmap( hdc
, (BITMAPINFO
*) lp
);
962 /**********************************************************************
963 * CreateIcon [USER.407]
965 HICON
CreateIcon(HANDLE hInstance
, int nWidth
, int nHeight
,
966 BYTE nPlanes
, BYTE nBitsPixel
, LPSTR lpANDbits
,
972 #ifdef DEBUG_RESOURCE
973 printf("CreateIcon: hInstance = %04x, nWidth = %08x, nHeight = %08x \n",
974 hInstance
, nWidth
, nHeight
);
975 printf(" nPlanes = %04x, nBitsPixel = %04x,",nPlanes
, nBitsPixel
);
976 printf(" lpANDbits= %04x, lpXORbits = %04x, \n",lpANDbits
, lpXORbits
);
979 if (hInstance
== (HANDLE
)NULL
) {
980 printf("CreateIcon / hInstance %04x not Found!\n",hInstance
);
983 hIcon
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(ICONALLOC
) + 1024);
984 if (hIcon
== (HICON
)NULL
) {
985 printf("Can't allocate memory for Icon in CreateIcon\n");
988 lpico
= (ICONALLOC
*)GlobalLock(hIcon
);
990 lpico
->descriptor
.Width
=nWidth
;
991 lpico
->descriptor
.Height
=nHeight
;
992 lpico
->descriptor
.ColorCount
=16; /* Dummy Value */
993 lpico
->descriptor
.Reserved1
=0;
994 lpico
->descriptor
.Reserved2
=nPlanes
;
995 lpico
->descriptor
.Reserved3
=nWidth
*nHeight
;
997 /* either nPlanes and/or nBitCount is set to one */
998 lpico
->descriptor
.icoDIBSize
=nWidth
*nHeight
*nPlanes
*nBitsPixel
;
999 lpico
->descriptor
.icoDIBOffset
=0;
1001 if( !(lpico
->hBitmap
=CreateBitmap(nWidth
, nHeight
, nPlanes
, nBitsPixel
,
1003 printf("CreateIcon: couldn't create the XOR bitmap\n");
1007 /* the AND BitMask is always monochrome */
1008 if( !(lpico
->hBitMask
=CreateBitmap(nWidth
, nHeight
, 1, 1, lpANDbits
)) ) {
1009 printf("CreateIcon: couldn't create the AND bitmap\n");
1013 GlobalUnlock(hIcon
);
1014 #ifdef DEBUG_RESOURCE
1015 printf("CreateIcon Alloc hIcon=%X\n", hIcon
);