| 1 | /* $Id: cvticongrp.cpp,v 1.7 2000-05-28 16:45:12 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * PE2LX Icon group code | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 | #define INCL_GPIBITMAPS | 
|---|
| 13 | #define INCL_BITMAPFILEFORMAT | 
|---|
| 14 | #define INCL_DOSFILEMGR          /* File Manager values      */ | 
|---|
| 15 | #define INCL_DOSERRORS           /* DOS Error values         */ | 
|---|
| 16 | #define INCL_DOSPROCESS          /* DOS Process values       */ | 
|---|
| 17 | #define INCL_DOSMISC             /* DOS Miscellanous values  */ | 
|---|
| 18 | #define INCL_WIN | 
|---|
| 19 | #include <os2wrap.h> | 
|---|
| 20 | #include <stdio.h> | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 | #include <stdlib.h> | 
|---|
| 23 | #include <string.h> | 
|---|
| 24 | #include <win32type.h> | 
|---|
| 25 | #include <win32api.h> | 
|---|
| 26 | #include <winconst.h> | 
|---|
| 27 | #include <winicon.h> | 
|---|
| 28 | #include <misc.h> | 
|---|
| 29 | #include "cvtresource.h" | 
|---|
| 30 | #include <winres.h> | 
|---|
| 31 |  | 
|---|
| 32 | #define DBG_LOCALLOG    DBG_cvticongrp | 
|---|
| 33 | #include "dbglocal.h" | 
|---|
| 34 |  | 
|---|
| 35 | //****************************************************************************** | 
|---|
| 36 | //****************************************************************************** | 
|---|
| 37 | void *ConvertIconGroup(IconHeader *ihdr, int size, Win32ImageBase *module) | 
|---|
| 38 | { | 
|---|
| 39 | ResourceDirectory *rdir = (ResourceDirectory *)(ihdr + 1); | 
|---|
| 40 | int i, groupsize = 0, os2iconsize; | 
|---|
| 41 | BITMAPARRAYFILEHEADER2 *bafh, *orgbafh; | 
|---|
| 42 | WINBITMAPINFOHEADER    *iconhdr; | 
|---|
| 43 | void                   *os2icon; | 
|---|
| 44 | HRSRC                   hRes; | 
|---|
| 45 |  | 
|---|
| 46 | dprintf(("Icon Group type :%d", ihdr->wType)); | 
|---|
| 47 | dprintf(("Icon Group count:%d", ihdr->wCount)); | 
|---|
| 48 | for(i=0;i<ihdr->wCount;i++) { | 
|---|
| 49 | dprintf2(("Icon    : %d", rdir->wNameOrdinal)); | 
|---|
| 50 | dprintf2(("Width   : %d", (int)rdir->bWidth)); | 
|---|
| 51 | dprintf2(("Height  : %d", (int)rdir->bHeight)); | 
|---|
| 52 | dprintf2(("Colors  : %d", (int)rdir->bColorCount)); | 
|---|
| 53 | dprintf2(("Bits    : %d", rdir->wBitCount)); | 
|---|
| 54 | dprintf2(("ResBytes: %d", rdir->lBytesInRes)); | 
|---|
| 55 | hRes = FindResourceA(module->getInstanceHandle(), | 
|---|
| 56 | (LPCSTR)rdir->wNameOrdinal, (LPSTR)NTRT_ICON); | 
|---|
| 57 |  | 
|---|
| 58 | groupsize += QueryConvertedResourceSize(module->getInstanceHandle(), (char *)NTRT_ICON, hRes); | 
|---|
| 59 | rdir++; | 
|---|
| 60 | } | 
|---|
| 61 | bafh    = (BITMAPARRAYFILEHEADER2 *)malloc(groupsize+ihdr->wCount*sizeof(BITMAPARRAYFILEHEADER2)); | 
|---|
| 62 | orgbafh = bafh; | 
|---|
| 63 |  | 
|---|
| 64 | rdir = (ResourceDirectory *)(ihdr + 1); | 
|---|
| 65 | for(i=0;i<ihdr->wCount;i++) { | 
|---|
| 66 | bafh->usType    = BFT_BITMAPARRAY; | 
|---|
| 67 | bafh->cbSize    = sizeof(BITMAPARRAYFILEHEADER2); | 
|---|
| 68 | bafh->cxDisplay = 0; | 
|---|
| 69 | bafh->cyDisplay = 0; | 
|---|
| 70 | hRes = FindResourceA(module->getInstanceHandle(), | 
|---|
| 71 | (LPCSTR)rdir->wNameOrdinal, (LPSTR)NTRT_ICON); | 
|---|
| 72 |  | 
|---|
| 73 | if(hRes == NULL) { | 
|---|
| 74 | dprintf(("Can't find icon!")); | 
|---|
| 75 | rdir++; | 
|---|
| 76 | continue; | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | iconhdr = (WINBITMAPINFOHEADER *)LockResource(LoadResource(module->getInstanceHandle(), hRes)); | 
|---|
| 80 | os2icon = ConvertIcon(iconhdr, SizeofResource(module->getInstanceHandle(), hRes), &os2iconsize, (int)bafh - (int)orgbafh + sizeof(BITMAPARRAYFILEHEADER2)-sizeof(BITMAPFILEHEADER2)); | 
|---|
| 81 |  | 
|---|
| 82 | if(os2icon == NULL) { | 
|---|
| 83 | dprintf(("Can't convert icon!")); | 
|---|
| 84 | rdir++; | 
|---|
| 85 | continue; | 
|---|
| 86 | } | 
|---|
| 87 |  | 
|---|
| 88 | if(i != ihdr->wCount -1) { | 
|---|
| 89 | bafh->offNext = (int)&bafh->bfh2 - (int)orgbafh + os2iconsize; | 
|---|
| 90 | } | 
|---|
| 91 | else    bafh->offNext = 0; | 
|---|
| 92 |  | 
|---|
| 93 | memcpy((char *)&bafh->bfh2, os2icon, os2iconsize); | 
|---|
| 94 | free(os2icon); | 
|---|
| 95 |  | 
|---|
| 96 | bafh = (BITMAPARRAYFILEHEADER2 *)((int)&bafh->bfh2 + os2iconsize); | 
|---|
| 97 |  | 
|---|
| 98 | rdir++; | 
|---|
| 99 | } | 
|---|
| 100 | return (void *)orgbafh; | 
|---|
| 101 | } | 
|---|
| 102 | //****************************************************************************** | 
|---|
| 103 | //****************************************************************************** | 
|---|