我的对话框上有一个标准的
CMFCMenuButton
控件:
CONTROL "Congregation Link",IDC_MFCMENUBUTTON_CONGREGATION_LINK,
"MfcMenuButton",WS_TABSTOP,257,60,159,14
这是菜单:
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
我使用标准方法来初始化控件:
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);
}
}
我想模仿一个超链接:
这可以通过
CMFCMenuButton
控制实现吗?
PS。理想情况下,它会显示带有下划线的链接(很像按钮超链接控件)
您只需实现 WM_SETCURSOR 处理程序。这应该适用于按钮区域。
CMFCMenuButton
的文档,我意识到它源自 CMFCButton
。
CMFCButton::SetMouseCursorHand
。引用文档:
使用此方法将手的光标图像与按钮相关联。光标是从应用程序资源加载的。
所以我更新了我的
InitCongregationLinkMenuButton
方法以包括:
m_menuBtnCongregationLink.SetMouseCursorHand();
它有效:
我现在有了手形光标,无需派生新类。但即使鼠标位于下拉箭头上方,它仍保持为手形光标。