📄 pluginlist.cpp
字号:
////////////////////////////////////////////////////////////////////////////////
// pluginlist.cpp : implementation of the CPlugInList class
// Author: Saji Varkey (SCV)
// $Header: /USB/Util/EzMr/pluginlist.cpp 5 8/08/00 2:26p Tpm $
// Copyright (c) 2000 Cypress Semiconductor. May not be reproduced without permission.
// See the EzUsb Developer's Kit license agreement for more details.
////////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
//#include "galaxy.h"
#include "pluginlist.h"
#include "plugintool.h"
//#include "tools.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
static const CString PLUGIN_TOOLS_BASE = "SOFTWARE\\Cypress\\common\\Plugins";
static const CString MENU_NAME = "MenuName";
static const CString EXE_PATH = "ExePath";
static const CString INIT_DIR = "InitialDirectory";
static const CString DEF_ARGS = "DefArguments";
//...........................................................................................
//
// DESCRIPTION:
// Constructor
//
//...........................................................................................
CPlugInList::CPlugInList( int maxTools /* = 25*/ )
{
m_maxTools = maxTools;
}
//.........................................................................................
//
// DESCRIPTION:
// Destructor
//
// RETURN:
//
//.........................................................................................
CPlugInList::~CPlugInList()
{
DeleteAll(); // delete all the tools
}
//.........................................................................................
//
// DESCRIPTION:
// This function deletes all the tools stored.
//
// RETURN:
// void
//.........................................................................................
void CPlugInList::DeleteAll()
{
int nCount = m_plugInToolsArray.GetSize(); // get count
for ( int i = nCount - 1; i > -1; i-- )
{
delete (CPlugInTool*)m_plugInToolsArray[ i ];
}
m_plugInToolsArray.RemoveAll();
}
//.........................................................................................
//
// DESCRIPTION:
// This function gets all the plug-in tools from the registry.
//
// RETURN:
// void
//.........................................................................................
void CPlugInList::GetPluginToolsFromReg()
{
DWORD dwCount = 0;
CString strTemp;
CString strTemp2;
CStringArray strArray;
DeleteAll();
CHAR RegPath[MAX_PATH] = "Software\\Cypress\\common\\Plugins";
HKEY hKey;
HKEY hKeyRoot = HKEY_LOCAL_MACHINE;
HKEY hKey2;
HKEY hKeyRoot2 = HKEY_LOCAL_MACHINE;
DWORD retCodeLoop;
DWORD retCode;
CHAR DevPath[MAX_PATH] = "";
CHAR PlugInPath[MAX_PATH] = "";
retCode = RegOpenKeyEx (hKeyRoot,
RegPath,
0,
KEY_ENUMERATE_SUB_KEYS |
KEY_EXECUTE |
KEY_QUERY_VALUE,
&hKey);
if (retCode == ERROR_SUCCESS)
{
int dwIndex;
for(dwIndex=0, retCodeLoop = ERROR_SUCCESS; retCodeLoop == ERROR_SUCCESS; dwIndex++)
{ // enumerate subkeys
TCHAR szSubkey[MAX_PATH];
DWORD cbSubkeySize = MAX_PATH;
retCodeLoop = RegEnumKeyEx( hKey, dwIndex, szSubkey, &cbSubkeySize,
0, 0, 0, 0 );
if(retCodeLoop != (DWORD)ERROR_SUCCESS)
break;
sprintf(PlugInPath, "%s\\%s", RegPath, szSubkey);
TRACE("Found Plug-in:%s\n",PlugInPath);
retCode = RegOpenKeyEx (hKeyRoot2,
PlugInPath,
0,
KEY_ENUMERATE_SUB_KEYS |
KEY_EXECUTE |
KEY_QUERY_VALUE,
&hKey2);
if (retCode == ERROR_SUCCESS)
{ // Get the 4 Parameters
CString strReturnName; // menu name
CString strReturnPath; // exe. path
CString strReturnInitdir; // init. dir
CString strReturnDefArg; // default arguments
DWORD dwType=REG_SZ;// buffer for value type
BYTE bData[MAX_PATH]; // data buffer
DWORD cbData=MAX_PATH; // data buffer size
retCode = RegQueryValueEx(
hKey2, // handle to key to query
MENU_NAME, // address of name of value to query
0, // reserved
&dwType, // address of buffer for value type
&bData[0], // address of data buffer
&cbData // address of data buffer size
);
if(retCode == ERROR_SUCCESS)
{
TCHAR PlugInKey[MAX_PATH];
sprintf(PlugInKey, "%s: %s",
MENU_NAME, bData);
TRACE("Got PlugInKey:%s \n", PlugInKey);
strReturnName = bData; // menu name
}
cbData=MAX_PATH; // data buffer size
retCode = RegQueryValueEx(
hKey2, // handle to key to query
EXE_PATH, // address of name of value to query
0, // reserved
&dwType, // address of buffer for value type
&bData[0], // address of data buffer
&cbData // address of data buffer size
);
if(retCode == ERROR_SUCCESS)
{
TCHAR PlugInKey[MAX_PATH];
sprintf(PlugInKey, "%s: %s",
EXE_PATH, bData);
TRACE("Got PlugInKey:%s \n", PlugInKey);
strReturnPath = bData; // menu name
}
cbData=MAX_PATH; // data buffer size
retCode = RegQueryValueEx(
hKey2, // handle to key to query
INIT_DIR, // address of name of value to query
0, // reserved
&dwType, // address of buffer for value type
&bData[0], // address of data buffer
&cbData // address of data buffer size
);
if(retCode == ERROR_SUCCESS)
{
TCHAR PlugInKey[MAX_PATH];
sprintf(PlugInKey, "%s: %s",
INIT_DIR, bData);
TRACE("Got PlugInKey:%s \n", PlugInKey);
strReturnInitdir = bData; // menu name
}
cbData=MAX_PATH; // data buffer size
retCode = RegQueryValueEx(
hKey2, // handle to key to query
DEF_ARGS, // address of name of value to query
0, // reserved
&dwType, // address of buffer for value type
&bData[0], // address of data buffer
&cbData // address of data buffer size
);
if(retCode == ERROR_SUCCESS)
{
TCHAR PlugInKey[MAX_PATH];
sprintf(PlugInKey, "%s: %s",
DEF_ARGS, bData);
TRACE("Got PlugInKey:%s \n", PlugInKey);
strReturnDefArg = bData; // menu name
}
if(strReturnName != "EZ-USB Control Panel")
{
CPlugInTool *tool1 = new CPlugInTool( strReturnName, strReturnPath,
strReturnInitdir, strReturnDefArg );
m_plugInToolsArray.Add( tool1 ); // add tool to the array
}
}
RegCloseKey (hKey2); // Close the key handle.
}
}
}
//.........................................................................................
//
// DESCRIPTION:
// Call this function, in the UpdateUI method, to update the menu with
// names of the plug-in tools.
//
// RETURN:
// void
//.........................................................................................
void CPlugInList::UpdateMenu( CCmdUI* pCmdUI )
{
// retrive all tools from the registry
//
GetPluginToolsFromReg();
int nSize = m_plugInToolsArray.GetSize();
CMenu* pMenu = pCmdUI->m_pMenu;
if (m_strOriginal.IsEmpty() && pMenu != NULL) // store the default string
{
pMenu->GetMenuString(pCmdUI->m_nID, m_strOriginal, MF_BYCOMMAND);
}
if ( !nSize ) // no plug-in tools?
{
// Restore the original string and disable the menu
//
if (!m_strOriginal.IsEmpty())
{
pCmdUI->SetText(m_strOriginal);
for (int nCount = 1; nCount < m_maxTools; nCount++) // delete everything except the first
{
pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID + nCount, MF_BYCOMMAND);
}
}
pCmdUI->Enable(FALSE);
return;
}
if ( pCmdUI->m_pMenu == NULL ) // Is Valid menu?
{
return;
}
for ( int nCount = 0; nCount < m_maxTools; nCount++ ) // delete all existing menu items
{
pCmdUI->m_pMenu->DeleteMenu(pCmdUI->m_nID + nCount, MF_BYCOMMAND);
}
for (nCount = 0; nCount < nSize; nCount++)
{
CString strTemp;
CString strName;
// double up any '&' characters so they are not underlined
//
strName = ((CPlugInTool*)m_plugInToolsArray[nCount])->GetMenuName();
LPCTSTR lpszSrc = strName;
LPTSTR lpszDest = strTemp.GetBuffer(strName.GetLength()*2);
while (*lpszSrc != 0)
{
if (*lpszSrc == '&')
{
*lpszDest++ = '&';
}
if (_istlead(*lpszSrc))
{
*lpszDest++ = *lpszSrc++;
}
*lpszDest++ = *lpszSrc++;
}
*lpszDest = 0;
strTemp.ReleaseBuffer();
// insert mnemonic + the file name
//
TCHAR buf[10];
wsprintf(buf, _T("&%d "), ( nCount + 1 ) );
pCmdUI->m_pMenu->InsertMenu(pCmdUI->m_nIndex++,
MF_STRING | MF_BYPOSITION, pCmdUI->m_nID++,
CString(buf) + strTemp);
}
// update end menu count
//
pCmdUI->m_nIndex--; // point to last menu added
pCmdUI->m_nIndexMax = pCmdUI->m_pMenu->GetMenuItemCount();
pCmdUI->m_bEnableChanged = TRUE; // all the added items are enabled
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -