📄 bcgpskinmanager.cpp
字号:
{
g_pWorkspace->OnSelectSkin ();
}
return TRUE;
}
if (iSkin < 0 || iSkin >= m_Skins.GetSize ())
{
ASSERT(FALSE);
return FALSE;
}
CBCGPSkinEntry& skinEntry = m_Skins [iSkin];
int iLibIndex = skinEntry.m_iLibraryIndex;
int iSkinIndex = skinEntry.m_iSkinIndexInLibrary;
CBCGPSkinLibrary& skinLibrary = m_SkinLibraresInstances [iLibIndex];
if (skinLibrary.GetInstance () == NULL)
{
HINSTANCE hInstance = ::LoadLibrary (skinEntry.m_strLibraryPath);
if (!skinLibrary.Init (hInstance))
{
ASSERT(FALSE);
return FALSE;
}
}
CRuntimeClass* pSkin = skinLibrary.GetSkin (iSkinIndex);
if (pSkin == NULL)
{
ASSERT(FALSE);
return FALSE;
}
CBCGPVisualManager::DestroyInstance ();
if (m_iActiveSkin != BCG_DEFUALT_SKIN) // In case of not default previous skin we must unload it
{
if (skinEntry.m_strLibraryPath != m_Skins [m_iActiveSkin].m_strLibraryPath)
{
long lPreviousLibIndex = m_Skins [m_iActiveSkin].m_iLibraryIndex;
::FreeLibrary(m_SkinLibraresInstances[lPreviousLibIndex].Detach ());
}
}
m_iActiveSkin = BCG_DEFUALT_SKIN;
if (CBCGPVisualManager::CreateVisualManager (pSkin) == NULL)
{
ASSERT(FALSE);
return FALSE;
}
m_iActiveSkin = iSkin;
if (g_pWorkspace != NULL)
{
g_pWorkspace->OnSelectSkin ();
}
return TRUE;
}
//**********************************************************************************
BOOL CBCGPSkinManager::ShowSelectSkinDlg ()
{
CBCGPLocalResource localRes;
CBCGPSelectSkinDlg dlg;
return dlg.DoModal () == IDOK;
}
//**********************************************************************************
BOOL CBCGPSkinLibrary::Init (HINSTANCE hInstance)
{
if (hInstance == NULL)
{
return FALSE;
}
if ((m_pfGetSkinVersion =
(GETBCGSKINVERSION)::GetProcAddress(hInstance, "BCGCBProGetSkinVersion")) == NULL)
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinVersion proc\n");
return FALSE;
}
if ((m_pfIsUNICODE =
(ISUNICODE)::GetProcAddress(hInstance, "BCGCBProIsUNICODE")) == NULL)
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProIsUNICODE proc\n");
}
if ((m_pfGetSkinCount =
::GetProcAddress(hInstance, "BCGCBProGetSkinCount")) == NULL)
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinCount proc\n");
return FALSE;
}
if ((m_pfGetSkinName =
(GETBCGSKINNAME)::GetProcAddress(hInstance, "BCGCBProGetSkinName")) == NULL )
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinName proc\n");
return FALSE;
}
if ((m_pfGetSkinAuthor =
(GETBCGSKINNAME)::GetProcAddress(hInstance, "BCGCBProGetSkinAuthor")) == NULL )
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinAuthor proc\n");
return FALSE;
}
if ((m_pfGetSkinAuthorURL =
(GETBCGSKINNAME)::GetProcAddress(hInstance, "BCGCBProGetSkinAuthorURL")) == NULL )
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinAuthorURL proc\n");
return FALSE;
}
if ((m_pfGetSkinAuthorMail =
(GETBCGSKINNAME)::GetProcAddress(hInstance, "BCGCBProGetSkinAuthorMail")) == NULL )
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinAuthorMail proc\n");
return FALSE;
}
if ((m_pfGetSkin =
(GETBCGSKIN)::GetProcAddress(hInstance, "BCGCBProGetSkinClass")) == NULL)
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProGetSkinClass proc\n");
return FALSE;
}
if ((m_pfSkinPreview =
(BCGPREVIEWSKIN)::GetProcAddress(hInstance, "BCGCBProPreviewSkin")) == NULL)
{
TRACE0("CBCGPSkinLibrary::Init: Can't find BCGCBProPreviewSkin proc\n");
return FALSE;
}
m_hInstance = hInstance;
return TRUE;
}
//**********************************************************************************
void CBCGPSkinManager::ScanSkinsLocation ()
{
if (m_strSkinsDirectory.IsEmpty ())
{
return;
}
// Save infor about active skin:
CString strCurrentLib;
CString strCurrentSkin;
BOOL bIsDefaultSkin = m_iActiveSkin == BCG_DEFUALT_SKIN;
if (!bIsDefaultSkin)
{
strCurrentLib = m_Skins [m_iActiveSkin].m_strLibraryPath;
strCurrentSkin = m_Skins [m_iActiveSkin].m_strSkinName;
SetActiveSkin (BCG_DEFUALT_SKIN);
}
RemoveAllSkins ();
RenameTempLibs ();
CString strFindCriteria = m_strSkinsDirectory + DLL_FILE_MASK;
CFileFind find;
BOOL bResult = find.FindFile (strFindCriteria);
while (bResult)
{
bResult = find.FindNextFile ();
CString strFileName = find.GetFilePath ();
AddSkinLibrary (strFileName, FALSE);
}
// Restore active skin:
if (!bIsDefaultSkin)
{
for (int iIndex = 0; iIndex < m_Skins.GetSize (); iIndex++)
{
if (m_Skins [iIndex].m_strLibraryPath == strCurrentLib &&
m_Skins [iIndex].m_strSkinName == strCurrentSkin)
{
SetActiveSkin (iIndex);
break;
}
}
}
}
//**********************************************************************************
void CBCGPSkinManager::LoadAllSkins ()
{
RenameTempLibs ();
for (int i = 0; i < m_Skins.GetSize (); i++)
{
CBCGPSkinEntry& skinEntry = m_Skins [i];
int iLibIndex = skinEntry.m_iLibraryIndex;
CString strLibPath = skinEntry.m_strLibraryPath;
CBCGPSkinLibrary& skinLibrary = m_SkinLibraresInstances [iLibIndex];
if (skinLibrary.GetInstance () != NULL)
{
continue;
}
HINSTANCE hInstance = ::LoadLibrary (skinEntry.m_strLibraryPath);
if (!skinLibrary.Init (hInstance))
{
ASSERT(FALSE);
continue;
}
}
}
//**********************************************************************************
void CBCGPSkinManager::UnLoadAllSkins ()
{
CString strCurrentLib;
if (m_iActiveSkin != BCG_DEFUALT_SKIN)
{
strCurrentLib = m_Skins [m_iActiveSkin].m_strLibraryPath;
}
for (int i = 0; i < m_Skins.GetSize (); i++)
{
CBCGPSkinEntry& skinEntry = m_Skins [i];
int iLibIndex = skinEntry.m_iLibraryIndex;
CString strLibPath = skinEntry.m_strLibraryPath;
if (strCurrentLib == strLibPath)
{
continue;
}
CBCGPSkinLibrary& skinLibrary = m_SkinLibraresInstances [iLibIndex];
if (skinLibrary.GetInstance () == NULL)
{
continue;
}
::FreeLibrary(skinLibrary.Detach ());
}
}
//**********************************************************************************
void CBCGPSkinManager::RemoveAllSkins ()
{
m_Skins.RemoveAll ();
for (int i = 0; i < m_SkinLibraresInstances.GetSize (); i++)
{
::FreeLibrary(m_SkinLibraresInstances[i].GetInstance ());
}
m_SkinLibraresInstances.RemoveAll ();
}
//***********************************************************************************
void CBCGPSkinManager::EnableSkinsDownload ( LPCTSTR lpszURL,
LPCTSTR lpszUserName,
LPCTSTR lpszPassword,
LPCTSTR lpszDownloadDLLName)
{
m_strSkinsURL = (lpszURL == NULL) ? _T("") : lpszURL;
#ifdef _UNICODE
m_strDownloadDllName = (lpszDownloadDLLName == NULL) ?
_T("BCGSkinDownloaderU.dll") : lpszDownloadDLLName;
#else
m_strDownloadDllName = (lpszDownloadDLLName == NULL) ?
_T("BCGSkinDownloader.dll") : lpszDownloadDLLName;
#endif
m_strUserName = (lpszUserName == NULL) ? _T("") : lpszUserName;
m_strUserPassword = (lpszPassword == NULL) ? _T("") : lpszPassword;
}
//***********************************************************************************
BOOL CBCGPSkinManager::DownloadSkins ()
{
CWaitCursor wait;
HINSTANCE hInstDLL = ::LoadLibrary (m_strDownloadDllName);
if (hInstDLL == NULL)
{
CBCGPLocalResource localRes;
CString strError;
strError.Format (IDS_BCGBARRES_CANT_LOAD_DLL_FMT, m_strDownloadDllName);
AfxMessageBox (strError);
return FALSE;
}
BOOL bRes = FALSE;
#ifdef _UNICODE
BOOL bIsUnicode = TRUE;
#else
BOOL bIsUnicode = FALSE;
#endif
LPCSTR lpszLoadSkinsFunc3 = "BCGCBDownloadSkins3";
LPCSTR lpszLoadSkinsFunc2 = "BCGCBDownloadSkins2";
LPCSTR lpszLoadSkinsFunc = "BCGCBDownloadSkins";
BCGCBDOWNLOADSKINS3 pfDownloadSkins3 =
(BCGCBDOWNLOADSKINS3)::GetProcAddress (hInstDLL, lpszLoadSkinsFunc3);
if (pfDownloadSkins3 != NULL)
{
bRes = pfDownloadSkins3 (m_strSkinsURL, m_strUserName, m_strUserPassword,
m_strSkinsDirectory, _BCGCBPRO_VERSION_MAJOR, _BCGCBPRO_VERSION_MINOR, bIsUnicode,
1 /* PE */);
}
else
{
BCGCBDOWNLOADSKINS2 pfDownloadSkins2 =
(BCGCBDOWNLOADSKINS2)::GetProcAddress (hInstDLL, lpszLoadSkinsFunc2);
if (pfDownloadSkins2 != NULL)
{
bRes = pfDownloadSkins2 (m_strSkinsURL, m_strUserName, m_strUserPassword,
m_strSkinsDirectory, _BCGCBPRO_VERSION_MAJOR, _BCGCBPRO_VERSION_MINOR, bIsUnicode);
}
else
{
BCGCBDOWNLOADSKINS pfDownloadSkins =
(BCGCBDOWNLOADSKINS)::GetProcAddress (hInstDLL, lpszLoadSkinsFunc);
if (pfDownloadSkins == NULL)
{
CBCGPLocalResource localRes;
CString strError;
strError.Format (IDS_BCGBARRES_CANNT_FIND_ENTRY,
m_strDownloadDllName, _T("BCGCBDownloadSkins"));
AfxMessageBox (strError);
::FreeLibrary(hInstDLL);
return FALSE;
}
bRes = pfDownloadSkins (m_strSkinsURL, m_strUserName, m_strUserPassword,
m_strSkinsDirectory, _BCGCBPRO_VERSION_MAJOR, _BCGCBPRO_VERSION_MINOR);
}
}
wait.Restore ();
if (GetWorkspace () != NULL)
{
GetWorkspace()->OnAfterDownloadSkins (m_strSkinsDirectory);
}
::FreeLibrary(hInstDLL);
return bRes;
}
//**********************************************************************************
BOOL CBCGPSkinManager::RenameTempLibs ()
{
//---------------------------------------------
// We need to rename all temporary (downloaded)
// skin DLL to the actual names:
//---------------------------------------------
if (m_strSkinsDirectory.IsEmpty ())
{
return TRUE;
}
CString strFindCriteria = m_strSkinsDirectory + TMP_FILE_MASK;
CFileFind find;
BOOL bResult = find.FindFile (strFindCriteria);
while (bResult)
{
bResult = find.FindNextFile ();
CString strNameSkin = find.GetFilePath ();
TCHAR szNameDLL [_MAX_PATH];
TCHAR drive [_MAX_DRIVE];
TCHAR dir [_MAX_DIR];
TCHAR fname [_MAX_FNAME];
TCHAR ext [_MAX_EXT];
_tsplitpath (strNameSkin, drive, dir, fname, ext);
_tmakepath (szNameDLL, drive, dir, fname, _T("dll"));
if (_taccess (szNameDLL, 0) != -1)
{
// The previous version is already exist, delete it
_tremove (szNameDLL);
}
_trename (strNameSkin, szNameDLL);
}
return TRUE;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -