zoukankan      html  css  js  c++  java
  • C++ Button右键弹出式菜单

     

    Button右键弹出式菜单

     

    关键点

    用类来实现 的

     

    实现过程

    新建1个类  类名CButtonPopMenu 基类CButton

    新建1个菜单资源 IDR_MENU1

     

    // ButtonPopMenu.h : header file
    // Attributes
    public:
        CRect m_Rect;  
        CMenu m_Menu;  
        int m_MenuID;
        
    // ButtonPopMenu.cpp : implementation file     
    void CButtonPopMenu::OnRButtonDown(UINT nFlagsCPoint point
    {
        GetWindowRect( &m_Rect);
        point.x += m_Rect.left;
        point.y += m_Rect.top;
        
        VERIFY(m_Menu.LoadMenu(m_MenuID));    
        CMenupPopup = m_Menu.GetSubMenu(0); 
        ASSERT(pPopup != NULL); 
        CWndpWndPopupOwner = this; 
        
        while ( pWndPopupOwner->GetStyle() & WS_CHILD )
        {    
            pWndPopupOwner = pWndPopupOwner->GetParent(); 
            pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_LEFTBUTTONpoint.xpoint.ypWndPopupOwner);
        }
        m_Menu.Detach(); 
        m_Menu.DestroyMenu(); 
        CButton::OnRButtonDown(nFlagspoint);
    }
        
    // project02Dlg.h : header file
    #include "ButtonPopMenu.h"
    CButtonPopMenu    m_btn1; 
        
    // project02Dlg.cpp : implementation file
    BOOL CProject02Dlg::OnInitDialog()
        // TODO: Add extra initialization here
        m_btn1.m_MenuID=IDR_MENU1;
            

     

     

       

    图-1

    图-2


     

    备注

    此文可以实现任意控件的右键菜单弹出

    像一些控件默认所没有的功能都可以通过定义类 然后关联类来实现

     

    相关链接

                               

    控件上弹出菜单

     




    附件列表

    • 相关阅读:
      P4318 完全平方数 [二分答案+容斥+莫比乌斯函数]
      P2522 [HAOI2011]Problem b
      莫比乌斯反演学习笔记
      UVALive646 Deranged Exams [容斥+排列组合]
      HDU5514 Frogs [容斥(II)]
      P2567 [SCOI2010]幸运数字 [容斥+有技巧的搜索]
      微信api退款操作
      类中或者是程序集中,根据虚拟路径获取绝对路径
      加载程序集中内嵌资源
      .NET Framework 框架简述01
    • 原文地址:https://www.cnblogs.com/xe2011/p/3885702.html
    Copyright © 2011-2022 走看看