hslistbox.cpp
来自「IO函数调用测试」· C++ 代码 · 共 101 行
CPP
101 行
// HSListBox.cpp : implementation file
//
#include "stdafx.h"
#include "IOExplorer.h"
#include "HSListBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHSListBox
CHSListBox::CHSListBox()
{
}
CHSListBox::~CHSListBox()
{
}
BEGIN_MESSAGE_MAP(CHSListBox, CListBox)
//{{AFX_MSG_MAP(CHSListBox)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/****************************************************************************
* CHSListBox::updateHS
* Result: void
*
* Effect:
* Computes the width of the item and sets the scroll value
****************************************************************************/
void CHSListBox::updateHS()
{
CClientDC dc(this);
CFont * f = GetFont();
CFont * oldfont = dc.SelectObject(f);
CRect r;
int width = 0;
GetClientRect(&r);
for(int i = 0; i < CListBox::GetCount(); i++)
{ /* compute each */
CString s;
CListBox::GetText(i, s);
int w = dc.GetTextExtent(s).cx;
if(w > width)
width = w;
} /* compute each */
dc.SelectObject(oldfont);
// Now determine if we need a horizontal scroll bar
// Add a fudge factor for the 3-D borders
width += 3 * ::GetSystemMetrics(SM_CXBORDER);
SetHorizontalExtent(width);
}
/////////////////////////////////////////////////////////////////////////////
// CHSListBox message handlers
/****************************************************************************
* CHSListBox::AddString
* Inputs:
* LPCTSTR s: String to add
* Result: int
* Position at which it was added, or LB_ERR or LB_SPACE
* Effect:
* Adds the string, and computes if the horizontal tab value is required
****************************************************************************/
int CHSListBox::AddString(LPCTSTR s)
{
int result = CListBox::AddString(s);
updateHS();
return result;
}
/****************************************************************************
* CHSListBox::DeleteString
* Inputs:
* int n: Index to delete
* Result: int
* Number of items remaining
* Effect:
* Deletes an item from the list box. Recomputes the horizontal
* scroll state
****************************************************************************/
int CHSListBox::DeleteString(int n)
{
int result = CListBox::DeleteString(n);
updateHS();
return result;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?