home *** CD-ROM | disk | FTP | other *** search
- // To use this style of Visio-driving,
- //
- // <1> make a new plain old Windows app with the wizard
- //
- // <2> add this file to the project
- //
- // <3> add the file vao_src\helpers.cpp to the project
- //
- // <4> set vao_inc as part of the project include paths
- //
- // <5> compile it and run it...
- //
-
- // Be sure to include <initguid.h> in *exactly one* source file in your project
- // before including visio.h. Grep on INITGUID in your system
- // include directories for more info.
-
- #include <windows.h>
- #include <ole2.h>
- #include <initguid.h>
-
- #include "visicpp.h"
-
- /**************************************************************************
- *+ Prototypes
- */
-
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow);
- IVApplication *GetVisioAppDual(void);
- int DoVisioAutomationSample(void);
-
- /**************************************************************************
- *+ WinMain
- */
-
- int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
- {
- int nRet= 0;
-
- if ( FAILED(OleInitialize(NULL)) )
- {
- nRet= 1;
- goto DONE;
- }
-
- nRet= DoVisioAutomationSample();
-
- OleUninitialize();
-
- DONE:
- return nRet;
- }
-
- /**************************************************************************
- *+ GetVisioApp
- */
-
- IVApplication *GetVisioAppDual(void)
- {
- HRESULT hr= NOERROR;
- IUnknown *pUnk= NULL;
- IVApplication *pApp= NULL;
-
- hr= GetActiveObject(CLSID_Application, NULL, &pUnk);
-
- if (pUnk!=NULL)
- {
- pUnk->QueryInterface(IID_IVApplication, (LPVOID *) &pApp);
- }
- else
- {
- hr= CoCreateInstance
- (
- CLSID_Application,
- NULL,
- CLSCTX_INPROC_SERVER | CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,
- IID_IVApplication,
- (LPVOID *) &pApp
- );
- }
-
- return pApp;
- }
-
- /**************************************************************************
- *+ DoVisioAutomationSample
- */
-
- int DoVisioAutomationSample(void)
- {
- int nRet= 2;
-
- CVisioApplication cvApp(GetVisioAppDual());
-
- if (cvApp.IsSet())
- {
- CVisioShape cvShape= cvApp.Documents().Add( VBstr("") ).Pages().Item( VVariant(1L) ).DrawRectangle(1.0, 2.0, 3.0, 4.0);
-
- if (cvShape.IsSet())
- nRet= 0; // Success!
- }
-
- return nRet;
- }
-