Button右键弹出式菜单
关键点
用类来实现 的
实现过程
新建1个类 类名CButtonPopMenu 基类CButton
新建1个菜单资源 IDR_MENU1
// ButtonPopMenu.h : header file// Attributespublic:CRectm_Rect;CMenum_Menu;intm_MenuID;// ButtonPopMenu.cpp : implementation filevoidCButtonPopMenu::OnRButtonDown(UINTnFlags,CPointpoint){GetWindowRect( &m_Rect);point.x+=m_Rect.left;point.y+=m_Rect.top;VERIFY(m_Menu.LoadMenu(m_MenuID));CMenu*pPopup=m_Menu.GetSubMenu(0);ASSERT(pPopup!=NULL);CWnd*pWndPopupOwner= this;while (pWndPopupOwner->GetStyle() &WS_CHILD){pWndPopupOwner=pWndPopupOwner->GetParent();pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x,point.y,pWndPopupOwner);}m_Menu.Detach();m_Menu.DestroyMenu();CButton::OnRButtonDown(nFlags,point);}// project02Dlg.h : header file#include"ButtonPopMenu.h"CButtonPopMenum_btn1;// project02Dlg.cpp : implementation fileBOOLCProject02Dlg::OnInitDialog()// TODO: Add extra initialization herem_btn1.m_MenuID=IDR_MENU1; |
图-1
备注
此文可以实现任意控件的右键菜单弹出
像一些控件默认所没有的功能都可以通过定义类 然后关联类来实现
相关链接
控件上弹出菜单
来自为知笔记(Wiz)
附件列表
原文链接: https://www.cnblogs.com/xe2011/p/3885702.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/140107
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!