找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 159|回复: 0

[每日一码] 如何创建自己的NEW命令 [复制链接]

[复制链接]

1

主题

0

回帖

43

积分

管理员

积分
43
发表于 2024-3-14 20:33:27 | 显示全部楼层 |阅读模式
  1. // NewDwg.cpp : Initialization functions
  2. #include "StdAfx.h"
  3. #include "StdArx.h"
  4. #include "resource.h"HINSTANCE 采用hdllInstance =NULL ;// This command registers an ARX command.
  5. void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
  6.     const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);// NOTE: DO NOT edit the following lines.
  7. //{{AFX采用ARX采用MSG
  8. void InitApplication();
  9. void UnloadApplication();
  10. //}}AFX采用ARX采用MSG// NOTE: DO NOT edit the following lines.
  11. //{{AFX采用ARX采用ADDIN采用FUNCS
  12. //}}AFX采用ARX采用ADDIN采用FUNCS
  13. /////////////////////////////////////////////////////////////////////////////
  14. // DLL Entry Point
  15. extern "C"
  16. BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
  17. {
  18.    if (dwReason == DLL采用PROCESS采用ATTACH){
  19.       采用hdllInstance = hInstance;
  20.    }
  21.    else if (dwReason == DLL采用PROCESS采用DETACH) {
  22.    }
  23.    return TRUE;    // ok
  24. } /////////////////////////////////////////////////////////////////////////////
  25. // ObjectARX EntryPoint
  26. extern "C" AcRx::AppRetCode
  27. acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
  28. {
  29.    switch (msg) {
  30.       case AcRx::kInitAppMsg:
  31.          // Comment out the following line if your
  32.          // application should be locked into memory
  33.          acrxDynamicLinker->unlockApplication(pkt);
  34.          acrxDynamicLinker->registerAppMDIAware(pkt);
  35.          InitApplication();
  36.          break;
  37.       case AcRx::kUnloadAppMsg:
  38.          UnloadApplication();
  39.          break;
  40.    }
  41.    return AcRx::kRetOK;
  42. }// Init this application. Register your
  43. // commands, reactors...
  44. void InitApplication()
  45. {
  46.    // NOTE: DO NOT edit the following lines.
  47.    //{{AFX采用ARX采用INIT
  48.    AddCommand("ASDKMYNEW", "MYNEW", "MYNEW", ACRX采用CMD采用MODAL, mynewmynew);
  49.    //}}AFX采用ARX采用INIT   // TODO: add your initialization functions}// Unload this application. Unregister all objects
  50. // registered in InitApplication.
  51. void UnloadApplication()
  52. {
  53.    // NOTE: DO NOT edit the following lines.
  54.    //{{AFX采用ARX采用EXIT
  55.    acedRegCmds->removeGroup("ASDKMYNEW");
  56.    //}}AFX采用ARX采用EXIT   // TODO: clean up your application
  57. }// This functions registers an ARX command.
  58. // It can be used to read the localized command name
  59. // from a string table stored in the resources.
  60. void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
  61.   const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
  62. {
  63.    char cmdLocRes[65];   // If idLocal is not -1, it's treated as an ID for
  64.    // a string stored in the resources.
  65.    if (idLocal != -1) {      // Load strings from the string table and register the command.
  66.       ::LoadString(采用hdllInstance, idLocal, cmdLocRes, 64);
  67.       acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc);   }
  68.    else
  69.       // idLocal is -1, so the 'hard coded'
  70.       // localized function name is used.
  71.       acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
  72. } // NewDwgCommands.cpp
  73. // ObjectARX defined command#include "StdAfx.h"
  74. #include "StdArx.h"// This is command 'MYNEW'
  75. [/it618postdisplay]
  76. 普通浏览复制代码
  77. void mynewmynew()
  78. {
  79.    // TODO: Implement the command
  80.    const TCHAR newFile[] = "Drawing.dwg";
  81.    const TCHAR dwtFile[] = "Template\\Acad.dwt";
  82.    TCHAR dwtPath [ MAX采用PATH ], *pLastSlash = NULL;
  83.    HMODULE hAcad = NULL;
  84.    // Get the Template file/pathname by:
  85.    //     get the pathname of the AutoCAD executable
  86.    //     find the final backslash
  87.    //     copy the template directory name and the template filename (e.g."Template\\Acad.dwt")
  88.    //       onto this path after the final backslash
  89.    // Copy this file to the destination path
  90.    // Open this file in the AutoCAD editor
  91.    if ( NULL == ( hAcad = ::GetModuleHandle (采用T("acad.exe"))))
  92.       acutPrintf( "\nCannot get handle to AutoCAD's executable!" );
  93.    else if ( !::GetModuleFileName( hAcad, dwtPath, MAX采用PATH ))
  94.       acutPrintf( "\nCannot get AutoCAD's location!" );
  95.    else if ( NULL == ( pLastSlash = strrchr( dwtPath, '\\' )))
  96.       acutPrintf( "\nCannot extract AutoCAD's path!" );
  97.    else if ( (pLastSlash - dwtPath) + strlen( dwtFile ) > MAX采用PATH )
  98.       acutPrintf( "\nPath too long to get template path!" );
  99.    else {
  100.       strcpy( pLastSlash + 1, dwtFile );
  101.       // Do not overwrite file if it already exists (could do further checking here)
  102.       if ( !::CopyFile( dwtPath, newFile, TRUE )){
  103.          // Cannot copy file for one reason or another (if error 80 then file exists)
  104.          DWORD dwErr = GetLastError();
  105.          acutPrintf( "\nCannot copy template file, failed with error %d",dwErr );
  106.          return;
  107.       }
  108.       // See solution 3615 if you need to clear the DBMOD system variable
  109.       if ( /*Adesk::kFalse == */acedSyncFileOpen( newFile ))
  110.          // Opening the newly copied file has failed/been cancelled
  111.          ::DeleteFile( newFile );
  112.    }
  113. }
复制代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|膜结构网

GMT+8, 2025-1-10 21:49 , Processed in 0.093805 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表