#ifndef _COMMON_RESDATA_HPP_ #define _COMMON_RESDATA_HPP_ #ifndef _COMMON_WINDOWS_HPP_ #include #endif #ifndef _COMMON_STRING_HPP_ #include #endif class ResType { public: enum Resource{RtAccelerator=RT_ACCELERATOR,RtBitmap=RT_BITMAP,RtDialog=RT_DIALOG, RtFont=RT_FONT,RtFontDir=RT_FONTDIR,RtMenu=RT_MENU,RtData=RT_RCDATA, RtString=RT_STRING,RtMessageTable=RT_MESSAGETABLE,RtCursor=RT_CURSOR, RtGroupCursor=RT_GROUP_CURSOR,RtIcon=RT_ICON,RtGroupIcon=RT_GROUP_ICON, RtVersion=RT_VERSION}; }; class ResDisposition { public: enum Disposition{Assume,Delete,Invalid}; }; template class ResData { public: ResData(void); ResData(const ResData &someResData); ResData(const String &resName,ResType::Resource resType=ResType::RtData,HMODULE hResModule=GetModuleHandle(0)); virtual ~ResData(); ResData &operator=(const ResData &someResData); ResData &operator=(const String &resName); operator T*(void)const; WORD isOkay(void)const; private: void create(const String &resName,ResType::Resource resType=ResType::RtData,HMODULE hResModule=::GetModuleHandle(0)); void destroy(void); HRSRC resHandle(void)const; void resHandle(HRSRC resHandle); HGLOBAL resData(void)const; void resData(HGLOBAL resData); ResDisposition::Disposition resDisp(void)const; void resDisp(ResDisposition::Disposition resDisp); HRSRC mhResHandle; HGLOBAL mhResData; ResDisposition::Disposition mDisposition; }; template inline ResData::ResData(void) : mhResHandle(0), mhResData(0), mDisposition(ResDisposition::Invalid) { } template inline ResData::ResData(const ResData &someResData) : mhResHandle(0), mhResData(0), mDisposition(ResDisposition::Invalid) { *this=someResData; } template inline ResData::ResData(const String &resName,ResType::Resource resType,HMODULE hResModule) : mhResHandle(0), mhResData(0), mDisposition(ResDisposition::Delete) { create(resName,resType,hResModule); } template inline ResData::~ResData() { destroy(); } template inline ResData &ResData::operator=(const ResData &someResData) { if(!someResData.isOkay())return *this; destroy(); resData(someResData.resData()); resHandle(someResData.resHandle()); resDisp(ResDisposition::Assume); return *this; } template inline ResData &ResData::operator=(const String &resName) { if(resName.isNull())return *this; destroy(); create(resName); return *this; } template inline ResData::operator T*(void)const { return (T*)mhResData; } template inline void ResData::create(const String &resName,ResType::Resource resType,HMODULE hResModule) { destroy(); resHandle(::FindResource(hResModule,resName,(const char*)resType)); if(!resHandle())return; resData(::LoadResource(hResModule,mhResHandle)); resDisp(ResDisposition::Delete); } template inline void ResData::destroy(void) { if(!resData()||ResDisposition::Assume==resDisp())return; ::FreeResource(resData()); resData(0); resHandle(0); resDisp(ResDisposition::Invalid); } template inline HRSRC ResData::resHandle(void)const { return mhResHandle; } template inline void ResData::resHandle(HRSRC resHandle) { mhResHandle=resHandle; } template inline HGLOBAL ResData::resData(void)const { return mhResData; } template inline void ResData::resData(HGLOBAL resData) { mhResData=resData; } template inline ResDisposition::Disposition ResData::resDisp(void)const { return mDisposition; } template inline void ResData::resDisp(ResDisposition::Disposition resDisp) { mDisposition=resDisp; } template inline WORD ResData::isOkay(void)const { return (resData()&&resHandle()); } #endif