home *** CD-ROM | disk | FTP | other *** search
- // To use this style of Visio-driving with an MFC app,
- //
- // <1> make sure OLE Automation has been enabled in your app
- // (there's a check box for this at app wizard
- // project creation time)
- //
- // <2> add this file to your MFC project
- //
- // <3> add "visimfc.cpp" to your MFC project
- //
- // <4> step on the gas!
- //
- // ...oh yeah, and don't forget to call the function DoVisioAutomationSample
- // from InitInstance or in response to a menu choice...
- //
-
- #include "stdafx.h"
-
- #include "visimfc.h"
-
- int DoVisioAutomationSample(void);
-
- int DoVisioAutomationSample(void)
- {
- CLSID visio_clsid=
- { 0x00021a20, 0x0000, 0x0000, { 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
-
- IUnknown *pUnk= NULL;
- Application app;
- Documents docs;
- Document doc;
- Pages pages;
- Page page;
- Shape shape;
-
-
- GetActiveObject(visio_clsid, NULL, &pUnk);
-
- IDispatch *pDisp= NULL;
- if (pUnk!=NULL)
- pUnk->QueryInterface(IID_IDispatch, (LPVOID *) &pDisp);
-
- if (pDisp==NULL)
- app.CreateDispatch(visio_clsid);
- else
- app.AttachDispatch(pDisp);
-
- docs.AttachDispatch(app.GetDocuments());
- doc.AttachDispatch(docs.Add(""));
- pages.AttachDispatch(doc.GetPages());
- page.AttachDispatch(pages.GetItem(COleVariant(1L)));
- shape.AttachDispatch(page.DrawRectangle(1.0, 2.0, 3.0, 4.0));
-
- return 0;
- }
-