如何在 listbox中,选中其中某个选项,不按任何按键,弹出相应的解释菜单,,请各位高手,指点迷津!!!!!!!!小弟愚笨,说的详细些,万分感谢!!!!!
解决方案 »
- vc使用ado连接access出错,Provider 路径中含有特殊字符
- 讨论个方案,关于多方向运动控制的
- 怎么获得MSDN文档
- 请问哪有《Windows NT 技术内幕》第二版下载?
- 精通VC开发数据库的请进!关于ADO数据操作的问题。
- 高手请进:关于VC不能使用VB创建的DLL的问题,真是郁闷!!!
- 往键盘缓冲区里写的东西会直接显示在当前获得焦点的编辑框上吗?怎么写键盘缓冲区?
- 本人刚开始学习com+,请各位大虾推荐几本好书,不胜感激!
- 求助:AUTOCAD做的图怎么导出呢?(在线急等,解决问题,马上给分)
- SendMessage发消息,怎样用PeekMessage接收
- 如何向COleControl控件上动态添加图片(bitmap)?
- 寻求GPRS资料
看看这个代码能用不,大致就是这样子
//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);
}
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
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.
然后用这个代码覆盖.h文件和.cpp文件
不过一些头文件要保留!使用CMyList的时候,记得要#include "MyList.h"
给我发邮件吧!
在公司上聊天工具不好!