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

📄 testsincplot_dllview.cpp

📁 VC++中调用Matlab .m函数编译后的动态链接库
💻 CPP
字号:
// testsincplot_dllView.cpp : implementation of the CTestsincplot_dllView class
//

#include "stdafx.h"
#include "testsincplot_dll.h"

#include "testsincplot_dllDoc.h"
#include "testsincplot_dllView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CTestsincplot_dllView

IMPLEMENT_DYNCREATE(CTestsincplot_dllView, CView)

BEGIN_MESSAGE_MAP(CTestsincplot_dllView, CView)
	//{{AFX_MSG_MAP(CTestsincplot_dllView)
	ON_COMMAND(ID_PLOTSINC, OnPlotsinc)
	ON_COMMAND(ID_PLOTINVIEW, OnPlotinview)
	ON_WM_SIZE()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTestsincplot_dllView construction/destruction

CTestsincplot_dllView::CTestsincplot_dllView()
{
	// TODO: add construction code here
	libsincplotInitialize();
	this->pArrayIn=NULL;
	this->pArrayOut=NULL;
}

CTestsincplot_dllView::~CTestsincplot_dllView()
{
	if(pArrayIn)
	{
		mxDestroyArray(pArrayIn);
	}
	if(pArrayOut)
	{
		mxDestroyArray(pArrayOut);
	}
	libsincplotTerminate();	
}

BOOL CTestsincplot_dllView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CTestsincplot_dllView drawing

void CTestsincplot_dllView::OnDraw(CDC* pDC)
{
	CTestsincplot_dllDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	if(pArrayOut!=NULL)
	{
		int i=0;
		int j=0,k=0;
		CString testStr;
		for(i=0;i<mxGetNumberOfElements(pArrayOut);i++)
		{
			testStr.Format("%6.2f",*(mxGetPr(pArrayOut)+i));			
			pDC->TextOut(5+j*40,5+k*15,testStr);
			j++;
			if(j>20) 
			{
				j=0;
				k++;
			}
		}
	}
}

/////////////////////////////////////////////////////////////////////////////
// CTestsincplot_dllView printing

BOOL CTestsincplot_dllView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CTestsincplot_dllView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CTestsincplot_dllView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CTestsincplot_dllView diagnostics

#ifdef _DEBUG
void CTestsincplot_dllView::AssertValid() const
{
	CView::AssertValid();
}

void CTestsincplot_dllView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CTestsincplot_dllDoc* CTestsincplot_dllView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestsincplot_dllDoc)));
	return (CTestsincplot_dllDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CTestsincplot_dllView message handlers

void CTestsincplot_dllView::OnPlotsinc() 
{
	// TODO: Add your command handler code here	
	if(pArrayIn==NULL)
	{
		pArrayIn = mxCreateDoubleMatrix(1,1,mxREAL);		
	}
	//构造一个[3 10]的随机的输入参数
	*(mxGetPr(pArrayIn))=10*(0.3+0.7*rand()*1.0/RAND_MAX);
	mlxSincplot(1,&pArrayOut,1,&pArrayIn);
	CDC * pDC = GetDC();
	int i=0;
	int j=0,k=0;
	CString testStr;
	for(i=0;i<mxGetNumberOfElements(pArrayOut);i++)
	{
		testStr.Format("%6.2f",*(mxGetPr(pArrayOut)+i));			
		pDC->TextOut(5+j*40,5+k*15,testStr);
		j++;
		if(j>20) 
		{
			j=0;
			k++;
		}
	}
}

void CTestsincplot_dllView::OnPlotinview() 
{
	// TODO: Add your command handler code here	
	m_plotH = ::FindWindow(NULL,"Figure No. 1");
	if(::IsWindow(m_plotH))
	{		
		//将CTestsincplot_dllView设为MATLAB窗口的父窗口
		::SetParent(m_plotH,this->GetSafeHwnd());
		CWnd * pWnd = NULL;		
		pWnd = FromHandle(m_plotH);
		CRect rect;
		GetClientRect(&rect);
		pWnd->MoveWindow(&rect,false);
		pWnd->ModifyStyle(WS_CAPTION|WS_BORDER,WS_MAXIMIZE,0);		
	}
}

void CTestsincplot_dllView::OnSize(UINT nType, int cx, int cy) 
{
	CView::OnSize(nType, cx, cy);
	
	// TODO: Add your message handler code here
	if(::IsWindow(m_plotH))
	{
		::MoveWindow(m_plotH,0,0,cx,cy,true);
	}
}

⌨️ 快捷键说明

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