contenttypecombobox.cpp
来自「管理项目进度工具的原代码」· C++ 代码 · 共 121 行
CPP
121 行
// contenttypecombobox.cpp : implementation file
//
#include "stdafx.h"
#include "contenttypecombobox.h"
#include "ContentMgr.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContentTypeComboBox
CContentTypeComboBox::CContentTypeComboBox(const CContentMgr* pContentMgr) :
m_pContentMgr(pContentMgr), m_nInitSel(0)
{
}
CContentTypeComboBox::~CContentTypeComboBox()
{
}
BEGIN_MESSAGE_MAP(CContentTypeComboBox, CComboBox)
//{{AFX_MSG_MAP(CContentTypeComboBox)
ON_WM_CREATE()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CContentTypeComboBox message handlers
int CContentTypeComboBox::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CComboBox::OnCreate(lpCreateStruct) == -1)
return -1;
if (!m_pContentMgr)
return -1;
if (!GetCount())
FillCombo();
return 0;
}
void CContentTypeComboBox::FillCombo()
{
ASSERT (CComboBox::GetCount() == 0);
ASSERT (m_pContentMgr);
if (m_pContentMgr && !CComboBox::GetCount())
{
for (int nItem = 0; nItem < m_pContentMgr->GetNumContent(); nItem++)
{
CString sItem = m_pContentMgr->GetContentTypeDescription(nItem);
AddString(sItem);
}
}
if (m_nInitSel < GetCount())
SetCurSel(m_nInitSel);
}
void CContentTypeComboBox::PreSubclassWindow()
{
if (!CComboBox::GetCount() && m_pContentMgr)
FillCombo();
CComboBox::PreSubclassWindow();
}
int CContentTypeComboBox::GetSelectedFormat(CONTENTFORMAT& cf) const
{
int nSel = GetCurSel();
if (nSel != CB_ERR)
cf = m_pContentMgr->GetContentFormat(nSel);
return nSel;
}
int CContentTypeComboBox::SetSelectedFormat(LPCTSTR szTypeID)
{
int nSel = m_pContentMgr ? m_pContentMgr->FindContent(szTypeID) : CB_ERR;
SetCurSel(nSel);
return nSel;
}
int CContentTypeComboBox::GetCount() const
{
if (m_pContentMgr)
return m_pContentMgr->GetNumContent();
// else
return CComboBox::GetCount();
}
void CContentTypeComboBox::SetCurSel(int nSel)
{
if (GetSafeHwnd())
CComboBox::SetCurSel(nSel);
else
m_nInitSel = nSel;
}
int CContentTypeComboBox::GetCurSel() const
{
if (GetSafeHwnd())
return CComboBox::GetCurSel();
// else
return m_nInitSel;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?