Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I wrote a shell extension using c++, but after performing right click after 30 times, windows menu goes black and I have to reset the explorer.exe
How can I prevent this issue, and also I have more than 60 Items in my shell menu.

What I have tried:

I wrote the shell menu based on Microsoft example and Still no success.

[Edit by Jochen Arndt: Code posted as solution and comment]
#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;

    // The pDataObj pointer contains the objects being acted upon. In this 
    // example, we get an HDROP handle for enumerating the selected files and 
    // folders.
    if (SUCCEEDED(pDataObj->GetData(&fe, &stm)))
    {
        // Get an HDROP handle.
        HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
        if (hDrop != NULL)
        {
            // Determine how many files are involved in this operation. This 
            // code sample displays the custom context menu item when only 
            // one file is selected. 
            UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
            if (nFiles == 1)
            {

                // Get the path of the file.
                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)))
						{
							//MessageBox(NULL, szMessage, L"CppShellExtContextMenuHandler", MB_OK);
						}
                    hr = S_OK;
                }
            }

            GlobalUnlock(stm.hGlobal);
        }

        ReleaseStgMedium(&stm);
    } 

    // If any value other than S_OK is returned from the method, the context 
    // menu item is not displayed.
    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)
{
	/*wchar_t szMessage[300];
	StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"The selected file is:\r\n\r\n%s", this->m_szSelectedFile);*/
	//MessageBox(NULL, m_szSelectedFile, L"CppShellExtContextMenuHandler", MB_OK);
	//system("notepad.exe");
	PCSTR m_pszVerb;
	//	StrCmpIA(pici->lpVerb, 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)
		{
			//MessageBox(NULL, (LPCWSTR)pici->lpVerb, L"Code", MB_OK);
			//MessageBox(NULL, (LPCWSTR)m_szSelectedFile, L"Code", MB_OK);

			UINT _Code = (UINT)pici->lpVerb;
			if (_Code == 1) //Icon Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 3;
				_writer << "|0" << endl;
			}
			else if (_Code == 2) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 4;
				_writer << "|0" << endl;
			}
			else if (_Code == 3) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 7;
				_writer << "|0" << endl;
			}
			else if (_Code == 4) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 5;
				_writer << "|0" << endl;
			}
			else if (_Code == 5) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 6;
				_writer << "|0" << endl;
			}
			else if (_Code == 7) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 9;
				_writer << "|0" << endl;
			}
			else if (_Code == 8) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 8;
				_writer << "|0" << endl;
			}
			else if (_Code == 9) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 0;
				_writer << "|0" << endl;
			}
		}
		else
		{
		_writer << m_szSelectedFile;
		_writer << "|" << 1;
		_writer << "|";
		_writer << (UINT)pici->lpVerb - 50 << endl;
		}
	}
	_writer.close();
	//LPWSTR wszPath_ = NULL;
	////SHGetKnownFolderPath(FOLDERID_, 0, NULL, &wszPath_);


	//char the_patha[256];
	//_getcwd(the_patha, 255);

	//size_t nSize1 = 1 + strlen(the_patha);

 //   LPWSTR wUserName = new WCHAR[nSize1];

 //   MultiByteToWideChar(CP_ACP, 0, the_patha, -1, wUserName, nSize1);

	///*LPWSTR _Base = NULL;
	//MultiByteToWideChar(CP_ACP, 0, the_patha, -1, _Base, 0);*/

	//MessageBox(NULL, wUserName, L"Test", MB_OK);
	//wstring _Path_44(wUserName);
	//_Path_44 = _Path_44 + L"\\Change\\ChangeIcon.exe";
	//ShellExecute( NULL, NULL, (LPWSTR)_Path_44.c_str(), NULL, NULL, SW_SHOW );
	
	/*std::wstring prefix (L"");
	wstring _Fol(m_szSelectedFile);
	if(_Fol.substr(0, prefix.size()) != prefix) {
		
	}*/

	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);
	// Get The Value
	wstring _PackName((std::istreambuf_iterator<char>(reader_1)),
			(std::istreambuf_iterator<char>()) );

	//MessageBox(NULL, (LPWSTR)_PackName.c_str(), L"", MB_OK);

	ShellExecute( NULL, NULL, (LPWSTR)_PackName.c_str(), NULL, NULL, SW_SHOW );
	//return S_OK;
	
	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);// Get color of first pixel at 0,0
			clrBK = GetSysColor(COLOR_MENU);// Get the current background color of the menu
			
			for (nRow = 0; nRow < bm.bmHeight; nRow++)// work our way through all the pixels changing their color
				for (nCol = 0; nCol < bm.bmWidth; nCol++)// when we hit our set transparency color.
					if (GetPixel(hdcDst, nCol, nRow) == clrTP)
						SetPixel(hdcDst, nCol, nRow, clrBK);
			
			DeleteDC(hdcDst);
		}
		DeleteDC(hdcSrc);
		
	}
	return hbmNew;// return our transformed bitmap.
}

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;

	// Read Selected Packs for the Menu
	
	//sqlite3_open(DB, &dbfile);

	if ( sqlite3_open(DB, &dbfile) == SQLITE_OK )
	{
		//MessageBox(NULL, L"Connected Successfully", L"Connection", MB_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);

	// Get The Value
	string _PackName((std::istreambuf_iterator<char>(reader_1)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName != "")
	{
		// Custom Pack One
		_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);

	// Get The Value
	string _PackName_((std::istreambuf_iterator<char>(reader_2)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName_ != "")
	{
		// Custom Pack One
		_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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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);

	// Get The Value
	string _PackName__((std::istreambuf_iterator<char>(reader_3)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName__ != "")
	{
		// Custom Pack One
		_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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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);

	// Get The Value
	string _PackName___((std::istreambuf_iterator<char>(reader_4)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName___ != "")
	{
		// Custom Pack One
		_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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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;
				}					
			}
		}
	}

	// Settings Menu
	
	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);

	// Final Menu Structure Pack 01
	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);
	// Final Menu Structure Pack 02
	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);
    // Final Menu Structure Pack 03
	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);
    // Final Menu Structure Pack 04
	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"-";



	// Final Menu Structure Tools Menu
	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);

	// Get The Value
	string _PackName_____((std::istreambuf_iterator<char>(reader_0)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName_____ != "")
	{
		// Custom Pack One
		_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());

		//CString _Mess = _q.c_str();
		//MessageBox(NULL, _Mess.GetBuffer(0), L"Error", MB_OK);

		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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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);

	/*InsertMenu (hmenu, indexMenu, MIIM_BITMAP | MF_BYPOSITION | MF_POPUP, 
                 (UINT_PTR) subMenus, L"My Advanced Menu");*/

	sqlite3_close(dbfile);
	return MAKE_HRESULT(SEVERITY_SUCCESS, 0, _bigID - idCmdFirst + 1);
}
Posted
Updated 2-Feb-18 3:23am
v2
Comments
Dave Kreskowiak 2-Feb-18 8:36am    
Need more detail. Is that 60 items you intended to be there or is your code constantly adding the same items over and over to the menu?

