MFC and ARX union develop perfect AutoCAD application program

  • Time:
  • Click:71
  • source:SCHOCH CNC Machining
One, foreword AutoCAD is application package of sweeping software of subdesign of general purpose computer. Begin from AutoCAD 13 version, autoDesk company rolled out a kind of new object-oriented software interface ARX (AutoCAD Runtime Extenstion) . This interface is development language with VC++ , ARX library is development tool, use object-oriented process designing method and supportive MFC process designing. So far developer people obtained a capacious sky to be able to use MFC already, can realize 2 development of AutoCAD again with union of ARX tool library. Microsoft foundation kind library (MFC) is C++ kind of the library patulous, it was offerred write beforehand in great quantities kind pile up with support, if make the window and processing news,can handle tasks of a lot of standard Windows process designing. If the toolbar, view that divide a window and OLE2 support,it also can mix complex character in the program. Because this uses MFC to be able to simplify,the program is written, make developer saves many encode to work. ARX is from AutoCAD   R13 edition begins peculiar object-oriented C++ to develop environment, function efficiency of powerful, operation is tall. Make clear through systematic application using in CAD, a lot of its new character can realize the function that a lot of original development environments realize hard, improve development efficiency. ARX is representing the development way of AutoCAD, the first selection tool that makes development of new generation application software. After Windows is rolled out, autoCAD developer people the friendly interface that seeks a kind of method to make its apply a program to have Windows already in effort all the time does not break its function again, but always fare badly, of ARX push the wish with old developer of be sent on a diplomatic mission to become a possibility. Be aimed at the problem of above, the article will be right if where,each fields that MFC uses in ARX application process are made one detailed discussion, give out the method that implementation MFC and development of ARX application union give perfect AutoCAD application order (article discussion is based on AutoCAD   R14, objectARX 2.

0 undertake) . 2, the MFC warehouse that because ARX application can be linked with trends already,MFC uses medium common issue in ARX is built together, the MFC library that also can link with the static state is built together, in ARX application so we can make full use of the advantage of MFC. We will divide a part to undertake discussion to a few common problems under. The MFC warehouse that dynamic link uses in using dynamic link or static link to apply in one ARX or the MFC library that the static state links are greatly what version differs in be being developed by applied process function and additional AutoCAD is harmonious between compare a decision. Developer should decide is the function that dynamic link brings version of advantageous more important harmonious still some is compiled implement the compiling that uses with place of current version AutoCAD implement consistency is more important. The ARX application that builds with the MFC library form of dynamic link and AutoCAD share same MFC trends to link a library, the application that the MFC library form that because this should apply,links than using a static state builds smaller, moving efficiency is taller. However it has however: ① .

Uses development is compiled implement must compile with what use compose to build AutoCAD implement version is identical ② .

The development of newest version is compiled implement the likelihood cannot use ③ .

In new the ARX application that builds with inchoate version in emission AutoCAD edition may misfire wait for defect. The ARX that the MFC library form that links as a result of the static state builds uses a MFC warehouse also to load arrived in the ARX application that each static state links, reason afore-mentioned issues are nonexistent to this kind of ARX application but this kind of application has however: ① .

Bigger memory requirement ② .

Traversal speed is slow (the commutative space that needs because of place is larger) wait for defect. Answer because of this developer balance advantages and disadvantages is made again accept or reject (the case that the article discusses dynamic link only, static link and dynamic link are very similar, the reader can consult corresponding development documentation) . MFC and always try not to make because of AutoCAD without mode dialog box window of systematic focusing Yu Jizi, reason ought to issue one request without mode dialog box. Inside one groovy intermittence, will receive WM_ACAD_KEEPFOCUS window information without mode dialog box (in Adscodes.

The definition in H is 1001) . When the dialog box receives this information, if wants to maintain focusing to should return TRUE, return FALSE otherwise (default is worth) , right now the mouse leaves dialog box system no longer focusing at the dialog box. The ON_MESSAGE in the message map in the dialog box () function is as follows: BEGIN_MESSAGE_MAP(HelloDlg, CDialog) ON_COMMAND(IDCLOSE, onClose) ON_COMMAND(IDC_DRAW_CIRCLE, onDrawCircle) ON_MESSAGE(WM_ACAD_KEEPFOCUS, onAcadKeepFocus) END_MESSAGE_MAP() uses a dialog box here kind for HelloDlg, it by Cdialog kind derive. Must be this message to write function of a handle when adding this one entry the message to reflect shoot. Assume we already wrote one function KeepFocus() , it returns TRUE when the dialog box wants to maintain focusing, return FALSE conversely criterion message sentence handle function should be: Afx_msg LONG HelloDlg: OnAcadKeepFocus(UINT, LONG) {Return KeepTheFocus() ? TRUE: FALSE; } 3, the project of the MFC that the MFC library that we will distribute a part to be linked to trends is being used in ARX under the MFC library that ARX application links at trends undertakes discussion trends linking installs a preexistence project option to be chosen " MFC AppWizard(DLL) " , choose Regular DLL Using Shared MFC DLL next, input project name to be in next " Project Settings " in the dialog box " General " label in " Microsoft Foundation Classes " region is chosen " Use MFC Ina Shared DLL For The Field.

" delete what build by AppWizard place.

Cpp, .

H project file, arxmfcdll.

Cpp and Resourcehelper.

H adds an item in (in Object ARX SDK ObjectArxutilsmfcextras catalog falls) in Link label in, "General " column " Output File Name " the applied process name after the input is compiled, suffixal for.

Arx is in Link label in, "Output " column, "Base Address " input " 01c000000 " , "Entry-point Symbol " input " DllEntryPoint@12 " in C/C++ label in, "Code Generation " column " Use Run-time Library " choose " Multithread DLL " in C/C++ label in, "Preprocessor " _WINDLL of the definition in column, _AFXDLL 2.

The initialization of MFC to carry out DLL initialization, dllMain() function ought to be transferred in AcrxEntryPoint() function, the method is shown as follows: Extern "C" AcRx: AppRetCode AcrxEntryPoint(AcRx: AppMsgCode   Msg, void* ) {Switch(Msg) {Case AcRx: KInitAppMsg: DllMain(_hdllInstance, DLL_PROCESS_ATTACH, NULL); File:// joins Break; Case AcRx of specific applied initialization code: UnloadAppMsg: DllMain(_hdllInstance, DLL_PROCESS_DETACH, NULL); Break; Default; Break; } Return AcRx: KRetOK; } developer needs to press only in front narrates method undertakes setting criterion above works all need not developer intervenes, developer needs to join corresponding user function only can. 3. Resource management is mixed in ARX application and AutoCAD when other application process uses the MFC warehouse that share, resource management becomes very serious. You must the applied process resource that clarity must have managed you, the resource that avoids it and AutoCAD or process of other ARX application produces conflict. Clear resource setting includes commonly the following 3 paces: Function AfxSetResourceHandle() is called to will define resource to set oneself when the measure that implements any resource that bring about MFC to search you be worth for systematic default. Setting systematic natural resources the application that is you before resource, call AfxGetResourceHandle() function to acquire a system current natural resources. After carrying out any requirements to use the function that defines resource oneself, immediately systematic natural resources reductive for the resource that saves before sentence handle. The AutoCAD API function that commands a handle to need to call a requirement to obtain AutoCAD resource in applied process dialog box (or call AutoCAD to command) when, we ought to set resource before transferring function above all for AutoCAD, after function is carried out, restore to use program resource again next (the resource that AcedGetAcadResourceInstance() function can obtain AutoCAD sentence handle) . To make resource management simpler we used a C++ kind CtemporaryResourceOverride (can find below Objectarxutilsmfcextras catalog) , when a this kinds object is built, the object sets systematic natural resources the applied resource that is you, when the object is deleted, analyse form function sets resource automatically for systematic natural resources. CtemporaryResourceOverride statement consults please the Afxmfcdll below Objectarxutilsmfcextras catalog.

Cpp file. 4.

Example wants to press in one dialog box now suppose " OK " the scale after pushbutton one circle, the ARX application implementation that uses MFC joins object ID to be the message map of ON_OK to use ClassWizard first, edit code Void CDiaTest next: File:// of   of   of OnOK() {HINSTANCE Hin_new; Hin_new=acedGetAcadResourceInstance(); obtains the resource CTemporaryResourceOverride *jxs; File:// of ACAD to define new target Jxs=new CTemporaryResourceOverride(hin_new) ;// to allocate memory for Jxs, and initialization CreateCircle();// draws round Delet Jxs;// to delete object CDialog: OnOK(); } AcDbObjectId CreateCircle() {AcGePoint3d Center(9.

0, 3.

0, 0.

0); AcGeVector3d Normal(0.

0, 0.

0, 1.

0); AcDbCircle *pCirc = New AcDbCircle(center, normal, 2.

0); AcDbBlockTable *pBlockTable; AcdbCurDwg()->getBlockTable(pBlockTable, acDb: KForRead); AcDbBlockTableRecord *pBlockTableRecord; PBlockTable->getAt(ACDB_MODEL_SPACE, PBlockTableRecord, acDb: KForWrite); PBlockTable->close(); AcDbObjectId CircleId; PBlockTableRecord->appendAcDbEntity(circleId, of process of application of PCirc); PBlockTableRecord->close(); PCirc->close(); Return CircleId; } ARX upgrade the ARX application of use MFC wants to be used in new edition AutoCAD must undertake upgrading, concrete move is as follows: Definition _WINDLL and _AFXDLL are used " Multithreaded DLL Runtime Library " (release edition) carry away existing ARX-MFC is felt board carry away code of existing DLL MFC initialization carries away any CwinApp kind derive object Arxmfcdll.

Cpp and Resourcehelper.

H adds an item, make adjust accordingly (these two files are inside Objectarxutilsmfcextras of ObjectARX SDK catalog) 4, the method that ARX and MFC union process designing used in the development of the mould CAD system that last word author is having, practice proves to use MFC to undertake the process designing of Windows style on one hand, use ARX to offer on the other hand kind arrive with function development AutoCAD system is internal, realize systematic function requirement, greatly rose to develop efficiency, undoubted this is AutoCAD developer people optimal choice. CNC Milling CNC Machining