This commit is contained in:
2024-08-16 13:56:54 -04:00
parent 75df00b3e3
commit 2e364ff470
19 changed files with 211 additions and 125 deletions

View File

@@ -6,15 +6,19 @@
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif
#ifndef _COMMON_BLOCK_HPP_
#include <common/block.hpp>
#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};
enum Resource {RtAccelerator = (int)RT_ACCELERATOR, RtBitmap = (int)RT_BITMAP, RtDialog = (int)RT_DIALOG,
RtFont=(int)RT_FONT,RtFontDir=(int)RT_FONTDIR,RtMenu=(int)RT_MENU,RtData=(int)RT_RCDATA,
RtString=(int)RT_STRING,RtMessageTable=(int)RT_MESSAGETABLE,RtCursor=(int)RT_CURSOR,
RtGroupCursor=(int)RT_GROUP_CURSOR,RtIcon=(int)RT_ICON,RtGroupIcon=(int)RT_GROUP_ICON,
RtVersion=(int)RT_VERSION};
};
class ResDisposition
@@ -29,15 +33,18 @@ class ResData
public:
ResData(void);
ResData(const ResData &someResData);
ResData(const String &resName,ResType::Resource resType=ResType::RtData,HMODULE hResModule=GetModuleHandle(0));
ResData(WORD resourceId,ResType::Resource resType=ResType::RtData,HMODULE hResModule=GetModuleHandle(0));
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;
DWORD getSize()const;
WORD isOkay(void)const;
private:
void create(const String &resName,ResType::Resource resType=ResType::RtData,HMODULE hResModule=::GetModuleHandle(0));
void destroy(void);
void create(WORD resourceId, ResType::Resource resType = ResType::RtData, HMODULE hResModule = ::GetModuleHandle(0));
void destroy(void);
HRSRC resHandle(void)const;
void resHandle(HRSRC resHandle);
HGLOBAL resData(void)const;
@@ -45,8 +52,10 @@ private:
ResDisposition::Disposition resDisp(void)const;
void resDisp(ResDisposition::Disposition resDisp);
HRSRC mhResHandle;
HGLOBAL mhResData;
HRSRC mhResHandle; // returned from ::FindResource()
HGLOBAL mhResData; // returned from ::LoadResource();
HMODULE mhResModule; // the module
T* pData;
ResDisposition::Disposition mDisposition;
};
@@ -68,11 +77,21 @@ ResData<T>::ResData(const ResData &someResData)
template <class T>
inline
ResData<T>::ResData(const String &resName,ResType::Resource resType,HMODULE hResModule)
: mhResHandle(0), mhResData(0), mDisposition(ResDisposition::Delete)
: mhResHandle(0), mhResData(0), mhResModule(hResModule), mDisposition(ResDisposition::Delete)
{
create(resName,resType,hResModule);
}
template <class T>
inline
ResData<T>::ResData(WORD resourceId, ResType::Resource resType, HMODULE hResModule)
: mhResHandle(0), mhResData(0), mhResModule(hResModule), mDisposition(ResDisposition::Delete)
{
create(resourceId, resType, hResModule);
}
template <class T>
inline
ResData<T>::~ResData()
@@ -102,24 +121,50 @@ ResData<T> &ResData<T>::operator=(const String &resName)
return *this;
}
template <class T>
inline
DWORD ResData<T>::getSize()const
{
if (!isOkay())return 0;
return ::SizeofResource(mhResModule, mhResHandle);
}
template <class T>
inline
ResData<T>::operator T*(void)const
{
return (T*)mhResData;
return pData;
}
template <class T>
inline
void ResData<T>::create(const String &resName,ResType::Resource resType,HMODULE hResModule)
{
ResType resourceType = ResType();
destroy();
resHandle(::FindResource(hResModule,resName,(const char*)resType));
resHandle(::FindResource(hResModule, resName, MAKEINTRESOURCE(resType)));
if(!resHandle())return;
resData(::LoadResource(hResModule,mhResHandle));
resDisp(ResDisposition::Delete);
pData = (T*)::LockResource(resData());
}
template <class T>
inline
void ResData<T>::create(WORD resourceId, ResType::Resource resType, HMODULE hResModule)
{
ResType resourceType = ResType();
destroy();
// resHandle(::FindResource(hResModule, resName, (const char*)resType));
resHandle(::FindResource(hResModule, MAKEINTRESOURCE(resourceId), MAKEINTRESOURCE(resType)));
if (!resHandle())return;
resData(::LoadResource(hResModule, mhResHandle));
resDisp(ResDisposition::Delete);
pData = (T*)::LockResource(resData());
}
template <class T>
inline
void ResData<T>::destroy(void)
@@ -128,6 +173,7 @@ void ResData<T>::destroy(void)
::FreeResource(resData());
resData(0);
resHandle(0);
pData = 0;
resDisp(ResDisposition::Invalid);
}