#include #include #include #include #include OwnerDraw::OwnerDraw() : mhLibrary(0) { String dllPathFileName; dllPathFileName.reserve(String::MaxString); ::GetWindowsDirectory(dllPathFileName,String::MaxString-1); #if defined(__FLAT__) dllPathFileName+="\\RESLIB32.DLL"; #else dllPathFileName+="\\RESLIB16.DLL"; #endif mhLibrary=::LoadLibrary(dllPathFileName); if((UINT)mhLibrary<32) ::MessageBox(NULL,(LPSTR)"Could not load resource library!",(LPSTR)"RESOURCE ERROR",MB_ICONSTOP|MB_APPLMODAL); return; } OwnerDraw::~OwnerDraw() { if(0!=mhLibrary)::FreeLibrary(mhLibrary); } int OwnerDraw::associate(int ctlID,String &focusUp,String &noFocusUp,String &focusDown,FocusItem focusItem) { int itemIndex; if(!(itemIndex=locateLinkedButton(ctlID)))mLinkedButtons.insert(&LinkedButton(ctlID,focusUp,noFocusUp,focusDown,mhLibrary,(LinkedButton::FocusItem)focusItem)); else { itemIndex--; mLinkedButtons[itemIndex].referenceCount(mLinkedButtons[itemIndex].referenceCount()+1); } return TRUE; } int OwnerDraw::handleOwnerButton(int ctlID,LPARAM lParam) { int itemIndex; LPDRAWITEMSTRUCT lpControlData((LPDRAWITEMSTRUCT)lParam); if(!(itemIndex=locateLinkedButton(ctlID)))return FALSE; return mLinkedButtons[--itemIndex].drawButton(lpControlData); } void OwnerDraw::freeButton(int ctlID) { int itemIndex; if(!(itemIndex=locateLinkedButton(ctlID)))return; --itemIndex; if(mLinkedButtons[itemIndex].referenceCount()-1<=0)mLinkedButtons.remove(itemIndex); else mLinkedButtons[itemIndex].referenceCount(mLinkedButtons[itemIndex].referenceCount()-1); } int OwnerDraw::locateLinkedButton(int ctlID) { size_t size((int)mLinkedButtons.size()); for(int i=0;i