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
;
576 int i
, image_size
, n
;
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
);
601 hAccel
= GlobalAlloc(GMEM_MOVEABLE
,
602 sizeof(ACCELHEADER
) + (n
+ 1)*sizeof(ACCELENTRY
));
603 lpAccelTbl
= (LPACCELHEADER
)GlobalLock(hAccel
);
604 lpAccelTbl
->wCount
= 0;
605 for (i
= 0; i
< n
; i
++) {
606 lpAccelTbl
->tbl
[i
].type
= *(lp
++);
607 lpAccelTbl
->tbl
[i
].wEvent
= *((WORD
*)lp
);
609 lpAccelTbl
->tbl
[i
].wIDval
= *((WORD
*)lp
);
611 if (lpAccelTbl
->tbl
[i
].wEvent
== 0) break;
613 printf("Accelerator #%u / event=%04X id=%04X type=%02X \n",
614 i
, lpAccelTbl
->tbl
[i
].wEvent
, lpAccelTbl
->tbl
[i
].wIDval
,
615 lpAccelTbl
->tbl
[i
].type
);
617 lpAccelTbl
->wCount
++;
619 GlobalUnlock(hAccel
);
620 GlobalUnlock(rsc_mem
);
625 /**********************************************************************
626 * TranslateAccelerator [USER.178]
628 int TranslateAccelerator(HWND hWnd
, HANDLE hAccel
, LPMSG msg
)
630 ACCELHEADER
*lpAccelTbl
;
632 if (hAccel
== 0 || msg
== NULL
) return 0;
633 if (msg
->message
!= WM_KEYDOWN
&&
634 msg
->message
!= WM_KEYUP
&&
635 msg
->message
!= WM_CHAR
) return 0;
637 printf("TranslateAccelerators hAccel=%04X !\n", hAccel
);
639 lpAccelTbl
= (LPACCELHEADER
)GlobalLock(hAccel
);
640 for (i
= 0; i
< lpAccelTbl
->wCount
; i
++) {
641 /* if (lpAccelTbl->tbl[i].type & SHIFT_ACCEL) { */
642 /* if (lpAccelTbl->tbl[i].type & CONTROL_ACCEL) { */
643 if (lpAccelTbl
->tbl
[i
].type
& VIRTKEY_ACCEL
) {
644 if (msg
->wParam
== lpAccelTbl
->tbl
[i
].wEvent
&&
645 msg
->message
== WM_KEYDOWN
) {
646 SendMessage(hWnd
, WM_COMMAND
, lpAccelTbl
->tbl
[i
].wIDval
, 0x00010000L
);
649 if (msg
->message
== WM_KEYUP
) return 1;
652 if (msg
->wParam
== lpAccelTbl
->tbl
[i
].wEvent
&&
653 msg
->message
== WM_CHAR
) {
654 SendMessage(hWnd
, WM_COMMAND
, lpAccelTbl
->tbl
[i
].wIDval
, 0x00010000L
);
659 GlobalUnlock(hAccel
);
663 /**********************************************************************
664 * FindResource [KERNEL.60]
666 HANDLE
FindResource(HANDLE instance
, LPSTR resource_name
, LPSTR type_name
)
674 #ifdef DEBUG_RESOURCE
675 printf("FindResource hInst=%04X typename=%08X resname=%08X\n",
676 instance
, type_name
, resource_name
);
678 if (OpenResourceFile(instance
) < 0)
681 rh
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(*r
));
684 r
= (RESOURCE
*)GlobalLock(rh
);
691 if (((int) resource_name
& 0xffff0000) == 0)
693 r
->size_shift
= FindResourceByNumber(&r
->nameinfo
, (int)type_name
,
694 (int) resource_name
| 0x8000);
698 r
->size_shift
= FindResourceByName(&r
->nameinfo
, (int)type_name
,
702 if (r
->size_shift
== -1)
711 /**********************************************************************
712 * LoadResource [KERNEL.61]
714 HANDLE
LoadResource(HANDLE instance
, HANDLE hResInfo
)
724 if (OpenResourceFile(instance
) < 0)
727 r
= (RESOURCE
*)GlobalLock(hResInfo
);
731 image_size
= r
->nameinfo
.length
<< r
->size_shift
;
733 h
= r
->rsc_mem
= GlobalAlloc(GMEM_MOVEABLE
, image_size
);
734 image
= GlobalLock(h
);
736 lseek(ResourceFd
, ((int) r
->nameinfo
.offset
<< r
->size_shift
), SEEK_SET
);
738 if (image
== NULL
|| read(ResourceFd
, image
, image_size
) != image_size
)
741 GlobalUnlock(hResInfo
);
746 GlobalUnlock(hResInfo
);
750 /**********************************************************************
751 * LockResource [KERNEL.62]
753 LPSTR
LockResource(HANDLE hResData
)
755 return GlobalLock(hResData
);
758 /**********************************************************************
759 * FreeResource [KERNEL.63]
761 HANDLE
FreeResource(HANDLE hResData
)
765 for (r
= rp
= Top
; r
!= NULL
; r
= r
->next
)
767 if (r
->info_mem
== hResData
)
774 GlobalFree(r
->rsc_mem
);
775 GlobalFree(r
->info_mem
);
783 /**********************************************************************
784 * AccessResource [KERNEL.64]
786 int AccessResource(HANDLE instance
, HANDLE hResInfo
)
789 #ifdef DEBUG_RESOURCE
790 printf("AccessResource(%04X, %04X);\n", instance
, hResInfo
);
793 resfile = OpenResourceFile(instance);
801 /**********************************************************************
805 RSC_LoadResource(int instance
, char *rsc_name
, int type
, int *image_size_ret
)
807 struct resource_nameinfo_s nameinfo
;
820 else if (OpenResourceFile(instance
) < 0)
824 * Get resource by ordinal
826 if (((int) rsc_name
& 0xffff0000) == 0)
828 size_shift
= FindResourceByNumber(&nameinfo
, type
,
829 (int) rsc_name
| 0x8000);
832 * Get resource by name
836 size_shift
= FindResourceByName(&nameinfo
, type
, rsc_name
);
838 if (size_shift
== -1) {
839 if ((LONG
)rsc_name
>= 0x00010000L
)
840 printf("RSC_LoadResource / Resource '%s' not Found !\n", rsc_name
);
842 printf("RSC_LoadResource / Resource '%X' not Found !\n", rsc_name
);
848 lseek(ResourceFd
, ((int) nameinfo
.offset
<< size_shift
), SEEK_SET
);
850 image_size
= nameinfo
.length
<< size_shift
;
851 if (image_size_ret
!= NULL
)
852 *image_size_ret
= image_size
;
853 hmem
= GlobalAlloc(GMEM_MOVEABLE
, image_size
);
854 image
= GlobalLock(hmem
);
855 if (image
== NULL
|| read(ResourceFd
, image
, image_size
) != image_size
)
865 /**********************************************************************
869 LoadString(HANDLE instance
, WORD resource_id
, LPSTR buffer
, int buflen
)
877 #ifdef DEBUG_RESOURCE
878 printf("LoadString: instance = %04x, id = %d, "
879 "buffer = %08x, length = %d\n",
880 instance
, resource_id
, buffer
, buflen
);
883 hmem
= RSC_LoadResource(instance
, (char *) ((resource_id
>> 4) + 1),
884 NE_RSCTYPE_STRING
, &rsc_size
);
888 p
= GlobalLock(hmem
);
889 string_num
= resource_id
& 0x000f;
890 for (i
= 0; i
< string_num
; i
++)
893 i
= MIN(buflen
- 1, *p
);
895 memcpy(buffer
, p
+ 1, i
);
903 printf("LoadString // I dont know why , but caller give buflen=%d *p=%d !\n", buflen
, *p
);
904 printf("LoadString // and try to obtain string '%s'\n", p
+ 1);
908 #ifdef DEBUG_RESOURCE
909 printf(" '%s'\n", buffer
);
914 /**********************************************************************
918 RSC_LoadMenu(HANDLE instance
, LPSTR menu_name
)
920 #ifdef DEBUG_RESOURCE
921 printf("RSC_LoadMenu: instance = %04x, name = '%s'\n",
922 instance
, menu_name
);
924 return RSC_LoadResource(instance
, menu_name
, NE_RSCTYPE_MENU
, NULL
);
927 /**********************************************************************
931 LoadBitmap(HANDLE instance
, LPSTR bmp_name
)
940 #ifdef DEBUG_RESOURCE
941 printf("LoadBitmap: instance = %04x, name = %08x\n",
944 if (instance
== (HANDLE
)NULL
) instance
= hSysRes
;
945 if (!(hdc
= GetDC(GetDesktopWindow()))) return 0;
947 rsc_mem
= RSC_LoadResource(instance
, bmp_name
, NE_RSCTYPE_BITMAP
,
949 if (rsc_mem
== (HANDLE
)NULL
) {
950 printf("LoadBitmap / BitMap %04X not Found !\n", bmp_name
);
953 lp
= (long *) GlobalLock(rsc_mem
);
959 size
= CONV_LONG (*lp
);
960 if (size
== sizeof(BITMAPCOREHEADER
)){
961 CONV_BITMAPCOREHEADER (lp
);
962 hbitmap
= ConvertCoreBitmap( hdc
, (BITMAPCOREHEADER
*) lp
);
963 } else if (size
== sizeof(BITMAPINFOHEADER
)){
964 CONV_BITMAPINFO (lp
);
965 hbitmap
= ConvertInfoBitmap( hdc
, (BITMAPINFO
*) lp
);
972 /**********************************************************************
973 * CreateIcon [USER.407]
975 HICON
CreateIcon(HANDLE hInstance
, int nWidth
, int nHeight
,
976 BYTE nPlanes
, BYTE nBitsPixel
, LPSTR lpANDbits
,
982 #ifdef DEBUG_RESOURCE
983 printf("CreateIcon: hInstance = %04x, nWidth = %08x, nHeight = %08x \n",
984 hInstance
, nWidth
, nHeight
);
985 printf(" nPlanes = %04x, nBitsPixel = %04x,",nPlanes
, nBitsPixel
);
986 printf(" lpANDbits= %04x, lpXORbits = %04x, \n",lpANDbits
, lpXORbits
);
989 if (hInstance
== (HANDLE
)NULL
) {
990 printf("CreateIcon / hInstance %04x not Found!\n",hInstance
);
993 hIcon
= GlobalAlloc(GMEM_MOVEABLE
, sizeof(ICONALLOC
) + 1024);
994 if (hIcon
== (HICON
)NULL
) {
995 printf("Can't allocate memory for Icon in CreateIcon\n");
998 lpico
= (ICONALLOC
*)GlobalLock(hIcon
);
1000 lpico
->descriptor
.Width
=nWidth
;
1001 lpico
->descriptor
.Height
=nHeight
;
1002 lpico
->descriptor
.ColorCount
=16; /* Dummy Value */
1003 lpico
->descriptor
.Reserved1
=0;
1004 lpico
->descriptor
.Reserved2
=nPlanes
;
1005 lpico
->descriptor
.Reserved3
=nWidth
*nHeight
;
1007 /* either nPlanes and/or nBitCount is set to one */
1008 lpico
->descriptor
.icoDIBSize
=nWidth
*nHeight
*nPlanes
*nBitsPixel
;
1009 lpico
->descriptor
.icoDIBOffset
=0;
1011 if( !(lpico
->hBitmap
=CreateBitmap(nWidth
, nHeight
, nPlanes
, nBitsPixel
,
1013 printf("CreateIcon: couldn't create the XOR bitmap\n");
1017 /* the AND BitMask is always monochrome */
1018 if( !(lpico
->hBitMask
=CreateBitmap(nWidth
, nHeight
, 1, 1, lpANDbits
)) ) {
1019 printf("CreateIcon: couldn't create the AND bitmap\n");
1023 GlobalUnlock(hIcon
);
1024 #ifdef DEBUG_RESOURCE
1025 printf("CreateIcon Alloc hIcon=%X\n", hIcon
);