mycombobox.cpp

来自「使用Visual C++ .NET实现简单了一个书籍管理系统」· C++ 代码 · 共 70 行

CPP
70
字号
// MyComboBox.cpp : 实现文件
//

#include "stdafx.h"
#include "LManage.h"
#include "MyComboBox.h"

// CMyComboBox

IMPLEMENT_DYNAMIC(CMyComboBox, CComboBox)
CMyComboBox::CMyComboBox()
{
}

CMyComboBox::~CMyComboBox()
{
}


BEGIN_MESSAGE_MAP(CMyComboBox, CComboBox)
END_MESSAGE_MAP()


// 得到当前显示的ID
int CMyComboBox::GetCurMyID()
{
	CString str;
	GetLBText( GetCurSel(), str );
	return GetStringID(str);
}
// 添加当前显示字符串
void CMyComboBox::AddMyString( int id , CString name )
{
	this->AddString( this->GetShowString( id, name ) );
}
// 设置当前显示项,根据ID确定
void CMyComboBox::SetMyCurSel( int id )
{
	CString str;
	for( int i = 0; i < GetCount(); i++ )
	{
		GetLBText( i, str );
		if( GetStringID(str) == id )
		{
			SetCurSel( i );
			return;
		}
	}
	SetCurSel(0);
}
// 组成显示字符串
CString CMyComboBox::GetShowString( int id, CString name )
{
	CString temp;
	temp.Format( "%d   %s", id, name );
	return temp;
}
// 得到显示字符串的ID
int CMyComboBox::GetStringID( CString str )
{
	int p = str.Find( "   " );
	if( p != -1 )
	{
		CString id = str.Mid( 0, p );
		return (int)atol( id );
	}
	else
		return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?