bool CMenuSpawn::AddToolBarResource(unsigned int resId, UINT uBitmap) { HRSRC hRsrc = ::FindResource(theApp->GetInstance(), MAKEINTRESOURCE(resId), RT_TOOLBAR); if (hRsrc == NULL) return false; HGLOBAL hGlb = ::LoadResource(theApp->GetInstance(), hRsrc); if (hGlb == NULL) return false; ToolBarData* pTBData = (ToolBarData*) ::LockResource(hGlb); if (pTBData == NULL) return false; ASSERT(pTBData->wVersion == 1); CBitmap bmp; bmp.LoadBitmap(theApp->GetInstance(),(LPCSTR)resId); int nBmpItems = ilList.Add(&bmp, RGB(192,192,192)); bmp.DeleteObject(); WORD* pItem = (WORD*)(pTBData+1); for(int i=0; i<pTBData->wItemCount; i++, pItem++) { if(*pItem != ID_SEPARATOR) AddImageItem(nBmpItems++, (WORD) *pItem); } // ** it seem that Windows doesn't free these resource (from Heitor Tome) UnlockResource(hGlb); FreeResource(hGlb); // ** return true; }
bool CMenuSpawn::LoadToolBarResource(unsigned int resId, UINT uBitmap) { HRSRC hRsrc = ::FindResource(NULL, MAKEINTRESOURCE(resId), RT_TOOLBAR); if (hRsrc == NULL) return false; HGLOBAL hGlb = ::LoadResource(theApp->GetInstance(), hRsrc); if (hGlb == NULL) return false; ToolBarData* pTBData = (ToolBarData*) ::LockResource(hGlb); if (pTBData == NULL) return false; ASSERT(pTBData->wVersion == 1); szImage.cx = (int) pTBData->wWidth; szImage.cy = (int) pTBData->wHeight; if (uBitmap != -1) { if(!ilList.CreateColor(uBitmap)) return FALSE; } else { if (ilList.Create(szImage.cx, szImage.cy, ILC_COLOR4|ILC_MASK, pTBData->wItemCount, 0) == false) return false; ilList.SetBkColor(cr3dFace); CBitmap bmp; bmp.LoadBitmap(theApp->GetInstance(),(LPCSTR)resId); ilList.Add(&bmp, RGB(192,192,192)); bmp.DeleteObject(); } WORD* pItem = (WORD*)(pTBData+1); int nBmpItems = 0; for(int i=0; i<pTBData->wItemCount; i++, pItem++) { if(*pItem != ID_SEPARATOR) AddImageItem(nBmpItems++, (WORD) *pItem); } // ** it seem that Windows doesn't free these resource (from Heitor Tome) UnlockResource(hGlb); FreeResource(hGlb); // ** return true; }
bool CGfxPopupMenu::LoadToolBarResource(unsigned int resId) { //David 08/04/98 - start - put CMenuSpawn in DLL HINSTANCE hInst = AfxFindResourceHandle (MAKEINTRESOURCE(resId), RT_TOOLBAR); if (!hInst) return false; //David 08/04/98 - end - put CMenuSpawn in DLL HRSRC hRsrc = ::FindResource(/*AfxGetResourceHandle()*/hInst, MAKEINTRESOURCE(resId), RT_TOOLBAR); if (hRsrc == NULL) return false; HGLOBAL hGlb = ::LoadResource(/*AfxGetResourceHandle()*/hInst, hRsrc); if (hGlb == NULL) return false; ToolBarData* pTBData = (ToolBarData*) ::LockResource(hGlb); if (pTBData == NULL) return false; ASSERT(pTBData->wVersion == 1); szImage.cx = (int) pTBData->wWidth; szImage.cy = (int) pTBData->wHeight; if (ilList.Create(szImage.cx, szImage.cy, ILC_COLOR4|ILC_MASK, pTBData->wItemCount, 0) == false) return false; ilList.SetBkColor(cr3dFace); CBitmap bmp; bmp.LoadBitmap(resId); ilList.Add(&bmp, RGB(192,192,192)); bmp.DeleteObject(); WORD* pItem = (WORD*)(pTBData+1); int nBmpItems = 0; for(int i=0; i<pTBData->wItemCount; i++, pItem++) { if(*pItem != ID_SEPARATOR) AddImageItem(nBmpItems++, (WORD) *pItem); } // ** it seem that Windows doesn't free these resource (from Heitor Tome) ::UnlockResource(hGlb); ::FreeResource(hGlb); // ** return true; }