ObjectARX_控件(線型、顏色、線寬、字體)

1.線型控件:CAcUiLineTypeComboBox函數

在其餘中添加須要的線型字體

class CLineTypeComboBox : public CAcUiLineTypeComboBox
{
public:
    CLineTypeComboBox ();
 
    virtual ~CLineTypeComboBox ();
 
    virtual BOOL OnSelectOther (BOOL isOther2, int curSel, int& newSel);
 
    virtual void OnComboBoxInit ();    
};
#include "StdAfx.h"
#include "LineTypeComboBox.h"

CLineTypeComboBox::CLineTypeComboBox()
{
}

CLineTypeComboBox::~CLineTypeComboBox()
{
}

void CLineTypeComboBox::OnComboBoxInit ()
{	
	Acad::ErrorStatus es;
	//用父類初始化
	CAcUiLineTypeComboBox::OnComboBoxInit();	
	std::vector<CString> arrstrLtName;
	//若是須要添加新線型,只需定義好新的宏名,在此加入便可...
	arrstrLtName.push_back(HH_NEWLINETYPE_001);
	arrstrLtName.push_back(HH_NEWLINETYPE_002);
	//新建線型,使用戶在界面上可以選擇到新增的線型
	AcDbDatabase *pCurDb=acdbHostApplicationServices()->workingDatabase();
	AcDbLinetypeTable  *pLinetypeTable;	
	es = pCurDb->getSymbolTable(pLinetypeTable, AcDb::kForWrite);
	if (es != Acad::eOk)
	{
		return;
	}
	int i=0;
	for (i=0; i<(int)arrstrLtName.size(); i++)
	{
		CString strLtName = arrstrLtName.at(i);
		if (!pLinetypeTable->has(strLtName))
		{
			AcDbLinetypeTableRecord  *pLinetypeRecord = new AcDbLinetypeTableRecord;
			pLinetypeRecord->setName(strLtName);
			if (i == 0)
			{
				pLinetypeRecord->setComments(_T("新增線型")+strLtName+_T("—>————<—"));	
			}
			else if (i == 1)
			{
				pLinetypeRecord->setComments(_T("新增線型")+strLtName+_T("—>>———<<—"));	
			}

			AcDbObjectId idLT = AcDbObjectId::kNull;
			es =  pLinetypeTable->add(idLT,pLinetypeRecord);
			CString LtName = strLtName;
			CAcUiLTypeRecord* pLTypeRecord = CreateLTRecord(LtName, idLT);
			CAcUiLineTypeComboBox::AddLTypeToControl(pLTypeRecord);
			pLinetypeRecord->close();
		}
	}
	pLinetypeTable->close();	
};	

BOOL CLineTypeComboBox::OnSelectOther(BOOL isOther2, int curSel, int& newSel)
{
	return __super::OnSelectOther(isOther2, curSel, newSel);
}

加載線型文件this

TCHAR sLineTypeFile[256];
	if (ads_findfile( _T("HHCAD.LIN"),sLineTypeFile)==RTNORM)
	{
		acdbLoadLineTypeFile(_T("continuousx"),sLineTypeFile,NULL);
		acdbLoadLineTypeFile(_T("ACAD_ISO02W100"),sLineTypeFile,NULL);
		acdbLoadLineTypeFile(_T("ACAD_ISO02W100x"),sLineTypeFile,NULL);
		acdbLoadLineTypeFile(_T("ACAD_ISO07W100"),sLineTypeFile,NULL);
		acdbLoadLineTypeFile(_T("ACAD_ISO10W100"),sLineTypeFile,NULL);
		acdbLoadLineTypeFile(_T("ACAD_ISO10W100x"),sLineTypeFile,NULL);
		acdbLoadLineTypeFile(_T("DASHED2"),sLineTypeFile,NULL);
	}

2.顏色控件:CAcUiColorComboBoxcode

int nColor = 1;//黑色
nIndex = m_cmbColor.FindItemByColorIndex(nColor);
if (nIndex > -1)
     m_cmbColor.SetCurSel(nIndex);

