如何在 listbox中,选中其中某个选项,不按任何按键,弹出相应的解释菜单,,请各位高手,指点迷津!!!!!!!!小弟愚笨,说的详细些,万分感谢!!!!!

解决方案 »

  1.   

    重载CListBox
    看看这个代码能用不,大致就是这样子
    //MyList.h
    class CMyList : public CListBox
    {public:
    CMyList ();
             ~CMyList() ;
    // attributes
    public:
             long int m_nToolTip;
    BOOL m_bToolTip;
    CToolTipCtrl* m_pToolTip;// 
    public:// 
    // ClassWizard 
    //{{AFX_VIRTUAL(CUndoList)
    public:
    virtual BOOL PreTranslateMessage(MSG* pMsg);
    //}}AFX_VIRTUAL// 
    public:
    protected:
    //{{AFX_MSG(CMyList)
    afx_msg void OnMouseMove(UINT nFlags, CPoint point);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    };///////////////////////////////////////////////
    //MyList.cpp
    #include "MyList.h"
    // CMyList
    CMyList::CMyList()
    {
    m_nToolTip = -1;
    m_bToolTip = false;
    m_pToolTip = NULL;}CMyList::~CMyList()
    {
    if (m_pToolTip != NULL)
    delete m_pToolTip;
    }
    BEGIN_MESSAGE_MAP(CMyList, CListBox)
    //{{AFX_MSG_MAP(CMyList)
    ON_WM_MOUSEMOVE()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()void CMyList::OnMouseMove(UINT nFlags, CPoint point) 

    BOOL bOutside;
    long int nPos = this->ItemFromPoint(point, bOutside);
    if (! bOutside) {
    SetCurSel(nPos);
    if (m_pToolTip != NULL) {
    if (m_nToolTip != nPos ) {
    m_nToolTip = nPos ;
    m_bToolTip = false;
    CRect rect ;
    GetClientRect(&rect) ;
    long int nTextLen = GetTextLen(nPos) ;
    if (nTextLen > 0) {
    CString text;
    GetText(m_nToolTip, text); CFont* pFont = GetParent()->GetFont();
    LOGFONT logFont;
    pFont->GetLogFont(&logFont);
    CFont font;
    font.CreateFontIndirect(&logFont);
    CDC dc;
    dc.CreateCompatibleDC(NULL);
    dc.SelectObject(font);
    SIZE sz;
    ::GetTextExtentPoint32(dc.GetSafeHdc(), text, text.GetLength(), &sz); if (sz.cx > rect.Width()) {
    m_pToolTip->UpdateTipText(text, this);
    m_bToolTip = true;
    }
    }
    }
    m_pToolTip->Activate(m_bToolTip);
    }
    }
    CListBox::OnMouseMove(nFlags, point);
    }BOOL CMyList::PreTranslateMessage(MSG* pMsg) 
    {
    if (m_pToolTip != NULL)
    m_pToolTip->RelayEvent(pMsg);
    return CListBox::PreTranslateMessage(pMsg);
    }
      

  2.   

    首先构造函数要改一下
    CMyList::CMyList()
    {
    m_nToolTip = -1;
    m_bToolTip = false;
    m_pToolTip = new CToolTipCtrl;
    if (m_pToolTip->Create(this)) {
    m_pToolTip->AddTool(this, "");
    // 
    m_pToolTip->SetDelayTime(TTDT_INITIAL, 100); // 100ms
    m_pToolTip->SetDelayTime(TTDT_AUTOPOP, 1000*10); // 10s
    m_pToolTip->SetDelayTime(TTDT_RESHOW, 100);   // 100ms
    }
    }用法就是把你的控件绑定变量,变量类型是CMyList
      

  3.   

    大哥很多错误地,
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(40) : error C2653: 'CMyList' : is not a class or namespace name
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(43) : error C2673: 'OnMouseMove' : global functions do not have 'this' pointers
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(43) : error C2227: left of '->ItemFromPoint' must point to class/struct/union
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(45) : error C2065: 'SetCurSel' : undeclared identifier
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(46) : error C2065: 'm_pToolTip' : undeclared identifier
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(47) : error C2065: 'm_nToolTip' : undeclared identifier
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(49) : error C2065: 'm_bToolTip' : undeclared identifier
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(51) : error C2660: 'GetClientRect' : function does not take 1 parameters
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(52) : error C2065: 'GetTextLen' : undeclared identifier
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(55) : error C2065: 'GetText' : undeclared identifier
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(57) : error C2660: 'GetParent' : function does not take 0 parameters
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(57) : error C2227: left of '->GetFont' must point to class/struct/union
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(69) : error C2227: left of '->UpdateTipText' must point to class/struct/union
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(69) : error C2673: 'OnMouseMove' : global functions do not have 'this' pointers
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(74) : error C2227: left of '->Activate' must point to class/struct/union
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(77) : error C2248: 'OnMouseMove' : cannot access protected member declared in class 'CWnd'
            d:\microsoft visual studio\vc98\mfc\include\afxwin.h(2358) : see declaration of 'OnMouseMove'
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(77) : error C2352: 'CWnd::OnMouseMove' : illegal call of non-static member function
            d:\microsoft visual studio\vc98\mfc\include\afxwin.h(2358) : see declaration of 'OnMouseMove'
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(80) : error C2653: 'CMyList' : is not a class or namespace name
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(83) : error C2227: left of '->RelayEvent' must point to class/struct/union
    D:\ÎҵŤ³Ì\1224merry\Mylist.cpp(84) : error C2352: 'CWnd::PreTranslateMessage' : illegal call of non-static member function
            d:\microsoft visual studio\vc98\mfc\include\afxwin.h(2422) : see declaration of 'PreTranslateMessage'
    Generating Code...
    Error executing cl.exe.
      

  4.   

    兄弟,你先从CListBox继承一个类,名称为CMyList
    然后用这个代码覆盖.h文件和.cpp文件
    不过一些头文件要保留!使用CMyList的时候,记得要#include "MyList.h"
      

  5.   

    给分先了,对了,有MSN,QQ吗,还有点问题问你,方便的话,tell me 3Q
      

  6.   

    [email protected]
    给我发邮件吧!
    在公司上聊天工具不好!