Since LoadSpriteFromRsrc() isn't yet available (as of Update 4), I thought I would try to defined a class that would let me load an Icon and use it for view decoration purposes. The Help File states that one can implement the ISprite interface:
"applications can implement this interface on other objects that are able to supply an icon resource."
So I came up with the following class:
struct MySprite : public ISprite { DEFINE_BENTLEY_REF_COUNTED_MEMBERS private: HICON m_oIcon {0}; public: MySprite() { DEFINE_BENTLEY_REF_COUNTED_MEMBER_INIT int iconID = 10003; /* IDI_ICON2; */ HINSTANCE myDll = GetModuleHandleW(L"srs_featureOperations"); m_oIcon = (HICON)LoadImage(myDll, MAKEINTRESOURCE(iconID), IMAGE_ICON, 0, 0, LR_DEFAULTCOLOR); // } ~MySprite() { // release memory form LoadImage() DeleteObject(m_oIcon); } void MakeClassAbstract() { } void GetHotSpot(Point2dP hotspot) { ICONINFO ii; GetIconInfo( m_oIcon, &ii ); hotspot->x = ii.xHotspot; hotspot->y = ii.yHotspot; return; } void GetSize(Point2dP size) { ICONINFO ii {0}; BITMAPINFO bmInf; if ( GetIconInfo( m_oIcon, &ii ) ) { if (ii.hbmColor) // ' Icon has color plane { if (GetObject(ii.hbmColor, sizeof(BITMAPINFO), &bmInf)) { size->x = bmInf.bmiHeader.biWidth; size->y = bmInf.bmiHeader.biHeight; //BitDepth = BMInf.bmBitsPixel } DeleteObject(ii.hbmColor); } else // ' Icon has no colour plane, image data stored in mask { if (GetObject(ii.hbmMask, sizeof(BITMAPINFO), &bmInf)) { size->x = bmInf.bmiHeader.biWidth; size->y = bmInf.bmiHeader.biHeight / 2; // monochrome icon contains image and XOR mask in the hbmMask //BitDepth = 1 } DeleteObject(ii.hbmMask); } } return; } bool GetUseAlpha() { return false; } }; MySprite m_oSprite;
So, when I try to use my "sprite" (m_oSprite) in my IViewDecoration::_DrawDecoration(), MicroStation immediately crashes. This leads me to believe that I have not correctly implemented ISprite class. I tested my class by calling m_oSprite.GetSize() and returned values that were correct, so I know the icon was successfully read from the DLL. Are there other requirements?
Bruce
Answer Verified By: Bruce Reeves SRNS
Just installed Update 6. Don't see IViewManager::LoadSpriteFromRsrc (in the doc's at least). Did it make it into Update 6? Or is there an alternative?
Defect #569256 reported by Jon is still open...and I didn't find any replacement either, so it doesn't look like it...