I have a derived CHtmlView
class and I have followed the various tutorials to display my own custom context menu.
This is the complete handler:
HRESULT CChristianLifeMinistryHtmlView::CustomContextMenu(const POINT* ppt, IUnknown* pcmdtReserved)
{
if (ppt == nullptr || pcmdtReserved == nullptr)
return E_FAIL;
IOleWindow* oleWnd = nullptr;
auto hr = pcmdtReserved->QueryInterface(IID_IOleWindow, reinterpret_cast<void**>(&oleWnd));
if (hr != S_OK && oleWnd == nullptr)
return hr;
HWND hwnd = nullptr;
hr = oleWnd->GetWindow(&hwnd);
if (hr != S_OK || hwnd == nullptr)
return hr;
// AJT 21.0.0 Bug fix - use the resource handle!
auto hMainMenu = LoadMenu(AfxGetResourceHandle(), MAKEINTRESOURCE(IDR_MENU_HTML_POPUP));
if (hMainMenu == nullptr)
return E_FAIL;
auto hPopupMenu = GetSubMenu(hMainMenu, 0);
if (hPopupMenu == nullptr)
{
::DestroyMenu(hMainMenu);
return E_FAIL;
}
if (ShowEditorSRRContextMenu())
{
::RemoveMenu(hPopupMenu, IDM_VIEWSOURCE, MF_BYCOMMAND);
}
// #TODO add code to check if return FALSE and use GetLastError
::SetMenuItemBitmaps(hPopupMenu, IDM_PAGESETUP, MF_BYCOMMAND, (HBITMAP)m_bmpPageSetup, (HBITMAP)m_bmpPageSetup);
::SetMenuItemBitmaps(hPopupMenu, IDM_PRINTPREVIEW, MF_BYCOMMAND, (HBITMAP)m_bmpPrintPreview, (HBITMAP)m_bmpPrintPreview);
::SetMenuItemBitmaps(hPopupMenu, IDM_REFRESH, MF_BYCOMMAND, (HBITMAP)m_bmpRefresh, (HBITMAP)m_bmpRefresh);
::SetMenuItemBitmaps(hPopupMenu, IDM_FIND, MF_BYCOMMAND, (HBITMAP)m_bmpFind, (HBITMAP)m_bmpFind); // AJT 22.0.2
// Show shortcut menu
const auto iSelection = ::TrackPopupMenu(hPopupMenu,
TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD,
ppt->x,
ppt->y,
0,
hwnd,
(RECT*)nullptr);
// Send selected shortcut menu item command to shell
if (iSelection != 0)
{
if (iSelection == IDM_PRINTPREVIEW)
{
::SendMessage(GetParent()->GetSafeHwnd(), WM_COMMAND, ID_FILE_PRINT_PREVIEW, NULL);
}
else if (iSelection == CUSTOM_MENU_VIEW_XML)
{
::SendMessage(GetParent()->GetSafeHwnd(), WM_COMMAND, CUSTOM_MENU_VIEW_XML, NULL);
}
else if (iSelection == CUSTOM_MENU_OPEN_FILE_LOCATION) // AJT 22.0.2 JIRA MSA 91
{
::SendMessage(GetParent()->GetSafeHwnd(), WM_COMMAND, ID_DISPLAY_WORKING_FOLDER, NULL);
}
else if (iSelection == IDM_REFRESH) // AJT 21.0.6 JIRA MSA 38
{
::SendMessage(GetParent()->GetSafeHwnd(), WM_COMMAND, ID_VIEW_REFRESH, NULL);
}
else
{
::SendMessage(hwnd, WM_COMMAND, iSelection, NULL);
}
}
return S_OK;
}
It gets displayed like this:
HRESULT CChristianLifeMinistryHtmlView::OnShowContextMenu(DWORD dwID, LPPOINT ppt,
LPUNKNOWN pcmdtReserved, LPDISPATCH pdispReserved)
{
if(ShowEditorMWBContextMenu())
return CustomContextMenu(ppt, pcmdtReserved);
return S_OK; // Eat it
}
Now, if I run my software (MFC project), and invoke the context menu:
All is good. But, if I create a temporary user account on my PC, and run my software from that temporary account:
Why are two of my custom menu items disabled for this user account?
- View XML
- Open File Location
I am using Windows 11. Is this coding issue? Is this a Windows 11 setup issue?
Update
If I right-click the app and run elevated then the context menu items are enabled. Why do I have to do that?
Background reading:
Is it not possible to add our own menu items on the CHtmlView context menu?