There are definitely bugs in your code, but, since we know absolutely nothing about your code, it's impossible to tell you what you're doing wrong.
CPallini 2-Feb-18 8:37am    
How could we possibly help you without having a look at the code? Well, we could say your code is buggy.

The black menu is an indication for a malfunctioning extension.

Because you did not show us any code, I can only give the advice to check your code.

You can for example comment most of the code showing only a dialog box upon activation of a menu command. Then check if the problem still occurs. If not, reactivate blocks of code until the problem arises again. Than you will know which code block is the source of the problem.

You should also always check if function calls succeed (usually by checking the return value). Not doing so and proceeding is a common source for such problems.

[EDIT: After code has been posted]
Quote:
Hi, I checked my codes and It happens when I Add Bitmaps to menu items. How to prevent this issue

You probably ran out of GDI resources (which is also indicated by happening not immediately).

In your GETICON() function you are calling MakeBitMapTransparent(iconHandle) which returns a new (converted) bitmap but you never delete the loaded bitmap. See
When you are finished using a bitmap, cursor, or icon you loaded without specifying the LR_SHARED flag, you can release its associated memory by calling one of the functions in the following table.

So you have to insert this at the end of MakeBitMapTransparent():
C++
DeleteObject(hbmSrc);
[/EDIT]
 
