619 lines
16 KiB
C++
619 lines
16 KiB
C++
#include "stdafx.h"
|
|
|
|
#include <afxtempl.h>
|
|
|
|
//extern TARCH_IMPEXP TCHAR g_sDwbPath[];
|
|
|
|
|
|
|
|
//由部分tkw文件名(无路径、无后缀),返回TKW全路径文件名
|
|
BOOL GetFullTkwFile(const TCHAR* szShortFile, CString &csTkwFileName)
|
|
{
|
|
CString csMenuName = szShortFile;
|
|
|
|
XString xsTchtkwFile;
|
|
if(!FindFile(_T("shstkw.idx"), xsTchtkwFile))
|
|
{
|
|
AfxMessageBox(_T("SYS目录下没有发行shstkw.idx文件!"));
|
|
return FALSE;
|
|
}
|
|
CString csTmp, csBuf, csTkwType, csTkwTmp;
|
|
CString csDwbPath, csDdblPath, csLib3dPath;
|
|
csDwbPath = g_sDwbPath;
|
|
csDdblPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\ddbl\\");
|
|
csLib3dPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\Lib3d\\");
|
|
|
|
FILE *fp=_tfopen(xsTchtkwFile, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
|
|
while(!feof(fp)) {
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T("") )
|
|
continue;
|
|
if(csBuf.Find(_T(':')) < 0 || csBuf.Find(_T('*')) < 0)
|
|
continue;
|
|
csTmp = csBuf.Mid(csBuf.Find(_T(':')) + 1,
|
|
csBuf.Find(_T('*')) - csBuf.Find(_T(':')) - 1);
|
|
|
|
csTkwType = csBuf.Left(csBuf.Find(_T(':')));
|
|
csTkwTmp = csBuf.Right(csBuf.GetLength() -csBuf.Find(_T('*')) - 1);
|
|
if(_tcsicmp(csTkwTmp, szShortFile)==0) {
|
|
if(csTkwType == _T("0"))
|
|
csTkwFileName = csDwbPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType == _T("2"))
|
|
csTkwFileName = csDdblPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType==_T("3"))
|
|
csTkwFileName = csLib3dPath + csTkwTmp + _T(".tkw");
|
|
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
}
|
|
fclose(fp);
|
|
return FALSE;
|
|
}
|
|
//由部分gjk文件名(无路径、无后缀),返回TKW全路径文件名
|
|
BOOL GetFullGjkFile(const TCHAR* szShortFile, CString &csTkwFileName)
|
|
{
|
|
CString csMenuName = szShortFile;
|
|
|
|
XString xsTchtkwFile;
|
|
if(!FindFile(_T("shsgjk.idx"), xsTchtkwFile))
|
|
{
|
|
AfxMessageBox(_T("SYS目录下没有发行shsgjk.idx文件!"));
|
|
return FALSE;
|
|
}
|
|
CString csTmp, csBuf, csTkwType, csTkwTmp;
|
|
CString csDwbPath, csDdblPath, csLib3dPath;
|
|
csDwbPath = g_sDwbPath;
|
|
csDdblPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\ddbl\\");
|
|
csLib3dPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\Lib3d\\");
|
|
|
|
FILE *fp=_tfopen(xsTchtkwFile, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
|
|
while(!feof(fp)) {
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T("") )
|
|
continue;
|
|
if(csBuf.Find(_T(':')) < 0 || csBuf.Find(_T('*')) < 0)
|
|
continue;
|
|
csTmp = csBuf.Mid(csBuf.Find(_T(':')) + 1,
|
|
csBuf.Find(_T('*')) - csBuf.Find(_T(':')) - 1);
|
|
|
|
csTkwType = csBuf.Left(csBuf.Find(_T(':')));
|
|
csTkwTmp = csBuf.Right(csBuf.GetLength() -csBuf.Find(_T('*')) - 1);
|
|
if(_tcsicmp(csTkwTmp, szShortFile)==0) {
|
|
if(csTkwType == _T("0"))
|
|
csTkwFileName = csDwbPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType == _T("2"))
|
|
csTkwFileName = csDdblPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType==_T("3"))
|
|
csTkwFileName = csLib3dPath + csTkwTmp + _T(".tkw");
|
|
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
}
|
|
fclose(fp);
|
|
return FALSE;
|
|
}
|
|
//输入下拉菜单上得到的图库名称,返回相对于实际TKW全路径文件名
|
|
BOOL GetTkwFileByMenu(const TCHAR* szMenuName, CString &csTkwFileName)
|
|
{
|
|
CString csMenuName = szMenuName;
|
|
|
|
XString xsTchtkwFile;
|
|
if(!FindFile(_T("shstkw.idx"), xsTchtkwFile)){
|
|
AfxMessageBox(_T("SYS目录下没有发行shstkw.idx文件!"));
|
|
return FALSE;
|
|
}
|
|
CString csTmp, csBuf, csTkwType, csTkwTmp;
|
|
CString csDwbPath, csDdblPath, csLib3dPath;
|
|
csDwbPath = g_sDwbPath;
|
|
csDdblPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\ddbl\\");
|
|
csLib3dPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\Lib3d\\");
|
|
|
|
FILE *fp=_tfopen(xsTchtkwFile, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
|
|
while(!feof(fp)) {
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T("") )
|
|
continue;
|
|
if(csBuf.Find(_T(':')) < 0 || csBuf.Find(_T('*')) < 0)
|
|
continue;
|
|
csTmp = csBuf.Mid(csBuf.Find(_T(':')) + 1,
|
|
csBuf.Find(_T('*')) - csBuf.Find(_T(':')) - 1);
|
|
if(csTmp == csMenuName){
|
|
csTkwType = csBuf.Left(csBuf.Find(_T(':')));
|
|
csTkwTmp = csBuf.Right(csBuf.GetLength() -csBuf.Find(_T('*')) - 1);
|
|
if(csTkwType == _T("0"))
|
|
csTkwFileName = csDwbPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType == _T("2"))
|
|
csTkwFileName = csDdblPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType==_T("3"))
|
|
csTkwFileName = csLib3dPath + csTkwTmp + _T(".tkw");
|
|
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
}
|
|
fclose(fp);
|
|
return FALSE;
|
|
}
|
|
//输入下拉菜单上得到的图库名称,返回相对于实际GJK全路径文件名
|
|
BOOL GetGjkwFileByMenu(const TCHAR* szMenuName, CString &csTkwFileName)
|
|
{
|
|
CString csMenuName = szMenuName;
|
|
XString xsTchtkwFile;
|
|
if(!FindFile(_T("shsgjk.idx"), xsTchtkwFile))
|
|
{
|
|
AfxMessageBox(_T("SYS目录下没有发行shsgjk.idx文件!"));
|
|
return FALSE;
|
|
}
|
|
CString csTmp, csBuf, csTkwType, csTkwTmp;
|
|
CString csDwbPath, csDdblPath, csLib3dPath;
|
|
csDwbPath = g_sDwbPath;
|
|
csDdblPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\ddbl\\");
|
|
csLib3dPath = csDwbPath.Left(csDwbPath.GetLength() - 5) + _T("\\Lib3d\\");
|
|
|
|
FILE *fp=_tfopen(xsTchtkwFile, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
|
|
while(!feof(fp))
|
|
{
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T(""))
|
|
continue;
|
|
if(csBuf.Find(_T(':')) < 0 || csBuf.Find(_T('*')) < 0)
|
|
continue;
|
|
csTmp = csBuf.Mid(csBuf.Find(_T(':')) + 1,
|
|
csBuf.Find(_T('*')) - csBuf.Find(_T(':')) - 1);
|
|
if(csTmp == csMenuName)
|
|
{
|
|
csTkwType = csBuf.Left(csBuf.Find(_T(':')));
|
|
csTkwTmp = csBuf.Right(csBuf.GetLength() -csBuf.Find(_T('*')) - 1);
|
|
if(csTkwType == _T("0"))
|
|
csTkwFileName = csDwbPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType == _T("2"))
|
|
csTkwFileName = csDdblPath + csTkwTmp + _T(".tkw");
|
|
else if(csTkwType==_T("3"))
|
|
csTkwFileName = csLib3dPath + csTkwTmp + _T(".tkw");
|
|
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
}
|
|
fclose(fp);
|
|
return FALSE;
|
|
}
|
|
// SYS//shstkw.idx 文件 返回下拉菜单显示条目
|
|
BOOL GetTchtkwAllItem(XStringList &lstTkwItem)
|
|
{
|
|
lstTkwItem.Reset();
|
|
XString xsTchtkwFile;
|
|
if(!FindFile(_T("shstkw.idx"), xsTchtkwFile))
|
|
{
|
|
AfxMessageBox(_T("SYS目录下没有发行shstkw.idx文件!"));
|
|
return FALSE;
|
|
}
|
|
CString csTmp, csBuf;
|
|
FILE *fp=_tfopen(xsTchtkwFile, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
|
|
while(!feof(fp)) {
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T("") )
|
|
continue;
|
|
if(csBuf == _T("#")){
|
|
lstTkwItem.Append(tstrnew(_T("#")));
|
|
continue;
|
|
}
|
|
if(csBuf.Find(_T(':')) < 0 || csBuf.Find(_T('*')) < 0)
|
|
continue;
|
|
csTmp = csBuf.Mid(csBuf.Find(_T(':')) + 1,
|
|
csBuf.Find(_T('*')) - csBuf.Find(_T(':')) - 1);
|
|
if(csTmp != _T(""))
|
|
lstTkwItem.Append(tstrnew(csTmp));
|
|
}
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
// SYS//shsgjk.idx 文件 返回下拉菜单显示条目
|
|
BOOL GetTchgjkAllItem(XStringList &lstTkwItem)
|
|
{
|
|
lstTkwItem.Reset();
|
|
XString xsTchtkwFile;
|
|
if(!FindFile(_T("shsgjk.idx"), xsTchtkwFile))
|
|
{
|
|
AfxMessageBox(_T("SYS目录下没有发行shstkw.idx文件!"));
|
|
return FALSE;
|
|
}
|
|
CString csTmp, csBuf;
|
|
FILE *fp=_tfopen(xsTchtkwFile, _T("r"));
|
|
if(!fp)
|
|
return FALSE;
|
|
|
|
while(!feof(fp)) {
|
|
TCHAR sBuf[256]=_T("");
|
|
_fgetts(sBuf, 255, fp);
|
|
csBuf = sBuf;
|
|
csBuf.TrimLeft();
|
|
csBuf.TrimRight();
|
|
if(csBuf == _T("") )
|
|
continue;
|
|
if(csBuf == _T("#")){
|
|
lstTkwItem.Append(tstrnew(_T("#")));
|
|
continue;
|
|
}
|
|
if(csBuf.Find(_T(':')) < 0 || csBuf.Find(_T('*')) < 0)
|
|
continue;
|
|
csTmp = csBuf.Mid(csBuf.Find(_T(':')) + 1,
|
|
csBuf.Find(_T('*')) - csBuf.Find(_T(':')) - 1);
|
|
if(csTmp != _T(""))
|
|
lstTkwItem.Append(tstrnew(csTmp));
|
|
}
|
|
fclose(fp);
|
|
return TRUE;
|
|
}
|
|
void TWBlock(PickSet &ss, const TCHAR* szFileName, XPoint ptIns)
|
|
{
|
|
AcDbObjectIdArray cloneSet;
|
|
|
|
long len = ss.Length();
|
|
for(long i=0;i<len;i++){
|
|
Entity ent = ss[i];
|
|
AcDbObjectId id;
|
|
acdbGetObjectId(id, ent);
|
|
cloneSet.append(id);
|
|
}
|
|
AcDbDatabase db;
|
|
AcDbObjectId idMSpace = db.currentSpaceId();
|
|
AcDbIdMapping idMap;
|
|
acdbCurDwg()->wblockCloneObjects(cloneSet, idMSpace, idMap, AcDb::kDrcIgnore, false);
|
|
AcDbBlockTable *pTable = NULL;
|
|
db.getBlockTable(pTable, AcDb::kForRead);
|
|
if(!pTable)
|
|
return;
|
|
|
|
AcGeMatrix3d mat;
|
|
mat.setToTranslation(AcGeVector3d(-ptIns[0], -ptIns[1], -ptIns[2]));
|
|
AcDbBlockTableRecord *pBlockTableRecord = NULL;
|
|
VERIFY(pTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,AcDb::kForRead)==Acad::eOk);
|
|
pTable->close();
|
|
if(!pBlockTableRecord)
|
|
return;
|
|
AcDbBlockTableRecordIterator* pBlockIterator = NULL;
|
|
|
|
pBlockTableRecord->newIterator(pBlockIterator);
|
|
if(!pBlockIterator){
|
|
pBlockTableRecord->close();
|
|
return;
|
|
}
|
|
for(pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step()) {
|
|
AcDbEntity *pEnt = NULL;
|
|
pBlockIterator->getEntity(pEnt,AcDb::kForWrite);
|
|
if(pEnt){
|
|
pEnt->setLayer(GetLayerIdFromString(_T("0"), &db));
|
|
pEnt->transformBy(mat);
|
|
pEnt->close();
|
|
}
|
|
}
|
|
delete pBlockIterator;
|
|
pBlockTableRecord->close();
|
|
#if (ADS>15)
|
|
acdbSaveAs2000(&db, szFileName);
|
|
#else
|
|
db.saveAs(szFileName);
|
|
#endif
|
|
}
|
|
|
|
|
|
CPoint Lcs2Mcs(XPoint point, BOOL bVector=FALSE)
|
|
{
|
|
CRect rect;
|
|
CPoint pt;
|
|
acedGetAcadDwgView()->GetClientRect(&rect);
|
|
|
|
pt.x = AS_INT(point.x*rect.Width());
|
|
if(!bVector) {
|
|
pt.y = rect.bottom - AS_INT(point.y*rect.Height());
|
|
} else {
|
|
pt.y = - AS_INT(point.y*rect.Height());
|
|
}
|
|
|
|
return pt;
|
|
}
|
|
|
|
void ReadVports(DList<TViewportInfo> &vpInfo) //读取视口信息
|
|
{
|
|
int nTileMode;
|
|
xg_getvar(_T("TILEMODE"), &nTileMode);
|
|
if (!nTileMode)
|
|
return;
|
|
struct resbuf *rb = NULL;
|
|
|
|
TViewportInfo vports;
|
|
BOOL flag = FALSE;
|
|
if (acedVports(&rb) != RTNORM)
|
|
return;
|
|
while (rb = rb->rbnext) {
|
|
if (rb->restype == RTSHORT) {
|
|
vports.VpID = rb->resval.rint;
|
|
flag = TRUE;
|
|
}
|
|
if (rb->restype == RTPOINT) {
|
|
if (flag) {
|
|
vports.ptLeft[X] = rb->resval.rpoint[0];
|
|
vports.ptLeft[Y] = rb->resval.rpoint[1];
|
|
vports.ptLeft[Z] = 0;
|
|
flag = FALSE;
|
|
}
|
|
else {
|
|
vports.ptRight[X] = rb->resval.rpoint[0];
|
|
vports.ptRight[Y] = rb->resval.rpoint[1];
|
|
vports.ptRight[Z] = 0;
|
|
vpInfo.Append(new TViewportInfo(vports));
|
|
}
|
|
}
|
|
}
|
|
if (rb)
|
|
ads_relrb(rb);
|
|
}
|
|
|
|
CRect GetVPRect(int cvport)
|
|
{
|
|
CWnd* pWndAcadView;
|
|
CRect rectVP;
|
|
pWndAcadView = acedGetAcadDwgView();
|
|
CRect rect;
|
|
pWndAcadView->GetClientRect(rect);
|
|
DList<TViewportInfo> ss;
|
|
ReadVports(ss);
|
|
long lCount = ss.Length();
|
|
for(long i=0L; i<lCount; i++) {
|
|
TViewportInfo &ent=*ss[i];
|
|
if(ent.VpID == cvport) {
|
|
XRectAngle box(ent.ptLeft, ent.ptRight);
|
|
XPoint ptCorners[4];
|
|
CPoint ptCorners2[4];
|
|
ptCorners[0]=box.GetLowLeft();
|
|
ptCorners[1]=box.GetLowRight();
|
|
ptCorners[2]=box.GetUpRight();
|
|
ptCorners[3]=box.GetUpLeft();
|
|
for(int n=0; n<4; n++) {
|
|
ptCorners2[n]=Lcs2Mcs(ptCorners[n]);
|
|
}
|
|
CRect rect2(ptCorners2[3], ptCorners2[1]);
|
|
rectVP = rect2;
|
|
return rectVP;
|
|
}
|
|
|
|
}
|
|
VERIFY(xg_getvar(_T("CVPORT"), &cvport)==RTNORM);
|
|
return GetVPRect(cvport);
|
|
}
|
|
|
|
|
|
|
|
|
|
void GetRectBmpFromBmp( CWnd *pWnd ,CRect rectClient, CBitmap &bitmap)
|
|
{
|
|
CClientDC dc(pWnd);
|
|
CDC memDC;
|
|
CRect rect;
|
|
rectClient.DeflateRect(2,2);
|
|
|
|
memDC.CreateCompatibleDC(&dc);
|
|
pWnd->GetWindowRect(rect);
|
|
bitmap.CreateCompatibleBitmap(&dc, rectClient.Width(), rectClient.Height());
|
|
|
|
CBitmap* pOldBitmap = memDC.SelectObject(&bitmap);
|
|
memDC.BitBlt(0, 0, rectClient.Width(),rectClient.Height(), &dc, rectClient.left,rectClient.top,SRCCOPY);
|
|
memDC.SelectObject(pOldBitmap);
|
|
|
|
}
|
|
|
|
void ReadXRenderData(Entity ent, CString &csName, CString &csMat)
|
|
{
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbEntity, pEnt);
|
|
if(!pEnt)
|
|
return;
|
|
resbuf *pxData = pEnt->xData(_T("TCH_GROUPNAME"));
|
|
if(pxData) {
|
|
resbuf *pNext = pxData->rbnext;
|
|
if(pNext && pNext->restype == 1000) {
|
|
csName = pNext->resval.rstring; //构件名称
|
|
pNext = pNext->rbnext;
|
|
if(pNext && pNext->restype == 1000)
|
|
csMat = pNext->resval.rstring; //材质
|
|
}
|
|
ads_relrb(pxData);
|
|
}
|
|
OPENOBJ_END();
|
|
}
|
|
|
|
void GetAShadePickSet(PickSet &ssMat, PickSet &ssSel)
|
|
{
|
|
XStringList lstMat;
|
|
long lenSel = ssSel.Length();
|
|
for(long i=0;i<lenSel;i++){
|
|
Entity ent = ssSel[i];
|
|
CString csTmp;
|
|
CString csMat;
|
|
ReadXRenderData(ent, csTmp, csMat);
|
|
if(lstMat.Index(csMat, FALSE) < 0)
|
|
lstMat.Append(tstrnew(csMat));
|
|
}
|
|
|
|
PickSet ss(SS_FREE);
|
|
RBList rbMask(RTDXF0, _T("INSERT"), 2, _T("RM_SDB"), NULL);
|
|
ss.Get(_T("X"), NULL, NULL, rbMask);
|
|
|
|
long length = ss.Length();
|
|
for(long j=0;j<length;j++){
|
|
Entity ent = ss[j];
|
|
BOOL bFlag = FALSE;
|
|
OPENOBJ_BEGIN(ent, AcDb::kForRead, AcDbBlockReference, pRef);
|
|
if(pRef){
|
|
resbuf *rb=pRef->xData(_T("AVE_MATERIAL"));
|
|
if(!rb)
|
|
continue;
|
|
RBList rbList(rb);
|
|
Groups *group=rbList.SearchNode(1000);
|
|
CString csMat = group->string; // group->string由RBList释放
|
|
for(int m=0;m<lstMat.Length();m++){
|
|
if(_tcsicmp(csMat, lstMat[m]) == 0){
|
|
bFlag = TRUE;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
OPENOBJ_END();
|
|
if(bFlag)
|
|
ssMat += ent;
|
|
}
|
|
}
|
|
|
|
|
|
BOOL SetLayerLocked(const TCHAR* szLayerName, BOOL bLock)
|
|
{
|
|
AcDbLayerTable *pLayertable = NULL;
|
|
AcDbLayerTableRecord *pLayerRec = NULL;
|
|
acdbCurDwg()->getLayerTable(pLayertable, AcDb::kForRead);
|
|
if(!pLayertable)
|
|
return FALSE;
|
|
|
|
if((pLayertable->getAt(szLayerName, pLayerRec, AcDb::kForWrite)) == Acad::eOk) {
|
|
if(bLock)
|
|
pLayerRec->setIsLocked(true); // 打开
|
|
else
|
|
pLayerRec->setIsLocked(false); // 关
|
|
pLayerRec->close();
|
|
pLayertable->close();
|
|
}
|
|
else
|
|
pLayertable->close();
|
|
return TRUE;
|
|
}
|
|
|
|
CString GetFileNameByAllName(const TCHAR* szAllFileName)
|
|
{
|
|
TCHAR szDrive[_MAX_DRIVE]=_T(""), szDir[_MAX_DIR]=_T(""), szFile[_MAX_FNAME]=_T(""), szExt[_MAX_EXT]=_T("");
|
|
_tsplitpath(szAllFileName, szDrive, szDir, szFile, szExt);
|
|
return CString(szFile);
|
|
}
|
|
|
|
CString GetPathNameByAllName(const TCHAR* szAllFileName)
|
|
{
|
|
TCHAR szDrive[_MAX_DRIVE]=_T(""), szDir[_MAX_DIR]=_T(""), szFile[_MAX_FNAME]=_T(""), szExt[_MAX_EXT]=_T("");
|
|
_tsplitpath(szAllFileName, szDrive, szDir, szFile, szExt);
|
|
XString csTmp = XString(_T("%s%s"), szDrive, szDir);
|
|
return CString((const TCHAR*)csTmp);
|
|
}
|
|
|
|
|
|
//从目录树中选取一个目录
|
|
BOOL GetFolderDia(XString &sFolder, CWnd *pParent, const TCHAR *pszTitle)
|
|
{
|
|
LPMALLOC pMalloc;
|
|
if (::SHGetMalloc(&pMalloc)!= NOERROR)
|
|
return FALSE;
|
|
|
|
BROWSEINFO bInfo;
|
|
LPITEMIDLIST pidl;
|
|
ZeroMemory ( (PVOID) &bInfo,sizeof (BROWSEINFO));
|
|
|
|
if (0) {
|
|
OLECHAR olePath[MAX_PATH];
|
|
ULONG chEaten;
|
|
ULONG dwAttributes;
|
|
HRESULT hr;
|
|
LPSHELLFOLDER pDesktopFolder;
|
|
//
|
|
// Get a pointer to the Desktop's IShellFolder interface.
|
|
//
|
|
if (SUCCEEDED(SHGetDesktopFolder(&pDesktopFolder))) {
|
|
//
|
|
// IShellFolder::ParseDisplayName requires the file name be in Unicode.
|
|
//
|
|
#ifndef _UNICODE
|
|
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, (const char *)sFolder, -1,
|
|
olePath, MAX_PATH);
|
|
#else
|
|
_tcscpy(olePath,sFolder);
|
|
#endif
|
|
|
|
//
|
|
// Convert the path to an ITEMIDLIST.
|
|
//
|
|
hr = pDesktopFolder->ParseDisplayName(NULL,
|
|
NULL,
|
|
olePath,
|
|
&chEaten,
|
|
&pidl,
|
|
&dwAttributes);
|
|
if (FAILED(hr)) {
|
|
pMalloc ->Free (pidl);
|
|
pMalloc ->Release ();
|
|
return FALSE;
|
|
}
|
|
bInfo.pidlRoot = pidl;
|
|
}
|
|
}
|
|
|
|
TCHAR szPath[1024]=_T("");
|
|
_tcscpy(szPath, sFolder);
|
|
bInfo.hwndOwner = pParent->GetSafeHwnd();
|
|
bInfo.pszDisplayName = szPath;
|
|
bInfo.lpszTitle = pszTitle;
|
|
bInfo.ulFlags = BIF_RETURNONLYFSDIRS;
|
|
bInfo.lpfn = NULL; //BrowseCtrlCallback; // address of callback function
|
|
bInfo.lParam = NULL; //(LPARAM)this; // pass address of object to callback function
|
|
|
|
if ((pidl = ::SHBrowseForFolder(&bInfo)) == NULL) {
|
|
pMalloc ->Release();
|
|
return FALSE;
|
|
}
|
|
|
|
if (::SHGetPathFromIDList(pidl,szPath) == FALSE) {
|
|
pMalloc ->Free(pidl);
|
|
pMalloc ->Release();
|
|
return FALSE;
|
|
}
|
|
|
|
_tcscat(szPath, _T("\\"));
|
|
sFolder=szPath;
|
|
|
|
|
|
pMalloc ->Free(pidl);
|
|
pMalloc ->Release();
|
|
return TRUE;
|
|
}
|