乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 9|回复: 0

browse folder code .

[复制链接]

124

主题

837

帖子

9

银币

顶梁支柱

Rank: 50Rank: 50

铜币
1333
发表于 2003-11-26 11:38:00 | 显示全部楼层 |阅读模式
// Date: Nov 18, 2003
#include
#include
#include
#include
#include
#include
#include
// Header file for SHBrowseForFolder API function.
#include
#include
//#define MAX_PATH 500;;
int dofun();
int funcload();
// FUNCLOAD -- Define this application's external functions.
//                           Return RTERROR on error, else RTNORM.
static int funcload()
{
        if(!acedDefun("EXP_NEWLAYER", 0))
                return RTERROR;
        if(!acedDefun("EXP_BROWSEFOLDER", 1))
                return RTERROR;
}
void createNewLayer(char* lyrname, Adesk::UInt16 clr, AcDbObjectId ltypeId, Adesk::Boolean current)
{
        // We need to check if the layer name exists
        // If the layer name exists, apply the color
        // linetype id and whither to make it current
        // or not. In order to be current it cannot be
        // frozen, so we need to check for this also.
        // If the layer name does not exist we just create
        // a new layer with the properties contained in the arguments
        
        AcDbLayerTable *pLyrTable;
        AcDbLayerTableRecord *pLyrTblRecord;
        AcDbObjectId recId;
        AcCmColor color;
        color.setColorIndex(clr); // set color to parameter clr
        AcDbDatabase *pCurDb = NULL;
        pCurDb = acdbHostApplicationServices()->workingDatabase();
        pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
        // Check to see if the layer name exists
        if(pLyrTable->has(lyrname))
        {
                pLyrTable->getAt(lyrname, pLyrTblRecord, AcDb::kForWrite, Adesk::kFalse);
                // pLyrTblRecord now points at the layer table record
                // which was opened for write
                pLyrTblRecord->setIsFrozen(Adesk::kFalse);
                pLyrTblRecord->setColor(color);
                pLyrTblRecord->setLinetypeObjectId(ltypeId);
        }
        else
        {
                // Note how we can change the open mode
                // of the layer table from AcDb::kForRead
                // to AcDb::kForWrite
                pLyrTable->upgradeOpen();
                pLyrTblRecord = new AcDbLayerTableRecord;
                pLyrTblRecord->setName(lyrname);
                pLyrTblRecord->setColor(color);
                pLyrTblRecord->setLinetypeObjectId(ltypeId);
                pLyrTable->add(pLyrTblRecord);
        }
        // Get the layer Table ObjectId
        recId = pLyrTblRecord->objectId();
        pLyrTblRecord->close();
        pLyrTable->close();
        // Set the layer current if current
        // is equal to Adesk::kTrue
        // pCurDb is point to the current
        // drawing database
        // The database AcDbDatabase has a number of
        // query and edit functions for the header variables
        if(current)
        {
                pCurDb->setClayer(recId);
        }
}
// DOFUN -- Execute external function (called upon an RQSUBR request).
//          Return value from the function executed, RTNORM or RTERROR.
static int dofun()
{
        //char *lyrname = 0;
        char* lyrname = 0;
        int col = 0;
        char *ltype = 0;
        AcDbObjectId ltypeObjId;
    Adesk::Boolean current = 0;
        struct resbuf *rb;
        struct resbuf *rbTrav;
        struct resbuf *res_list;
        int val;
        int i = 0;
        // Declared variable for calling EXP_BROWSEFOLDER function
        char path[MAX_PATH];
        BROWSEINFO bi = {0};
        ITEMIDLIST *pidl;
        char *title = 0;
        // Get the function code and check that it's within range.
        if((val = acedGetFunCode()) restype)
                        {
                        case RTSTR:
                                if(i == 0)
                                        lyrname = rbTrav->resval.rstring;
                                else if(i == 2)
                                        ltype = rbTrav->resval.rstring;
                                break;
                        case RTSHORT:
                                if(i == 1)
                                        col = rbTrav->resval.rint;
                                else if(i == 3)
                                        current = rbTrav->resval.rint;
                                break;
                        default:
                                break;
                        }        // switch
                        rbTrav = rbTrav->rbnext;
                        i += 1;
                }        // while
                if((lyrname == NULL))
                        lyrname = "NONE_NAME";
                if((ltype == NULL)||(strcmp(ltype, "") == 0))
                        ltype = "CONTINUOUS";
                AcDbLinetypeTable *pLinetypeTbl;
                acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLinetypeTbl, AcDb::kForRead);
                pLinetypeTbl->getAt(ltype,ltypeObjId);
                createNewLayer(lyrname,col,ltypeObjId,current);
                // The following code frament constructs a list to return to AutoLISP
                res_list = acutBuildList(
                        RTSTR, lyrname,
                        RTSHORT, col,
                        RTSTR, ltype,
                        RTSHORT, current,
                        0);
                if(res_list == NULL)
                {
                        acdbFail("Couldn't create list!\n");
                        return NULL;
                }
                acedRetList(res_list);
                if(res_list != NULL)
                        acutRelRb(res_list);
                break;
                // other function codes.
                //
        case 1:
                while(rbTrav)
                {
                        switch(rbTrav->restype)
                        {
                        case RTSTR:
                                if (i == 0)
                                {
                                        title = rbTrav->resval.rstring;
                                }
                                break;
                        default:
                                break;
                        }        // switch
                        rbTrav = rbTrav->rbnext;
                        i += 1;
                }        // while
                if( title != NULL)
                {
                        //bi.pszDisplayName = title;
                        bi.lpszTitle = title;
                        bi.ulFlags = BIF_RETURNONLYFSDIRS;
                }
                else
                {
                        //bi.pszDisplayName = title;
                        bi.lpszTitle = "Select a directory";
                        bi.ulFlags = BIF_RETURNONLYFSDIRS;
                }
                bi.lpfn = NULL;
                bi.lParam = 0;
                bi.iImage = 0;
                bi.hwndOwner = NULL;
                bi.pidlRoot = NULL;
        pidl = SHBrowseForFolder( &bi );
                if( pidl!= NULL)
                {
                        // 获取目录路径
                        SHGetPathFromIDList(pidl, path);
                        //const char * pPath=(char*)path;
                        //如何转换lpwstr宽字节,到一般的字符串。
                        //MessageBox(NULL,cString,"ok",MB_OK);
                        //释放内存
                        IMalloc *imalloc = 0;
                        if(SUCCEEDED(SHGetMalloc(&imalloc)))
                        {
                                imalloc->Free(pidl);
                                imalloc->Release();
                        }
                }
                if( path )
            acedRetStr(path);
                break;
                // Other function codes.
        default:
                break;
        }        // switch
        return 0;
}
// DLL Entry Point -- This function replaces main() for an ObjectARX program.
extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
{
        switch(msg)
        {
        case AcRx::kInitAppMsg:
                acrxDynamicLinker->unlockApplication(pkt);
                acrxRegisterAppMDIAware(pkt);
                break;
        case AcRx::kInvkSubrMsg:
                dofun();
                break;
        case AcRx::kLoadDwgMsg:
                funcload();
                break;
        default:
                break;
        }
        return AcRx::kRetOK;
}

nfcaatym3am.gif

nfcaatym3am.gif
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-2-4 13:49 , Processed in 0.152704 second(s), 57 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表