Share this answer
 
v2
Comments
Ali Hojjati 2-Feb-18 9:18am    
Hi, I checked my codes and It happens when I Add Bitmaps to menu items. How to prevent this issue
Jochen Arndt 2-Feb-18 9:42am    
See my updated answer.

Also please use the green 'Improve question' link to edit your question instead of posting solutions or large comments. I have added the code to your question. So you can delete your solution and the comment.
Here is my code

C++
#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;

    // The pDataObj pointer contains the objects being acted upon. In this 
    // example, we get an HDROP handle for enumerating the selected files and 
    // folders.
    if (SUCCEEDED(pDataObj->GetData(&fe, &stm)))
    {
        // Get an HDROP handle.
        HDROP hDrop = static_cast<HDROP>(GlobalLock(stm.hGlobal));
        if (hDrop != NULL)
        {
            // Determine how many files are involved in this operation. This 
            // code sample displays the custom context menu item when only 
            // one file is selected. 
            UINT nFiles = DragQueryFile(hDrop, 0xFFFFFFFF, NULL, 0);
            if (nFiles == 1)
            {

                // Get the path of the file.
                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)))
						{
							//MessageBox(NULL, szMessage, L"CppShellExtContextMenuHandler", MB_OK);
						}
                    hr = S_OK;
                }
            }

            GlobalUnlock(stm.hGlobal);
        }

        ReleaseStgMedium(&stm);
    } 

    // If any value other than S_OK is returned from the method, the context 
    // menu item is not displayed.
    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)
{
	/*wchar_t szMessage[300];
	StringCchPrintf(szMessage, ARRAYSIZE(szMessage), L"The selected file is:\r\n\r\n%s", this->m_szSelectedFile);*/
	//MessageBox(NULL, m_szSelectedFile, L"CppShellExtContextMenuHandler", MB_OK);
	//system("notepad.exe");
	PCSTR m_pszVerb;
	//	StrCmpIA(pici->lpVerb, 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)
		{
			//MessageBox(NULL, (LPCWSTR)pici->lpVerb, L"Code", MB_OK);
			//MessageBox(NULL, (LPCWSTR)m_szSelectedFile, L"Code", MB_OK);

			UINT _Code = (UINT)pici->lpVerb;
			if (_Code == 1) //Icon Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 3;
				_writer << "|0" << endl;
			}
			else if (_Code == 2) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 4;
				_writer << "|0" << endl;
			}
			else if (_Code == 3) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 7;
				_writer << "|0" << endl;
			}
			else if (_Code == 4) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 5;
				_writer << "|0" << endl;
			}
			else if (_Code == 5) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 6;
				_writer << "|0" << endl;
			}
			else if (_Code == 7) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 9;
				_writer << "|0" << endl;
			}
			else if (_Code == 8) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 8;
				_writer << "|0" << endl;
			}
			else if (_Code == 9) //Icon File Library
			{
				_writer << m_szSelectedFile;
				_writer << "|";
				_writer << 0;
				_writer << "|0" << endl;
			}
		}
		else
		{
		_writer << m_szSelectedFile;
		_writer << "|" << 1;
		_writer << "|";
		_writer << (UINT)pici->lpVerb - 50 << endl;
		}
	}
	_writer.close();
	//LPWSTR wszPath_ = NULL;
	////SHGetKnownFolderPath(FOLDERID_, 0, NULL, &wszPath_);


	//char the_patha[256];
	//_getcwd(the_patha, 255);

	//size_t nSize1 = 1 + strlen(the_patha);

 //   LPWSTR wUserName = new WCHAR[nSize1];

 //   MultiByteToWideChar(CP_ACP, 0, the_patha, -1, wUserName, nSize1);

	///*LPWSTR _Base = NULL;
	//MultiByteToWideChar(CP_ACP, 0, the_patha, -1, _Base, 0);*/

	//MessageBox(NULL, wUserName, L"Test", MB_OK);
	//wstring _Path_44(wUserName);
	//_Path_44 = _Path_44 + L"\\Change\\ChangeIcon.exe";
	//ShellExecute( NULL, NULL, (LPWSTR)_Path_44.c_str(), NULL, NULL, SW_SHOW );
	
	/*std::wstring prefix (L"");
	wstring _Fol(m_szSelectedFile);
	if(_Fol.substr(0, prefix.size()) != prefix) {
		
	}*/

	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);
	// Get The Value
	wstring _PackName((std::istreambuf_iterator<char>(reader_1)),
			(std::istreambuf_iterator<char>()) );

	//MessageBox(NULL, (LPWSTR)_PackName.c_str(), L"", MB_OK);

	ShellExecute( NULL, NULL, (LPWSTR)_PackName.c_str(), NULL, NULL, SW_SHOW );
	//return S_OK;
	
	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);// Get color of first pixel at 0,0
			clrBK = GetSysColor(COLOR_MENU);// Get the current background color of the menu
			
			for (nRow = 0; nRow < bm.bmHeight; nRow++)// work our way through all the pixels changing their color
				for (nCol = 0; nCol < bm.bmWidth; nCol++)// when we hit our set transparency color.
					if (GetPixel(hdcDst, nCol, nRow) == clrTP)
						SetPixel(hdcDst, nCol, nRow, clrBK);
			
			DeleteDC(hdcDst);
		}
		DeleteDC(hdcSrc);
		
	}
	return hbmNew;// return our transformed bitmap.
}

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;

	// Read Selected Packs for the Menu
	
	//sqlite3_open(DB, &dbfile);

	if ( sqlite3_open(DB, &dbfile) == SQLITE_OK )
	{
		//MessageBox(NULL, L"Connected Successfully", L"Connection", MB_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);

	// Get The Value
	string _PackName((std::istreambuf_iterator<char>(reader_1)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName != "")
	{
		// Custom Pack One
		_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);

	// Get The Value
	string _PackName_((std::istreambuf_iterator<char>(reader_2)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName_ != "")
	{
		// Custom Pack One
		_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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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);

	// Get The Value
	string _PackName__((std::istreambuf_iterator<char>(reader_3)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName__ != "")
	{
		// Custom Pack One
		_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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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);

	// Get The Value
	string _PackName___((std::istreambuf_iterator<char>(reader_4)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName___ != "")
	{
		// Custom Pack One
		_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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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;
				}					
			}
		}
	}

	// Settings Menu
	
	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);

	// Final Menu Structure Pack 01
	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);
	// Final Menu Structure Pack 02
	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);
    // Final Menu Structure Pack 03
	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);
    // Final Menu Structure Pack 04
	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"-";



	// Final Menu Structure Tools Menu
	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);

	// Get The Value
	string _PackName_____((std::istreambuf_iterator<char>(reader_0)),
			(std::istreambuf_iterator<char>()) );

	if (_PackName_____ != "")
	{
		// Custom Pack One
		_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());

		//CString _Mess = _q.c_str();
		//MessageBox(NULL, _Mess.GetBuffer(0), L"Error", MB_OK);

		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) };
					//iconHandle = TransparentCopy(iconHandle, RGB(255, 255, 255));
					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);

	/*InsertMenu (hmenu, indexMenu, MIIM_BITMAP | MF_BYPOSITION | MF_POPUP, 
                 (UINT_PTR) subMenus, L"My Advanced Menu");*/

	sqlite3_close(dbfile);
	return MAKE_HRESULT(SEVERITY_SUCCESS, 0, _bigID - idCmdFirst + 1);
}
 
Share this answer
 
Comments
Richard Deeming 2-Feb-18 9:43am    
If you want to update your question, click the green "Improve question" link and edit your question.

DO NOT post your update as a "solution".

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900