本文介绍了带有图标/位图的上下文菜单的Treelist ctrl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

上下文菜单弹出项目选择(不是文本选择),

无法在上下文菜单上显示位图/图标



我尝试了什么:



选择了一些项目时,整个树状列表中会出现上下文菜单。

The context menu is getting pop-up on item selection ( not on Text selection) ,
Failed to show bitmaps/icons on context menu

What I have tried:

The context menu is popping up on entire treelist with some item selected .

推荐答案

    UINT uFlags;
    CRect rc;
    CPoint clickpoint = point;
    CPoint mypoint = point;
    m_str_tree.ScreenToClient(&mypoint);
    HWND htemp;
    :: GetDlgItem(htemp,IDC_TREE);

    HTREEITEM htItem = m_str_tree.HitTest(mypoint, &uFlags);
    //To know which text is selcted
    CString  TreeText2 = m_str_tree.GetItemText(htItem);
    m_str_tree.GetItemRect(htItem, &rc, TRUE);

     // To check right click is on item text or not
    if (mypoint.x > rc.right || mypoint.x < rc.left)
    {
        return;
    }

or//<pre> if (! (htItem != nullptr && (TVHT_ONITEMLABEL & uFlags)))
    {
        return;
    }

 CMenu mnuPopupSubmit;
        //Add your menu id
        mnuPopupSubmit.LoadMenu(IDR_MENU1);

         CMenu *mnuPopupMenu = mnuPopupSubmit.GetSubMenu(0);
        ASSERT(mnuPopupMenu);

            mnuPopupMenu->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, clickpoint.x, clickpoint.y, this);




<pre>//Adding images to the context Menu

void CPathFinderDlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
    CDialogEx::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);

    // TODO: Add your message handler code here



    HICON hIcon = AfxGetApp()->LoadIcon(IDB_IMAGE);
    pPopupMenu->

//or directly load bitmaps as  CBitmap m_bitmapvar_16;
//m_bitmapvar_16.LoadBitmap(IDB_IMAGE); 
//ID__File is menu's option id

SetMenuItemBitmaps(ID__File, MF_BYCOMMAND, &m_bitmapvar_16, NULL);


}


这篇关于带有图标/位图的上下文菜单的Treelist ctrl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 17:42