我正在使用MFC Windows应用程序。我在Check List Box控件中使用复选框。某些复选框已禁用。如何实施禁用复选框的工具提示?
答案 0 :(得分:1)
Ran Wainstein实现了列表框控件中每个项目的工具提示。这也可以扩展到Check List Box控件。
MyCheckListBox.h
class CMyCheckListBox : public CCheckListBox
{
DECLARE_DYNAMIC(CMyCheckListBox)
public:
CMyCheckListBox(){};
virtual ~CMyCheckListBox(){};
afx_msg int OnToolHitTest(CPoint point, TOOLINFO * pTI) const;
UINT ItemFromPoint2(CPoint pt, BOOL& bOutside) const;
BOOL OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult );
protected:
virtual void PreSubclassWindow();
DECLARE_MESSAGE_MAP()
};
<强> MyCheckListBox.cpp 强>
这仅适用于Unicode字符串。
IMPLEMENT_DYNAMIC(CMyCheckListBox, CCheckListBox)
BEGIN_MESSAGE_MAP(CMyCheckListBox, CCheckListBox)
ON_NOTIFY_EX_RANGE(TTN_NEEDTEXT, 0, 0xFFFF, OnToolTipText)
END_MESSAGE_MAP()
void CMyCheckListBox::PreSubclassWindow() {
CCheckListBox::PreSubclassWindow();
EnableToolTips(TRUE);
}
int CMyCheckListBox::OnToolHitTest(CPoint point, TOOLINFO * pTI) const{
int row;
RECT cellrect;
BOOL tmp = FALSE;
row = ItemFromPoint(point,tmp);
if ( row == -1 )
return -1;
GetItemRect(row,&cellrect);
pTI->rect = cellrect;
pTI->hwnd = m_hWnd;
pTI->uId = (UINT)((row));
pTI->lpszText = LPSTR_TEXTCALLBACK;
return pTI->uId;
}
BOOL CMyCheckListBox::OnToolTipText( UINT id, NMHDR * pNMHDR, LRESULT * pResult ){
TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
CString strTipText;
UINT nID = pNMHDR->idFrom;
GetText( nID ,strTipText);
lstrcpyn(pTTTW->szText, strTipText, 80);
*pResult = 0;
return TRUE;
}
UINT CMyCheckListBox::ItemFromPoint2(CPoint pt, BOOL& bOutside) const{
int nFirstIndex, nLastIndex;
nFirstIndex = GetTopIndex();
nLastIndex = nFirstIndex + GetCount();
bOutside = TRUE;
CRect Rect;
int nResult = -1;
for (int i = nFirstIndex; nResult == -1 && i <= nLastIndex; i++){
if (GetItemRect(i, &Rect) != LB_ERR){
if (Rect.PtInRect(pt)){
nResult = i;
bOutside = FALSE;
}
}
}
return nResult;
}
最后在相应的对话框中实现Check List Box控件。输出为