PRESLINK AllocResLink( PRES pRes) { PRESLINK prl; PRES pResNew; PRES2 pRes2; LPTSTR pszName; INT cbName; LPTSTR pszType; if (!(prl = (PRESLINK)MyAlloc(sizeof(RESLINK)))) return NULL; prl->prlNext = NULL; prl->cbRes = ResourceSize(pRes); if (!(prl->hRes = GlobalAlloc(GMEM_MOVEABLE, prl->cbRes))) { MyFree(prl); Message(MSG_OUTOFMEMORY); return NULL; } pResNew = (PRES)GlobalLock(prl->hRes); memcpy(pResNew, pRes, prl->cbRes); GlobalUnlock(prl->hRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == ORDID_RT_DIALOG) { prl->fDlgResource = TRUE; pszName = ResourceName(pRes); cbName = NameOrdLen(pszName); if (!(prl->pszName = MyAlloc(cbName))) { GlobalFree(prl->hRes); MyFree(prl); return NULL; } NameOrdCpy(prl->pszName, pszName); pRes2 = ResourcePart2(pRes); prl->wLanguage = pRes2->LanguageId; } else { prl->fDlgResource = FALSE; prl->pszName = NULL; prl->wLanguage = 0; } return prl; }
static CONTROLITEM *ParseControlData(CONTROLITEM * pcd, int fextStyle) { char *pb,*Class,*Text,Ascii[250]; CLASSTEMPLATE *lpvdict; int Style,ExtStyle; if (fextStyle) { pcd = (CONTROLITEM *)((PBYTE)pcd + 4); Style = pcd->lExtendedStyle; ExtStyle = pcd->Style; } else { Style = pcd->Style; ExtStyle = pcd->lExtendedStyle; } printf("Control Id = %d\n",pcd->ID); printf("Style= 0x%x, extended style 0x%x. Coords: x=%d, y=%d, cx=%d, cy=%d\n", Style,ExtStyle,pcd->x,pcd->y,pcd->cx,pcd->cy); pb = (PBYTE)pcd + SIZEOF_CONTROLITEM; Class = (LPTSTR)pb; lpvdict = (CLASSTEMPLATE *)pb; if (lpvdict->Scheme == RCH_ORDINAL_SCHEME || lpvdict->Scheme == 0xFFFF0000) { pb += sizeof(CLASSTEMPLATE); } else { if (pb[0] == 0 && pb[1] == 0) pb += 2; Class = (LPTSTR)pb; pb += NameOrdLenW((LPTSTR)pb); } Text = (LPTSTR)pb; ConvertWideString(Text,Ascii); printf("Text \"%s\"\n",Ascii); if (IsOrd(Class)) printf("Class = 0x%x\n",OrdID(Class)); else { printf("Class = 0x%d\n",*Class); } pb += NameOrdLenW((LPTSTR)pb); /* * Finally, skip the Create Struct Data. * After this, pb will be pointing to the next control. */ pb += *(PWORD)pb + sizeof(WORD); DWordAlign((PBYTE *)&pb); return (CONTROLITEM *)pb; }
STATICFN BOOL IDUsedByCtrl( INT id) { register NPCTYPE npc; for (npc = npcHead; npc; npc = npc->npcNext) { if (npc->id == id || (npc->pwcd->iType == W_ICON && npc->text && IsOrd(npc->text) && id == (INT)OrdID(npc->text))) return TRUE; } return FALSE; }
static HWND SearchResource(LPCSTR lpName, int type, DLGPROC pDialogProc, LPARAM param, char *lpFileBase, int TotalFileSize, HWND parentWnd) { char *pResAll = lpFileBase + TotalFileSize; PRES pRes = (PRES)lpFileBase; char pszSearchedName[256]; char *pszType = ResourceType(pRes); char *pszName; int size = ResourceSize(pRes); char Name[512],*bb; PDIALOGBOXHEADER pdbh; HWND result; UINT_PTR ul; ul = (UINT_PTR)lpName; if (HIWORD(ul) == 0) { sprintf(pszSearchedName,"%d",LOWORD(ul)); } else if (IsOrd((char *)lpName)) { sprintf(pszSearchedName,"%d",OrdID(lpName)); } else if (lpName[1] == 0 && lpName[3] == 0) { ConvertWideString((char *)lpName,(char *)pszSearchedName); } else { strcpy(pszSearchedName,lpName); } do { if (pRes->HeaderSize+pRes->DataSize == 0) break; if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_DLGINCLUDE) { /* Ignore include files */ ; } else if (IsOrd((char *)pRes) && OrdID(pRes) == ORDID_RT_RESOURCE32) { /* * This is the dummy resource that identifies a * 32 bit resource file. This resource should be * skipped also. */ } else { /* This is some other kind of a resource. See if it matches */ if (pRes->DataSize) { int size = ResourceSize(pRes); pszType = ResourceType(pRes); if (IsOrd(pszType) && OrdID(pszType) == type) { pszName = ResourceName(pRes); if (!IsOrd(pszName)) { if (pszName[1] == 0 && pszName[3] == 0) ConvertWideString(pszName,Name); else strcpy(Name,pszName); } else { sprintf(Name,"%d",OrdID(pszName)); } if (!strcmp(Name,pszSearchedName)) { /* found it.*/ if (type == 5) { /* Build a dialog box */ pdbh = (PDIALOGBOXHEADER) SkipResHeader(pRes); bb = malloc(size); memcpy(bb,pdbh,size); result = CreateDialogIndirectParam(GetModuleHandle(NULL), (LPDLGTEMPLATE)bb, parentWnd, pDialogProc,param); free(bb); return result; } else if (type == 4) { /* Build a menu */ return (HWND) ReadMenu((char *)SkipResHeader(pRes)); } else if (type == 3) { /* Build an Icon */ HICON hicon; hicon = CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, TRUE, 0x30000); return (HWND)hicon; } else if (type == 1) { /* Build a cursor */ return (HWND)CreateIconFromResource((PBYTE)SkipResHeader(pRes), size, FALSE, 0x30000); } else if (type == 2 || type == 14) { /* Build bitmap */ char *start = SkipResHeader(pRes); bb = malloc(size); memcpy(bb,start,size); return (HWND) bb; } } } } } /* Move to the next resource. */ pRes = (PRES) (((char *) pRes) + pRes->HeaderSize + pRes->DataSize); DWordAlign((PBYTE *)&pRes); } while (pRes < (PRES) ((char *) pResAll + size)); return (HWND) 0; }