|
[code]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);
}
加载线型文件
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.颜色控件:CAcUiColorComboBox
int nColor = 1;//黑色
nIndex = m_cmbColor.FindItemByColorIndex(nColor);
if (nIndex > -1)
m_cmbColor.SetCurSel(nIndex);
3.线宽控件:CAcUiLineWeightComboBox
4.字体控件:
//====================================
// 函数名称 : 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);
}
}[/code] |
|