2026-10-04 00:04:20 +08:00
|
|
|
#include "StdAfx.h"
|
2026-09-28 15:28:50 +08:00
|
|
|
#include "KTMenuResource.h"
|
|
|
|
|
|
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
#undef THIS_FILE
|
|
|
|
|
static char THIS_FILE[]=__FILE__;
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_SERIAL(KTMenuResource, KTMenuBase,0)
|
|
|
|
|
|
|
|
|
|
KTMenuResource::KTMenuResource()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KTMenuResource::~KTMenuResource()
|
|
|
|
|
{
|
|
|
|
|
Clean();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KTMenuResource::Clean()
|
|
|
|
|
{
|
|
|
|
|
CString sRes;
|
|
|
|
|
KTResItem* pRes;
|
|
|
|
|
POSITION pos = m_mapItem.GetStartPosition();
|
|
|
|
|
while (pos != NULL)
|
|
|
|
|
{
|
|
|
|
|
m_mapItem.GetNextAssoc(pos, sRes, (void*&)pRes);
|
|
|
|
|
ASSERT(pRes != NULL);
|
|
|
|
|
delete pRes;
|
|
|
|
|
}
|
|
|
|
|
m_mapItem.RemoveAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KTMenuResource::Serialize(CArchive& ar)
|
|
|
|
|
{
|
|
|
|
|
if (ar.IsStoring())
|
|
|
|
|
{
|
|
|
|
|
int iSize = (int)m_mapItem.GetCount();
|
|
|
|
|
ar << iSize;
|
|
|
|
|
|
|
|
|
|
CString sRes;
|
|
|
|
|
KTResItem* pRes;
|
|
|
|
|
POSITION pos = m_mapItem.GetStartPosition();
|
|
|
|
|
while (pos != NULL)
|
|
|
|
|
{
|
|
|
|
|
m_mapItem.GetNextAssoc(pos, sRes, (void*&)pRes);
|
|
|
|
|
ASSERT(pRes != NULL);
|
|
|
|
|
ar << sRes;
|
|
|
|
|
ar << pRes->m_sIcon;
|
|
|
|
|
ar << pRes->m_sInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int iSize;
|
|
|
|
|
ar >> iSize;
|
|
|
|
|
|
|
|
|
|
CString sRes;
|
|
|
|
|
KTResItem* pRes;
|
|
|
|
|
for (int i = 0; i < iSize; i++)
|
|
|
|
|
{
|
|
|
|
|
ar >> sRes;
|
|
|
|
|
if (!m_mapItem.Lookup(sRes, (void*&)pRes))
|
|
|
|
|
{
|
|
|
|
|
pRes = new KTResItem;
|
|
|
|
|
ASSERT(pRes != NULL);
|
|
|
|
|
m_mapItem.SetAt(sRes, pRes);
|
|
|
|
|
}
|
|
|
|
|
ar >> pRes->m_sIcon;
|
|
|
|
|
ar >> pRes->m_sInfo;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KTMenuBase* KTMenuResource::CreateItem(CString& sLine)
|
|
|
|
|
{
|
|
|
|
|
int iFind1 = sLine.Find(_T('='));
|
|
|
|
|
if (iFind1 <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
CString sRes = sLine.Left(iFind1);
|
|
|
|
|
sRes.TrimRight();
|
|
|
|
|
iFind1++;
|
|
|
|
|
|
|
|
|
|
if (sRes.IsEmpty())
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
KTResItem* pItem = NULL;
|
|
|
|
|
if (!m_mapItem.Lookup(sRes, (void*&)pItem))
|
|
|
|
|
{
|
|
|
|
|
pItem = new KTResItem;
|
|
|
|
|
ASSERT(pItem != NULL);
|
|
|
|
|
m_mapItem.SetAt(sRes, pItem);
|
|
|
|
|
}
|
|
|
|
|
ASSERT(pItem != NULL);
|
|
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
int iFind2 = sLine.Find(_T(','), iFind1);
|
|
|
|
|
if (iFind2 < 0)
|
|
|
|
|
{
|
|
|
|
|
pItem->m_sIcon = sLine.Mid(iFind1);
|
|
|
|
|
pItem->m_sIcon.TrimLeft();
|
|
|
|
|
pItem->m_sIcon.TrimRight();
|
|
|
|
|
if (!pItem->m_sIcon.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
iFind1 = pItem->m_sIcon.GetLength() - 1;
|
|
|
|
|
if (pItem->m_sIcon[iFind1] == _T('\"'))
|
|
|
|
|
pItem->m_sIcon.Delete(iFind1);
|
|
|
|
|
if (iFind1 > 0 && pItem->m_sIcon[0] == _T('\"'))
|
|
|
|
|
pItem->m_sIcon.Delete(0);
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
for (int i = iFind2 - 1; i > iFind1 && sLine[i] == _T(' '); i--) ;
|
|
|
|
|
|
|
|
|
|
if (sLine[i] == _T('\"'))
|
|
|
|
|
{
|
|
|
|
|
pItem->m_sIcon = sLine.Mid(iFind1, i - iFind1);
|
|
|
|
|
pItem->m_sIcon.TrimLeft();
|
|
|
|
|
pItem->m_sIcon.TrimRight();
|
|
|
|
|
if (!pItem->m_sIcon.IsEmpty() && pItem->m_sIcon[0] == _T('\"'))
|
|
|
|
|
pItem->m_sIcon.Delete(0);
|
|
|
|
|
|
|
|
|
|
iFind1 = iFind2;
|
|
|
|
|
iFind1++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iFind1 = iFind2;
|
|
|
|
|
iFind1++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
|
{
|
|
|
|
|
int iFind2 = sLine.Find(_T(','), iFind1);
|
|
|
|
|
if (iFind2 < 0)
|
|
|
|
|
{
|
|
|
|
|
pItem->m_sInfo = sLine.Mid(iFind1);
|
|
|
|
|
pItem->m_sInfo.TrimLeft();
|
|
|
|
|
pItem->m_sInfo.TrimRight();
|
|
|
|
|
if (!pItem->m_sInfo.IsEmpty())
|
|
|
|
|
{
|
|
|
|
|
iFind1 = pItem->m_sInfo.GetLength() - 1;
|
|
|
|
|
if (pItem->m_sInfo[iFind1] == _T('\"'))
|
|
|
|
|
pItem->m_sInfo.Delete(iFind1);
|
|
|
|
|
if (iFind1 > 0 && pItem->m_sInfo[0] == _T('\"'))
|
|
|
|
|
pItem->m_sInfo.Delete(0);
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
for (int i = iFind2 - 1; i > iFind1 && sLine[i] == _T(' '); i--) ;
|
|
|
|
|
|
|
|
|
|
if (sLine[i] == _T('\"'))
|
|
|
|
|
{
|
|
|
|
|
pItem->m_sInfo = sLine.Mid(iFind1, i - iFind1);
|
|
|
|
|
pItem->m_sInfo.TrimLeft();
|
|
|
|
|
pItem->m_sInfo.TrimRight();
|
|
|
|
|
if (!pItem->m_sInfo.IsEmpty() && pItem->m_sInfo[0] == _T('\"'))
|
|
|
|
|
pItem->m_sInfo.Delete(0);
|
|
|
|
|
|
|
|
|
|
iFind1 = iFind2;
|
|
|
|
|
iFind1++;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iFind1 = iFind2;
|
|
|
|
|
iFind1++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BOOL KTMenuResource::GetResource(LPCTSTR pszRes, LPCTSTR& pszIcon, LPCTSTR& pszInfo) const
|
|
|
|
|
{
|
|
|
|
|
pszIcon = NULL;
|
|
|
|
|
pszInfo = NULL;
|
|
|
|
|
|
|
|
|
|
if (pszRes == NULL || _tcslen(pszRes) <= 0)
|
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
|
|
KTResItem* pItem;
|
|
|
|
|
if (m_mapItem.Lookup(pszRes, (void*&)pItem))
|
|
|
|
|
{
|
|
|
|
|
pszIcon = pItem->m_sIcon;
|
|
|
|
|
pszInfo = pItem->m_sInfo;
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LPCTSTR KTMenuResource::GetResourceIcon(LPCTSTR pszRes) const
|
|
|
|
|
{
|
|
|
|
|
LPCTSTR pszIcon, pszInfo;
|
|
|
|
|
GetResource(pszRes, pszIcon, pszInfo);
|
|
|
|
|
return pszIcon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
HBITMAP KTMenuResource::GetResourceIcon(HINSTANCE hRes, LPCTSTR pszRes)
|
|
|
|
|
{
|
|
|
|
|
if (pszRes == NULL || _tcslen(pszRes) <= 0)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
KTResItem* pItem;
|
|
|
|
|
if (!m_mapItem.Lookup(pszRes, (void*&)pItem) || NULL == pItem)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
return ::LoadBitmap(hRes, pItem->m_sIcon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LPCTSTR KTMenuResource::GetResourceInfo(LPCTSTR pszRes)
|
|
|
|
|
{
|
|
|
|
|
LPCTSTR pszIcon, pszInfo;
|
|
|
|
|
GetResource(pszRes, pszIcon, pszInfo);
|
|
|
|
|
return pszInfo;
|
|
|
|
|
}
|