⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 visioapp.cpp

📁 vc++与visio 安装VISIO office(推荐2003以上版本)必须安装visio office 否则程序无法运行 安装VisioSDK(推荐2003以上版本) 默认安装路径为<
💻 CPP
字号:
#include "stdafx.h"
#include "VisioApp.h"

bool CVisioApp::Initial()
{
	/*******初始化***********/
	HRESULT    hr= NOERROR;
	
	::OleInitialize(NULL);
	
	if (VAO_SUCCESS != vaoGetObjectWrap(m_app)){
		MessageBox(NULL, "Can not get the Visio Application!\n\nHave you install the Visio Application?","Error",MB_OK);
		return false;
	}
	hr= m_app.Documents(m_docs);
	if (!SUCCEEDED(hr)){
		MessageBox(NULL, "Can not get the Visio Documents!\n\nPlease close all visio windows,and retry!","Error",MB_OK);
		return false;
	}
	//创建模具文件(就是图形库,里面包含各种图形,BASFLO_M.vss是基本流程图的模具
	
	VBstr vss_name(_T("BASFLO_M.vss"));
    hr= m_docs.Add(vss_name, m_stencildoc);
	if (!SUCCEEDED(hr)){
		MessageBox(NULL, "Can not get the Visio Stencil Documents!\n\nCan not crete Visio chart!","Error",MB_OK);
		return false;
	}
	//创建模板文件(就是创建一个画布,以后会在里面画图,BASFLO_M.vst是基本流程图的画布)
	VBstr vst_name(_T("BASFLO_M.VST"));
    hr= m_docs.Add(vst_name, m_templatedoc);
	if (!SUCCEEDED(hr)){
		MessageBox(NULL, "Can not get the Visio Stencil Documents!\n\nCan not crete Visio chart!","Error",MB_OK);
		return false;
	}
	//创建pages
	hr=m_templatedoc.Pages(m_pages);
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "Can not get the Visio Pages !\n\nCan not crete Visio chart!","Error",MB_OK);
		return false;
	}
	//创建Masters
	hr= m_stencildoc.Masters(m_masters);
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "Can not get the Visio Master !\n\nCan not crete Visio chart!","Error",MB_OK);
		return false;
	}

	/*******初始化结束********/
	return true;
}

bool CVisioApp::draw()
{
	this->Initial();
	//draw
	HRESULT    hr= NOERROR;
	CVisioPage page;	
	m_pages.Item(VVariant(1L),page);

	CVisioMaster master;
	m_masters.Item(VVariant("进程"),master);
	CVisioShape shape;
	page.Drop(master,4,11,shape);
	//setShapeText(shape,"开始");
	//
	//shape.DrawRectangle(1.0,2.0,3,3,shape);
	
	//connect
	CVisioMaster connectMaster;
	CVisioShape connectShape;
	
	m_masters.Item(VVariant("动态连接线"),connectMaster);
	page.Drop(connectMaster,4,10,connectShape);

	//connect pin to BeginX
	CVisioCell pinCell;
	hr = shape.Cells(VBstr("Connections.X1"), pinCell);	
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "start - Connections.X3!","Error",MB_OK);
		return false;
	}

	CVisioCell begCell;
	hr = connectShape.Cells(VBstr("BeginX"), begCell);	
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "begin!","Error",MB_OK);
		return false;
	}
	hr = begCell.GlueTo(pinCell);
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "GlueTo error!","Error",MB_OK);
		return false;
	}

	////edn
	CVisioMaster endMaster;
	m_masters.Item(VVariant("终结符"),endMaster);
	CVisioShape endShape;
	page.Drop(endMaster,4,4,endShape);
	
	//setShapeText(endShape,"结束");
	CVisioCell endPinCell;
	hr = endShape.Cells(VBstr("Connections.X2"), endPinCell);
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "end Connections.X4!","Error",MB_OK);
		return false;
	}

	CVisioCell endCell;
	hr = connectShape.Cells(VBstr("EndX"), endCell);	
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "begin!","Error",MB_OK);
		return false;
	}
	hr = endCell.GlueTo(endPinCell);
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "GlueTo error!","Error",MB_OK);
		return false;
	}
	
	hr=m_templatedoc.SaveAs(VBstr(_T("d:\\other.vsd")),new short);
	if ( !SUCCEEDED(hr) ){
		MessageBox(NULL, "SaveError!","Error",MB_OK);
		return false;
	}
	return true;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -