I have a standard CMFCMenuButton
control on my dialog:
CONTROL "Congregation Link",IDC_MFCMENUBUTTON_CONGREGATION_LINK,
"MfcMenuButton",WS_TABSTOP,257,60,159,14
This is the menu:
IDR_MENU_HYPERLINK_POPUP MENU
BEGIN
POPUP "__HYPERLINK__"
BEGIN
MENUITEM "Add Hyperlink", ID_ADD_HYPERLINK
MENUITEM "Edit Hyperlink", ID_EDIT_HYPERLINK
MENUITEM "Remove Hyperlink", ID_REMOVE_HYPERLINK
END
END
I use standard approach to initialize the control:
void CCongregationDlg::InitCongregationLinkMenuButton()
{
m_menuCongregationLink.LoadMenu(IDR_MENU_HYPERLINK_POPUP);
m_menuBtnCongregationLink.m_hMenu = m_menuCongregationLink.GetSubMenu(0)->GetSafeHmenu();
m_menuBtnCongregationLink.m_nFlatStyle = CMFCButton::BUTTONSTYLE_SEMIFLAT;
// Resize (if required)
CRect rctButton;
m_menuBtnCongregationLink.GetWindowRect(&rctButton);
const auto nOrigWidth = rctButton.Width(); // Store the original width
const auto sizNewButton = m_menuBtnCongregationLink.SizeToContent(true); // This resizes the control!!!
if (sizNewButton.cx > nOrigWidth) // Compare to the original width rather than the new one
{
m_menuBtnCongregationLink.SizeToContent();
}
else // Restore original width
{
m_menuBtnCongregationLink.SetWindowPos(nullptr, -1, -1,
nOrigWidth, sizNewButton.cy, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
}
}
I would like to mimic a hyperlink:
- When the mouse is over the text it will show a hand cursor.
- When the mouse is over the drop-down arrow to display the menu it turns into a normal cursor.
Is this possible with the CMFCMenuButton
control?
PS. Ideally it would show the link with an underline (much like the button hyperlink control)
I was looking up the documentation for
CMFCMenuButton
and I realised that it is derived fromCMFCButton
.And, that class have this method:
CMFCButton::SetMouseCursorHand
. To quote the documentation:So I updated my
InitCongregationLinkMenuButton
method to include:And it works:
I now have the hand cursor without the need to derive a new class. But it stays as a hand cursor even when the mouse is over the drop-arrow.