3.線寬控件:CAcUiLineWeightComboBoxget

4.字體控件:it

//====================================
// 函數名稱	: GetDirFiles
// 函數介紹	: 取得某目錄下全部指定屬性的文件名
// 返 回 值	: 選擇的文件夾全路徑
//
//====================================
bool CAppUtility::GetDirFiles( LPCTSTR lpDir,//目錄					  std::vector<CAppUtility::_FileStru_>&arr,// 返回文件
LPCTSTR lpExt/*="*.*"*/,// 尋找的文件類型
bool bIsIncludeSub/* = true*/// 是否包含子目錄)
{
	CString szPath = lpDir;
	if ( szPath.IsEmpty() )
		return false;
	if ( szPath.Right(1) != _T('\\') )
		szPath += _T("\\");

	// 進入路徑
	if ( _tchdir(szPath) != 0 )
		return false;

	_FileStru_ aFile;
	_tcscpy(aFile.szPath, szPath);// 路徑

	intptr_t hHand = _tfindfirst(lpExt, &aFile);
	if ( -1 == hHand )
		return false;
	for (int nRet=0; nRet!=-1; nRet=_tfindnext(hHand, &aFile))
	{
		// 判斷若是是.或..則繼續循環
		if ( 0 == _tcscmp(aFile.name, _T(".")) ||
			0 == _tcscmp(aFile.name, _T("..")) )
			continue;
		// 若是是目錄,則進入
		if ( aFile.IsDir() )
		{
			if ( !bIsIncludeSub )
				continue;
			CString szSub = szPath + aFile.name+_T("\\");
			GetDirFiles(szSub, arr, lpExt, bIsIncludeSub);
		}
		else
		{
			_stprintf(aFile.szPath, _T("%s%s"), szPath, aFile.name);

			// 分解文件名與後綴 
			CString strTemp(aFile.name);

			// 從後向前分離出文件名、格式名(以.爲分界符) 
			int nPos = strTemp.ReverseFind(_T('.'));
			if ( -1 != nPos )
			{
				_tcscpy(aFile.strExtOnly, strTemp.Mid(nPos+1,strTemp.GetLength()-nPos));
				strTemp = strTemp.Mid(0,nPos);
			}			
			else
				aFile.strExtOnly[0] = _T('');
			_tcscpy(aFile.strNameOnly, strTemp);
			arr.push_back(aFile);
		}
	}
	_findclose(hHand);
	return true;
}

extern "C" __declspec(dllexport) int CALLBACK EnumFontFamProc(LPENUMLOGFONT lpelf,LPNEWTEXTMETRIC lpntm,DWORD nFontType,long lparam)
{
	CComboBox *pComb = (CComboBox *) ((void*)lparam);
	pComb->AddString(lpelf->elfLogFont.lfFaceName);	//Style
	return 1;
}

void InitFontCmb()
{
	LOGFONT lf;
	CClientDC dc (this);
	lf.lfCharSet =  ANSI_CHARSET; //中國標準字體
	_tcscpy(lf.lfFaceName,_T("")); //設置Style
	::EnumFontFamiliesEx((HDC) dc,&lf,(FONTENUMPROC)EnumFontFamProc,(LPARAM) (&m_cmbFont),0);

	// 尋找字體
	std::vector<CAppUtility::_FileStru_>arrSHX;
	CAppUtility::GetDirFiles(CAppUtility::GetCADPath()+_T("Font"), arrSHX, _T("*.shx"), true);
	CAppUtility::GetDirFiles(CAppUtility::GetPathFont(), arrSHX, _T("*.shx"), true);
	for (int i=0; i<(int)arrSHX.size(); ++i)
	{
		if ( m_cmbFont.FindString(-1, arrSHX[i].strNameOnly) != -1 )
			continue;
		m_cmbFont.AddString(arrSHX[i].strNameOnly);
	}
}
相關文章
相關標籤/搜索