📄 mylistbox.cpp
字号:
// MyListBox.cpp : implementation file
//
#include "stdafx.h"
#include "pelco.h"
#include "MyListBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyListBox
CMyListBox::CMyListBox()
{
m_nMaxWidth = 0;
}
CMyListBox::~CMyListBox()
{
}
BEGIN_MESSAGE_MAP(CMyListBox, CListBox)
//{{AFX_MSG_MAP(CMyListBox)
ON_WM_NCHITTEST()
ON_WM_CREATE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyListBox message handlers
int CMyListBox::AddString(LPCTSTR lpszItem)
{
int nRet = CListBox::AddString(lpszItem);
SCROLLINFO scrollInfo;
memset(&scrollInfo, 0, sizeof(SCROLLINFO));
scrollInfo.cbSize = sizeof(SCROLLINFO);
scrollInfo.fMask = SIF_ALL;
GetScrollInfo(SB_VERT, &scrollInfo, SIF_ALL);
int nScrollWidth = 0;
if(GetCount() > 1 && ((int)scrollInfo.nMax >= (int)scrollInfo.nPage))
{
nScrollWidth = GetSystemMetrics(SM_CXVSCROLL);
}
SIZE sSize;
CClientDC myDC(this);
CFont* pListBoxFont = GetFont();
if(pListBoxFont != NULL)
{
CFont* pOldFont = myDC.SelectObject(pListBoxFont);
GetTextExtentPoint32(myDC.m_hDC,
lpszItem, strlen(lpszItem), &sSize);
m_nMaxWidth = max(m_nMaxWidth, (int)sSize.cx);
SetHorizontalExtent(m_nMaxWidth + 3);
myDC.SelectObject(pOldFont);
}
return nRet;
}
UINT CMyListBox::OnNcHitTest(CPoint point)
{
// TODO: Add your message handler code here and/or call default
CString strTip;
m_wndToolTip.GetText(strTip, this);
if (strTip != m_tipText)
{
m_wndToolTip.UpdateTipText(m_tipText, this);
}
return CListBox::OnNcHitTest(point);
}
int CMyListBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CListBox::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: Add your specialized creation code here
if (!m_wndToolTip.Create(this, TTS_ALWAYSTIP) ||
!m_wndToolTip.AddTool(this, "Tool tip for List")
)
AfxMessageBox("Unable to add tool tip for List");
return 0;
}
void CMyListBox::OnDestroy()
{
CListBox::OnDestroy();
// TODO: Add your message handler code here
m_wndToolTip.DestroyWindow();
}
void CMyListBox::SetTipText(CString tipText)
{
m_tipText =tipText;
}
BOOL CMyListBox::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
m_wndToolTip.RelayEvent(pMsg);
return CListBox::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -