I have also copied and commented out the definitions for the relevant elements that we are going to create.
I hope that you fire up Visual Studio and try building this code; if you are impatient though and want to just run it, here is the dll.
Code Snippet - MyLine Command (A Complete Example)
- ////////////////////////////////////////////////////////////////////////////
- //
- // Written by: L. Lee Saunders
- // Date: 8/15/2010
- // (C)2010 BeerAndPretzelGames.com
- // All rights reserved
- //
- ////////////////////////////////////////////////////////////////////////////
- #include <windows.h>
- extern "C"
- {
- #include <XP.H>
- #include <Extend/Mysvc.h>
- }
- #define XPID 0xF000
- void XPCALL About(void);
- void XPCALL MYLINE(void);
- char CList[]="MYLINE\0";
- PCMDPROC PList[]={About,MYLINE};
- XP MyXP =
- { 0, CList, PList, 0, 0, 0, XPID, 0, 500, 0, 0, 500 };
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- FORMST(MyAPkt,"BLOG DLL commands:\n\n"
- "\tMYLINE - Duplicating the Line Command #s\n\0")
- void XPCALL About (void)
- {
- FormSt(&MyAPkt,RSC(FD_MsgBox));
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void XPCALL MYLINE2 (int Result,int Result2,int Result3);
- void XPCALL MYLINE3 (int Result,int Result2,int Result3);
- //This is the definition of LINE2
- //==========================================================================
- //typedef struct
- //{
- // CSTUFF CStuff; // entity properties
- // GLINE2 Line; // line properties
- //} LINE2;
- //This is the definition of GLINE2
- //==========================================================================
- //typedef struct
- //{
- // GPOINT2 p1; // starting point
- // GPOINT2 p2; // ending point
- //} GLINE2;
- //This is the definition of GPOINT2
- //==========================================================================
- //typedef struct
- //{
- // float x;
- // float y;
- //} GPOINT2;
- //This is the definition of CSTUFF
- //==========================================================================
- //typedef struct
- //{
- // int ERLen; // entity record length
- // unsigned char EType; // entity type code
- // char EFlags; // erase/select bits
- // char EFlags2; // extra flags
- // unsigned char EColor; // entity color
- // unsigned char EColor2; // fill (2nd) color
- // char EThick; // pen thickness 0..25.4 mm
- // short WPlane; // workplane (0 = XY plane)
- // short ELayer; // layer
- // short ELStyle; // line style (0=solid)
- // short GroupID; // group id (0 = not grouped)
- // short EFStyle; // fill style (0=hollow)
- // float LWidth; // line width
- // int Tag; // entity tag id
- //} CSTUFF;
- //This is the working structure that we will use to create all the lines
- LINE2 BuildL = {
- sizeof(LINE2), // entity record length
- ET_LINE2, // entity type code
- 0, // erase/select bits
- 0, // extra flags
- 1, // entity color
- 1, // fill (2nd) color
- 0, // pen thickness 0..25.4 mm
- 0, // workplane (0 = XY plane)
- 1, // layer
- 0, // line style (0=solid)
- 0, // group id (0 = not grouped)
- 0, // fill style (0=hollow)
- 0.0, // line width
- 0, // entity tag id
- 0.0, // starting point: x
- 0.0, // starting point: y
- 1.0, // ending point: x
- 1.0 // ending point: y
- };
- FORMST(lpszFirstPoint,"1st point:\0")
- FORMST(lpszNextPoint,"Next point:\0")
- RDATA P1Req =
- { sizeof(RDATA), RD_2DC, NULL, RDF_C, (DWORD*)&BuildL.Line.p1,
- (DWORD*)&lpszFirstPoint, RDC_XH, MYLINE2, NULL, NULL, 0, NULL, 0};
- RDATA P2Req =
- { sizeof(RDATA), RD_2DC, NULL, RDF_C, (DWORD*)&BuildL.Line.p2,
- (DWORD*)&lpszNextPoint, RDC_RBAND, MYLINE3, NULL, NULL, 0, NULL, 0};
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void XPCALL MYLINE (void)
- {
- ReqData(&P1Req); //get first point
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void XPCALL MYLINE2 (int Result,int Result2,int Result3)
- {
- if (Result != X_OK) { CmdEnd(); return; } //If we did not get valid info
- MarkUndoAdd(); //Enable Undo
- NewCsrOrg(BuildL.Line.p1.x, BuildL.Line.p1.y); //Set cursor origin
- ReqData(&P2Req); //Get next point
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- void XPCALL MYLINE3 (int Result,int Result2,int Result3)
- {
- pENTREC pEntRec; //Create a new drawing database entity
- if (Result != X_OK) { CmdEnd(); return; } //If we did not get valid info
- //This gets all the current stuff like current color and assigns it
- //to our line entity.
- GetCStuff(&BuildL.CStuff);
- //Append a copy of our line to the DB and return a pointer to the new
- //entity in the database. We assign it to pEntRec.
- pEntRec=DLApnd(NULL,(pENTREC)&BuildL);
- EDraw(pEntRec); //Draw our line
- ShowChanges(); //Needed for CC3 to "Show Changes" to the DB
- BuildL.Line.p1.x=BuildL.Line.p2.x; //move 2nd x to 1st x
- BuildL.Line.p1.y=BuildL.Line.p2.y; //move 2nd y to 1st y
- NewCsrOrg(BuildL.Line.p1.x,BuildL.Line.p1.y); //Set cursor origin
- ReqData(&P2Req); //Get next point
- }
- ////////////////////////////////////////////////////////////////////////////
- ////////////////// DllMain - XP initialization & Unload code ///////////
- BOOL WINAPI DllMain (HINSTANCE hDLL, DWORD dwReason, LPVOID lpReserved)
- {
- switch (dwReason)
- {
- case DLL_PROCESS_ATTACH:
- {
- MyXP.ModHdl=hDLL;
- XPRegCmd(&MyXP);
- break;
- }
- case DLL_PROCESS_DETACH:
- {
- XPUnregCmd(&MyXP);
- break;
- }
- }
- return TRUE;
- }
- ////////////////////////////////////////////////////////////////////////////
No comments:
Post a Comment