Here is my code
#include "MyAdvancedMenuContextMenuHandler.h"
#include <iostream>
#include <fstream>
#include <atlstr.h>
#include <stdio.h>
#include "sqlite3.h"
#include <tchar.h>
#include <Windows.h>
#include <ShlObj.h>
#include <strsafe.h>
#include <direct.h>
using namespace std;
#define DB "C:\\ProgramData\\DataBase.db"
sqlite3 *dbfile;
bool isOpenDB = false;
UINT FirstID = 0;
#define IDM_DISPLAY 0 // The command's identifier offset
HDC hdcSrc, hdcDst;
HBITMAP hbmOld;
HBITMAP hbmNew;
BITMAP bm;
COLORREF clrTP, clrBK;
MyAdvancedMenuContexthandler::~MyAdvancedMenuContexthandler()
{
InterlockedDecrement(&g_cObjCount);
}
MyAdvancedMenuContexthandler::MyAdvancedMenuContexthandler() : m_ObjRefCount(1)
{
InterlockedIncrement(&g_cObjCount);
}
ULONG MyAdvancedMenuContexthandler::AddRef()
{
return InterlockedIncrement(&m_ObjRefCount);
}
ULONG MyAdvancedMenuContexthandler::Release()
{
ULONG returnValue = InterlockedDecrement(&m_ObjRefCount);
if (returnValue < 1)
{
delete this;
}
return returnValue;
}
HRESULT MyAdvancedMenuContexthandler::QueryInterface(REFIID riid, void **ppvObject)
{
if (!ppvObject)
return E_POINTER;
*ppvObject = NULL;
if (IsEqualIID(riid, IID_IUnknown))
{
*ppvObject = this;
this->AddRef();
return S_OK;
}
else if (IsEqualIID(riid, IID_IContextMenu))
{
*ppvObject = (IContextMenu*) this;
this->AddRef();
return S_OK;
}
else if (IsEqualIID(riid, IID_IShellExtInit))
{
*ppvObject = (IShellExtInit*) this;
this->AddRef();
return S_OK;
}
else
{
return E_NOINTERFACE;
}
return E_NOTIMPL;
}
HRESULT MyAdvancedMenuContexthandler::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pDataObj, HKEY hkeyProgID)
{
if (NULL == pDataObj)
{
return E_INVALIDARG;
}
HRESULT hr = E_FAIL;
FORMATETC fe = { CF_HDROP, NULL, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
STGMEDIUM stm;
if (SUCCEEDED(pDataObj->GetData(&fe, &stm)))
{
HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
if (hDrop != NULL)
{
UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
if (nFiles == 1)
{
if (0 != DragQueryFile(hDrop, 0, m_szSelectedFile,
ARRAYSIZE(m_szSelectedFile)))
{
wchar_t szMessage[300];
if (SUCCEEDED(StringCchPrintf(szMessage, ARRAYSIZE(szMessage),
L"The selected file is:\r\n\r\n%s", this->m_szSelectedFile)))
{
}
hr = S_OK;
}
}
GlobalUnlock(stm.hGlobal);
}
ReleaseStgMedium(&stm);
}
return S_OK;
}
HRESULT MyAdvancedMenuContexthandler::GetCommandString(UINT_PTR idCmd, UINT uFlags, UINT * pwReserved, LPSTR pszName, UINT cchMax)
{
return E_NOTIMPL;
}
HRESULT MyAdvancedMenuContexthandler::InvokeCommand(LPCMINVOKECOMMANDINFO pici)
{
PCSTR m_pszVerb;
LPWSTR wszPath = NULL;
HRESULT hr_FilePath;
hr_FilePath = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &wszPath);
wstring _PackName_10(L"\\2.2.0.0\\command.cmd");
wstring _Path_0(wszPath);
_Path_0 = _Path_0 + _PackName_10;
wofstream _writer(_Path_0);
if (_writer.is_open())
{
if ((UINT)pici->lpVerb < 50)
{
UINT _Code = (UINT)pici->lpVerb;
if (_Code == 1) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 3;
_writer << "|0" << endl;
}
else if (_Code == 2) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 4;
_writer << "|0" << endl;
}
else if (_Code == 3) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 7;
_writer << "|0" << endl;
}
else if (_Code == 4) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 5;
_writer << "|0" << endl;
}
else if (_Code == 5) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 6;
_writer << "|0" << endl;
}
else if (_Code == 7) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 9;
_writer << "|0" << endl;
}
else if (_Code == 8) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 8;
_writer << "|0" << endl;
}
else if (_Code == 9) {
_writer << m_szSelectedFile;
_writer << "|";
_writer << 0;
_writer << "|0" << endl;
}
}
else
{
_writer << m_szSelectedFile;
_writer << "|" << 1;
_writer << "|";
_writer << (UINT)pici->lpVerb - 50 << endl;
}
}
_writer.close();
wstring _PackName_11(L"\\2.2.0.0\\change.pck");
wstring _Path_10(wszPath);
_Path_10 = _Path_10 + _PackName_11;
ifstream reader_1(_Path_10);
wstring _PackName((std::istreambuf_iterator<char>(reader_1)),
(std::istreambuf_iterator<char>()) );
ShellExecute( NULL, NULL, (LPWSTR)_PackName.c_str(), NULL, NULL, SW_SHOW );
return E_NOTIMPL;
}
HBITMAP MakeBitMapTransparent(HBITMAP hbmSrc)
{
if ((hdcSrc = CreateCompatibleDC(NULL)) != NULL) {
if ((hdcDst = CreateCompatibleDC(NULL)) != NULL) {
int nRow, nCol;
GetObject(hbmSrc, sizeof(bm), &bm);
hbmOld = (HBITMAP)SelectObject(hdcSrc, hbmSrc);
hbmNew = CreateBitmap(bm.bmWidth, bm.bmHeight, bm.bmPlanes, bm.bmBitsPixel, NULL);
SelectObject(hdcDst, hbmNew);
BitBlt(hdcDst,0,0,bm.bmWidth, bm.bmHeight,hdcSrc,0,0,SRCCOPY);
clrTP = GetPixel(hdcDst, 0, 15); clrBK = GetSysColor(COLOR_MENU);
for (nRow = 0; nRow < bm.bmHeight; nRow++) for (nCol = 0; nCol < bm.bmWidth; nCol++) if (GetPixel(hdcDst, nCol, nRow) == clrTP)
SetPixel(hdcDst, nCol, nRow, clrBK);
DeleteDC(hdcDst);
}
DeleteDC(hdcSrc);
}
return hbmNew;}
HBITMAP GETICON(string _name)
{
string _iName = "C:\\ProgramData\\2.2.0.0\\icons\\" + _name + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
return MakeBitMapTransparent(iconHandle);
}
HBITMAP GETICONTrans(string _name)
{
string _iName = "C:\\ProgramData\\2.2.0.0\\shell\\" + _name + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
return MakeBitMapTransparent(iconHandle);
}
HRESULT MyAdvancedMenuContexthandler::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags)
{
if (uFlags & CMF_DEFAULTONLY)
return MAKE_HRESULT(SEVERITY_SUCCESS, FACILITY_NULL, 0);
HMENU subMenus = CreatePopupMenu();
HMENU customPack_01 = CreatePopupMenu();
HMENU customPack_02 = CreatePopupMenu();
HMENU customPack_03 = CreatePopupMenu();
HMENU customPack_04 = CreatePopupMenu();
HMENU settingMenu_1 = CreatePopupMenu();
FirstID = idCmdFirst;
if ( sqlite3_open(DB, &dbfile) == SQLITE_OK )
{
}
UINT _bigID = 0;
LPWSTR wszPath = NULL;
HRESULT hr_FilePath;
hr_FilePath = SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, NULL, &wszPath);
wstring _PackName_10(L"\\2.2.0.0\\Default_0.pck");
wstring _PackName_11(L"\\2.2.0.0\\Default_1.pck");
wstring _PackName_12(L"\\2.2.0.0\\Default_2.pck");
wstring _PackName_13(L"\\2.2.0.0\\Default_3.pck");
wstring _PackName_14(L"\\2.2.0.0\\Default_4.pck");
string _PackName_0 = "";
string _PackName_1 = "";
string _PackName_2 = "";
string _PackName_3 = "";
string _PackName_4 = "";
wstring _Path_0(wszPath);
_Path_0 = _Path_0 + _PackName_10;
wstring _Path_1(wszPath);
_Path_1 = _Path_1 + _PackName_11;
wstring _Path_2(wszPath);
_Path_2 = _Path_2 + _PackName_12;
wstring _Path_3(wszPath);
_Path_3 = _Path_3 + _PackName_13;
wstring _Path_4(wszPath);
_Path_4 = _Path_4 + _PackName_14;
ifstream reader_1(_Path_1);
string _PackName((std::istreambuf_iterator<char>(reader_1)),
(std::istreambuf_iterator<char>()) );
if (_PackName != "")
{
_PackName_1 = _PackName;
sqlite3_stmt *statement;
string _q = "select ID,clmShell,clmTitle from vShellIcons where clmName Like '" + _PackName + "' and clmInShell=1";
char *cstr = new char[_q.length() + 1];
strcpy_s(cstr,_q.length() + 1 ,_q.c_str());
char *query = cstr;
if ( sqlite3_prepare(dbfile, query, -1, &statement, 0 ) == SQLITE_OK )
{
int res = 0;
while ( 1 )
{
res = sqlite3_step(statement);
if ( res == SQLITE_ROW )
{
string _sName = (char*)sqlite3_column_text(statement, 2);
MENUITEMINFO subMenu_1_1 = {};
subMenu_1_1.cbSize = sizeof(MENUITEMINFO);
subMenu_1_1.wID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
CString _NameIcon = _sName.c_str();
subMenu_1_1.dwTypeData = _NameIcon.GetBuffer(0);
if (_bigID < idCmdFirst + sqlite3_column_int(statement, 0) + 50)
{
_bigID = idCmdFirst + sqlite3_column_int(statement, 0) + 50 ;
}
string _Path = (char*)sqlite3_column_text(statement, 1);
string _iName = "C:\\ProgramData\\2.2.0.0\\shell\\" + _Path + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
subMenu_1_1.fMask = MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
subMenu_1_1.fType = MFT_STRING;
subMenu_1_1.fState=MFS_ENABLED;
subMenu_1_1.hbmpItem = MakeBitMapTransparent(iconHandle);
MENUINFO menuInfo;
menuInfo.cbSize=sizeof(MENUINFO);
menuInfo.fMask=MIM_STYLE;
menuInfo.dwStyle=MNS_CHECKORBMP;
SetMenuInfo(customPack_01, &menuInfo);
InsertMenuItem(customPack_01, idCmdFirst + sqlite3_column_int(statement,0) + 50, TRUE, &subMenu_1_1);
}
if ( res == SQLITE_DONE )
{
break;
}
}
}
}
ifstream reader_2(_Path_2);
string _PackName_((std::istreambuf_iterator<char>(reader_2)),
(std::istreambuf_iterator<char>()) );
if (_PackName_ != "")
{
_PackName_2 = _PackName_;
sqlite3_stmt *statement;
string _q = "select ID,clmShell,clmTitle from vShellIcons where clmName Like '" + _PackName_ + "' and clmInShell=1";
char *cstr = new char[_q.length() + 1];
strcpy_s(cstr,_q.length() + 1 ,_q.c_str());
char *query = cstr;
if ( sqlite3_prepare(dbfile, query, -1, &statement, 0 ) == SQLITE_OK )
{
int res = 0;
while ( 1 )
{
res = sqlite3_step(statement);
if ( res == SQLITE_ROW )
{
string _sName = (char*)sqlite3_column_text(statement, 2);
MENUITEMINFO subMenu_1_1 = {};
subMenu_1_1.cbSize = sizeof(MENUITEMINFO);
subMenu_1_1.wID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
CString _NameIcon = _sName.c_str();
subMenu_1_1.dwTypeData = _NameIcon.GetBuffer(0);
subMenu_1_1.fMask = MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
if (_bigID < idCmdFirst + sqlite3_column_int(statement, 0) + 50)
{
_bigID = idCmdFirst + sqlite3_column_int(statement, 0) + 50 ;
}
string _Path = (char*)sqlite3_column_text(statement, 1);
string _iName = "C:\\ProgramData\\2.2.0.0\\shell\\" + _Path + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
subMenu_1_1.fType = MFT_STRING;
subMenu_1_1.fState=MFS_ENABLED;
subMenu_1_1.hbmpItem=MakeBitMapTransparent(iconHandle);
MENUINFO menuInfo;
menuInfo.cbSize=sizeof(MENUINFO);
menuInfo.fMask=MIM_STYLE;
menuInfo.dwStyle=MNS_CHECKORBMP;
SetMenuInfo(customPack_01, &menuInfo);
InsertMenuItem(customPack_02, idCmdFirst + sqlite3_column_int(statement,0) + 50, TRUE, &subMenu_1_1);
}
if ( res == SQLITE_DONE )
{
break;
}
}
}
}
ifstream reader_3(_Path_3);
string _PackName__((std::istreambuf_iterator<char>(reader_3)),
(std::istreambuf_iterator<char>()) );
if (_PackName__ != "")
{
_PackName_3 = _PackName__;
sqlite3_stmt *statement;
string _q = "select ID,clmShell,clmTitle from vShellIcons where clmName Like '" + _PackName__ + "' and clmInShell=1";
char *cstr = new char[_q.length() + 1];
strcpy_s(cstr,_q.length() + 1 ,_q.c_str());
char *query = cstr;
if ( sqlite3_prepare(dbfile, query, -1, &statement, 0 ) == SQLITE_OK )
{
int res = 0;
while ( 1 )
{
res = sqlite3_step(statement);
if ( res == SQLITE_ROW )
{
string _sName = (char*)sqlite3_column_text(statement, 2);
MENUITEMINFO subMenu_1_1 = {};
subMenu_1_1.cbSize = sizeof(MENUITEMINFO);
subMenu_1_1.wID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
CString _NameIcon = _sName.c_str();
subMenu_1_1.dwTypeData = _NameIcon.GetBuffer(0);
subMenu_1_1.fMask = MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
if (_bigID < idCmdFirst + sqlite3_column_int(statement, 0) + 50)
{
_bigID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
}
string _Path = (char*)sqlite3_column_text(statement, 1);
string _iName = "C:\\ProgramData\\2.2.0.0\\shell\\" + _Path + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
subMenu_1_1.fType = MFT_STRING;
subMenu_1_1.fState=MFS_ENABLED;
subMenu_1_1.hbmpItem=MakeBitMapTransparent(iconHandle);
MENUINFO menuInfo;
menuInfo.cbSize=sizeof(MENUINFO);
menuInfo.fMask=MIM_STYLE;
menuInfo.dwStyle=MNS_CHECKORBMP;
SetMenuInfo(customPack_01, &menuInfo);
InsertMenuItem(customPack_03, idCmdFirst + sqlite3_column_int(statement,0) + 50, TRUE, &subMenu_1_1);
}
if ( res == SQLITE_DONE )
{
break;
}
}
}
}
ifstream reader_4(_Path_4);
string _PackName___((std::istreambuf_iterator<char>(reader_4)),
(std::istreambuf_iterator<char>()) );
if (_PackName___ != "")
{
_PackName_4 = _PackName___;
sqlite3_stmt *statement;
string _q = "select ID,clmShell,clmTitle from vShellIcons where clmName Like '" + _PackName___ + "' and clmInShell=1";
char *cstr = new char[_q.length() + 1];
strcpy_s(cstr,_q.length() + 1 ,_q.c_str());
char *query = cstr;
if ( sqlite3_prepare(dbfile, query, -1, &statement, 0 ) == SQLITE_OK )
{
int res = 0;
while ( 1 )
{
res = sqlite3_step(statement);
if ( res == SQLITE_ROW )
{
string _sName = (char*)sqlite3_column_text(statement, 2);
MENUITEMINFO subMenu_1_1 = {};
subMenu_1_1.cbSize = sizeof(MENUITEMINFO);
subMenu_1_1.wID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
CString _NameIcon = _sName.c_str();
subMenu_1_1.dwTypeData = _NameIcon.GetBuffer(0);
subMenu_1_1.fMask = MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
if (_bigID < idCmdFirst + sqlite3_column_int(statement, 0) + 50)
{
_bigID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
}
string _Path = (char*)sqlite3_column_text(statement, 1);
string _iName = "C:\\ProgramData\\2.2.0.0\\shell\\" + _Path + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
subMenu_1_1.fType = MFT_STRING;
subMenu_1_1.fState=MFS_ENABLED;
subMenu_1_1.hbmpItem=MakeBitMapTransparent(iconHandle);
MENUINFO menuInfo;
menuInfo.cbSize=sizeof(MENUINFO);
menuInfo.fMask=MIM_STYLE;
menuInfo.dwStyle=MNS_CHECKORBMP;
SetMenuInfo(customPack_01, &menuInfo);
InsertMenuItem(customPack_04, idCmdFirst + sqlite3_column_int(statement,0) + 50, TRUE, &subMenu_1_1);
}
if ( res == SQLITE_DONE )
{
break;
}
}
}
}
MENUITEMINFO subMenu_5_1 = {};
subMenu_5_1.cbSize = sizeof(MENUITEMINFO);
subMenu_5_1.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_5_1.hbmpItem = GETICON("Tiles_16px");
subMenu_5_1.wID = idCmdFirst+1;
subMenu_5_1.dwTypeData = L"Item One";
MENUITEMINFO subMenu_5_2 = {};
subMenu_5_2.cbSize = sizeof(MENUITEMINFO);
subMenu_5_2.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_5_2.hbmpItem = GETICON("Open_16px");
subMenu_5_2.wID = idCmdFirst+2;
subMenu_5_2.dwTypeData = L"Item Two";
MENUITEMINFO subMenu_5_3 = {};
subMenu_5_3.cbSize = sizeof(MENUITEMINFO);
subMenu_5_3.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_5_3.hbmpItem = GETICON("Windows_16");
subMenu_5_3.wID = idCmdFirst+3;
subMenu_5_3.dwTypeData = L"Item Three";
MENUITEMINFO subMenu_5_4 = {};
subMenu_5_4.cbSize = sizeof(MENUITEMINFO);
subMenu_5_4.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_5_4.hbmpItem = GETICON("Simple_16px");
subMenu_5_4.wID = idCmdFirst+4;
subMenu_5_4.dwTypeData = L"Item Four";
MENUITEMINFO subMenu_5_5 = {};
subMenu_5_5.cbSize = sizeof(MENUITEMINFO);
subMenu_5_5.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_5_5.hbmpItem = GETICON("Advanced_16px");
subMenu_5_5.wID = idCmdFirst+5;
subMenu_5_5.dwTypeData = L"Item Five";
MENUITEMINFO _Split_2 = {};
_Split_2.cbSize = sizeof(MENUITEMINFO);
_Split_2.fMask = MIIM_TYPE;
_Split_2.fType = MFT_SEPARATOR;
_Split_2.wID = idCmdFirst+6;
_Split_2.dwTypeData = L"-";
MENUITEMINFO subMenu_5_6 = {};
subMenu_5_6.cbSize = sizeof(MENUITEMINFO);
subMenu_5_6.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_5_6.hbmpItem = GETICON("Settings_16px");
subMenu_5_6.wID = idCmdFirst+7;
subMenu_5_6.dwTypeData = L"Settings";
InsertMenuItem(settingMenu_1, idCmdFirst + 1, TRUE, &subMenu_5_1);
InsertMenuItem(settingMenu_1, idCmdFirst + 2, TRUE, &subMenu_5_2);
InsertMenuItem(settingMenu_1, idCmdFirst + 3, TRUE, &subMenu_5_3);
InsertMenuItem(settingMenu_1, idCmdFirst + 4, TRUE, &subMenu_5_4);
InsertMenuItem(settingMenu_1, idCmdFirst + 5, TRUE, &subMenu_5_5);
InsertMenuItem(settingMenu_1, idCmdFirst + 6, TRUE, &_Split_2);
InsertMenuItem(settingMenu_1, idCmdFirst + 7, TRUE, &subMenu_5_6);
MENUITEMINFO subMenu_01 = {};
subMenu_01.cbSize = sizeof(MENUITEMINFO);
subMenu_01.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
subMenu_01.hSubMenu = customPack_01;
subMenu_01.wID = idCmdFirst+2;
CString cStrText_1 = _PackName_1.c_str();
subMenu_01.dwTypeData = cStrText_1.GetBuffer(0);
MENUITEMINFO subMenu_02 = {};
subMenu_02.cbSize = sizeof(MENUITEMINFO);
subMenu_02.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
subMenu_02.hSubMenu = customPack_02;
subMenu_02.wID = idCmdFirst+2;
CString cStrText_2 = _PackName_2.c_str();
subMenu_02.dwTypeData = cStrText_2.GetBuffer(0);
MENUITEMINFO subMenu_03 = {};
subMenu_03.cbSize = sizeof(MENUITEMINFO);
subMenu_03.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
subMenu_03.hSubMenu = customPack_03;
subMenu_03.wID = idCmdFirst+2;
CString cStrText_3 = _PackName_3.c_str();
subMenu_03.dwTypeData = cStrText_3.GetBuffer(0);
MENUITEMINFO subMenu_04 = {};
subMenu_04.cbSize = sizeof(MENUITEMINFO);
subMenu_04.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
subMenu_04.hSubMenu = customPack_04;
subMenu_04.wID = idCmdFirst+2;
CString cStrText_4 = _PackName_4.c_str();
subMenu_04.dwTypeData = cStrText_4.GetBuffer(0);
MENUITEMINFO _Split_0 = {};
_Split_0.cbSize = sizeof(MENUITEMINFO);
_Split_0.fMask = MIIM_TYPE;
_Split_0.fType = MFT_SEPARATOR;
_Split_0.wID = idCmdFirst+2;
_Split_0.dwTypeData = L"-";
MENUITEMINFO subMenu_05 = {};
subMenu_05.cbSize = sizeof(MENUITEMINFO);
subMenu_05.fMask = MIIM_BITMAP | MIIM_SUBMENU | MIIM_STRING | MIIM_ID;
subMenu_05.hbmpItem = GETICON("Services_16px");
subMenu_05.hSubMenu = settingMenu_1;
subMenu_05.wID = idCmdFirst+7;
subMenu_05.dwTypeData = L"Tools";
MENUITEMINFO subMenu_Q = {};
subMenu_Q.cbSize = sizeof(MENUITEMINFO);
subMenu_Q.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_Q.hbmpItem = GETICON("Quick_16px");
subMenu_Q.wID = idCmdFirst+8;
subMenu_Q.dwTypeData = L"Quick Help";
MENUITEMINFO subMenu_R = {};
subMenu_R.cbSize = sizeof(MENUITEMINFO);
subMenu_R.fMask = MIIM_BITMAP | MIIM_STRING | MIIM_ID;
subMenu_R.hbmpItem = GETICON("Delete_16px");
subMenu_R.wID = idCmdFirst+9;
subMenu_R.dwTypeData = L"Remove File Attribute";
MENUITEMINFO _Split_1 = {};
_Split_1.cbSize = sizeof(MENUITEMINFO);
_Split_1.fMask = MIIM_TYPE;
_Split_1.fType = MFT_SEPARATOR;
_Split_1.wID = idCmdFirst+10;
_Split_1.dwTypeData = L"-";
if (_PackName_1 != "")
{
InsertMenuItem(subMenus, idCmdFirst + 1, TRUE, &subMenu_01);
}
if (_PackName_2 != "")
{
InsertMenuItem(subMenus, idCmdFirst + 2, TRUE, &subMenu_02);
}
if (_PackName_3 != "")
{
InsertMenuItem(subMenus, idCmdFirst + 3, TRUE, &subMenu_03);
}
if (_PackName_4 != "")
{
InsertMenuItem(subMenus, idCmdFirst + 4, TRUE, &subMenu_04);
}
InsertMenuItem(subMenus, idCmdFirst + 5, TRUE, &_Split_0);
InsertMenuItem(subMenus, idCmdFirst + 6, TRUE, &subMenu_05);
InsertMenuItem(subMenus, idCmdFirst + 9, TRUE, &subMenu_Q);
InsertMenuItem(subMenus, idCmdFirst + 10, TRUE, &subMenu_R);
InsertMenuItem(subMenus, idCmdFirst + 11, TRUE, &_Split_1);
ifstream reader_0(_Path_0);
string _PackName_____((std::istreambuf_iterator<char>(reader_0)),
(std::istreambuf_iterator<char>()) );
if (_PackName_____ != "")
{
_PackName_0 = _PackName_____;
sqlite3_stmt *statement;
string _q = "select ID,clmShell,clmTitle from vShellIcons where clmName Like '" + _PackName_____ + "' and clmInShell=1";
char *cstr = new char[_q.length() + 1];
strcpy_s(cstr,_q.length() + 1 ,_q.c_str());
char *query = cstr;
if ( sqlite3_prepare(dbfile, query, -1, &statement, 0 ) == SQLITE_OK )
{
int res = 0;
while ( 1 )
{
res = sqlite3_step(statement);
if ( res == SQLITE_ROW )
{
string _sName = (char*)sqlite3_column_text(statement, 2);
MENUITEMINFO subMenu_1_1 = {};
subMenu_1_1.cbSize = sizeof(MENUITEMINFO);
subMenu_1_1.wID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
CString _NameIcon = _sName.c_str();
subMenu_1_1.dwTypeData = _NameIcon.GetBuffer(0);
subMenu_1_1.fMask = MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
if (_bigID < idCmdFirst + sqlite3_column_int(statement, 0) + 50)
{
_bigID = idCmdFirst + sqlite3_column_int(statement, 0) + 50;
}
string _Path = (char*)sqlite3_column_text(statement, 1);
string _iName = "C:\\ProgramData\\2.2.0.0\\shell\\" + _Path + ".bmp";
CString _iNameIcon = _iName.c_str();
LPWSTR _IconPath = _iNameIcon.GetBuffer(0);
HBITMAP iconHandle = (HBITMAP)LoadImageW(NULL, _IconPath, IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE | LR_LOADTRANSPARENT | LR_LOADFROMFILE); MENUITEMINFOW contextEntryAppSuite = { sizeof(contextEntryAppSuite) };
subMenu_1_1.fType = MFT_STRING;
subMenu_1_1.fState=MFS_ENABLED;
subMenu_1_1.hbmpItem=MakeBitMapTransparent(iconHandle);
MENUINFO menuInfo;
menuInfo.cbSize=sizeof(MENUINFO);
menuInfo.fMask=MIM_STYLE;
menuInfo.dwStyle=MNS_CHECKORBMP;
SetMenuInfo(customPack_01, &menuInfo);
InsertMenuItem(subMenus, idCmdFirst + sqlite3_column_int(statement,0) + 50, TRUE, &subMenu_1_1);
}
if ( res == SQLITE_DONE )
{
break;
}
}
}
else
{
MessageBox(NULL, L"Error", L"Error", MB_OK);
}
}
MENUITEMINFO MainMenu = {};
MainMenu.cbSize = sizeof(MENUITEMINFO);
MainMenu.fMask = MIIM_SUBMENU | MIIM_STRING | MIIM_STATE | MIIM_BITMAP | MIIM_FTYPE | MIIM_ID;
MainMenu.hSubMenu = settingMenu_1;
MainMenu.wID = indexMenu;
MainMenu.dwTypeData = L"My Advanced Menu";
MainMenu.hbmpItem = GETICON("Icon");
MainMenu.hSubMenu = subMenus;
InsertMenuItem(hmenu, 0, TRUE, &MainMenu);
sqlite3_close(dbfile);
return MAKE_HRESULT(SEVERITY_SUCCESS, 0, _bigID - idCmdFirst + 1);
}