|
- // NewDwg.cpp : Initialization functions
- #include "StdAfx.h"
- #include "StdArx.h"
- #include "resource.h"HINSTANCE 采用hdllInstance =NULL ;// This command registers an ARX command.
- void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
- const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal = -1);// NOTE: DO NOT edit the following lines.
- //{{AFX采用ARX采用MSG
- void InitApplication();
- void UnloadApplication();
- //}}AFX采用ARX采用MSG// NOTE: DO NOT edit the following lines.
- //{{AFX采用ARX采用ADDIN采用FUNCS
- //}}AFX采用ARX采用ADDIN采用FUNCS
- /////////////////////////////////////////////////////////////////////////////
- // DLL Entry Point
- extern "C"
- BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpReserved*/)
- {
- if (dwReason == DLL采用PROCESS采用ATTACH){
- 采用hdllInstance = hInstance;
- }
- else if (dwReason == DLL采用PROCESS采用DETACH) {
- }
- return TRUE; // ok
- } /////////////////////////////////////////////////////////////////////////////
- // ObjectARX EntryPoint
- extern "C" AcRx::AppRetCode
- acrxEntryPoint(AcRx::AppMsgCode msg, void* pkt)
- {
- switch (msg) {
- case AcRx::kInitAppMsg:
- // Comment out the following line if your
- // application should be locked into memory
- acrxDynamicLinker->unlockApplication(pkt);
- acrxDynamicLinker->registerAppMDIAware(pkt);
- InitApplication();
- break;
- case AcRx::kUnloadAppMsg:
- UnloadApplication();
- break;
- }
- return AcRx::kRetOK;
- }// Init this application. Register your
- // commands, reactors...
- void InitApplication()
- {
- // NOTE: DO NOT edit the following lines.
- //{{AFX采用ARX采用INIT
- AddCommand("ASDKMYNEW", "MYNEW", "MYNEW", ACRX采用CMD采用MODAL, mynewmynew);
- //}}AFX采用ARX采用INIT // TODO: add your initialization functions}// Unload this application. Unregister all objects
- // registered in InitApplication.
- void UnloadApplication()
- {
- // NOTE: DO NOT edit the following lines.
- //{{AFX采用ARX采用EXIT
- acedRegCmds->removeGroup("ASDKMYNEW");
- //}}AFX采用ARX采用EXIT // TODO: clean up your application
- }// This functions registers an ARX command.
- // It can be used to read the localized command name
- // from a string table stored in the resources.
- void AddCommand(const char* cmdGroup, const char* cmdInt, const char* cmdLoc,
- const int cmdFlags, const AcRxFunctionPtr cmdProc, const int idLocal)
- {
- char cmdLocRes[65]; // If idLocal is not -1, it's treated as an ID for
- // a string stored in the resources.
- if (idLocal != -1) { // Load strings from the string table and register the command.
- ::LoadString(采用hdllInstance, idLocal, cmdLocRes, 64);
- acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLocRes, cmdFlags, cmdProc); }
- else
- // idLocal is -1, so the 'hard coded'
- // localized function name is used.
- acedRegCmds->addCommand(cmdGroup, cmdInt, cmdLoc, cmdFlags, cmdProc);
- } // NewDwgCommands.cpp
- // ObjectARX defined command#include "StdAfx.h"
- #include "StdArx.h"// This is command 'MYNEW'
- [/it618postdisplay]
- 普通浏览复制代码
- void mynewmynew()
- {
- // TODO: Implement the command
- const TCHAR newFile[] = "Drawing.dwg";
- const TCHAR dwtFile[] = "Template\\Acad.dwt";
- TCHAR dwtPath [ MAX采用PATH ], *pLastSlash = NULL;
- HMODULE hAcad = NULL;
- // Get the Template file/pathname by:
- // get the pathname of the AutoCAD executable
- // find the final backslash
- // copy the template directory name and the template filename (e.g."Template\\Acad.dwt")
- // onto this path after the final backslash
- // Copy this file to the destination path
- // Open this file in the AutoCAD editor
- if ( NULL == ( hAcad = ::GetModuleHandle (采用T("acad.exe"))))
- acutPrintf( "\nCannot get handle to AutoCAD's executable!" );
- else if ( !::GetModuleFileName( hAcad, dwtPath, MAX采用PATH ))
- acutPrintf( "\nCannot get AutoCAD's location!" );
- else if ( NULL == ( pLastSlash = strrchr( dwtPath, '\\' )))
- acutPrintf( "\nCannot extract AutoCAD's path!" );
- else if ( (pLastSlash - dwtPath) + strlen( dwtFile ) > MAX采用PATH )
- acutPrintf( "\nPath too long to get template path!" );
- else {
- strcpy( pLastSlash + 1, dwtFile );
- // Do not overwrite file if it already exists (could do further checking here)
- if ( !::CopyFile( dwtPath, newFile, TRUE )){
- // Cannot copy file for one reason or another (if error 80 then file exists)
- DWORD dwErr = GetLastError();
- acutPrintf( "\nCannot copy template file, failed with error %d",dwErr );
- return;
- }
- // See solution 3615 if you need to clear the DBMOD system variable
- if ( /*Adesk::kFalse == */acedSyncFileOpen( newFile ))
- // Opening the newly copied file has failed/been cancelled
- ::DeleteFile( newFile );
- }
- }
复制代码 |
|