- 积分
- 42
- 注册时间
- 2005-10-22
- 仿真币
-
- 最后登录
- 1970-1-1
|
楼主 |
发表于 2007-12-4 20:40:56
|
显示全部楼层
来自 湖北武汉
基于MATLAB6.5,对7.X有启发。希望把什么寻找窗体,嵌入VC的工作扔掉吧!
至于其他功能,参照本帖,酌情加入
单文档MFC EXE
View类h,Include,定义
public:
CMatGraph m_MatAxes ;
View类cpp,OnInitialUpdate()中,创建
m_MatAxes.Create(this,0,0,1,1) ;
View类cpp,OnSize(UINT nType, int cx, int cy)中,
m_MatAxes.OnSize();
类头文件MatGraph.hpp
- #include "matlab.hpp"
- #include "libmwsglm.hpp"
- #include "libmatlb.hpp"
- #include "mwservices.h"
- #include "libmatlbm.hpp"
- class CMatGraph
- {
- public:
- CMatGraph() ;
- virtual ~CMatGraph() ;
- private:
- mwArray m_hFigure ;
- CWnd *m_wParentWnd ;
- HWND m_HwndFig ;
- bool m_bIniStart ;
- double m_dPosition[4] ;
- public:
- void Create(CWnd *mHPar,
- double dPox ,double dPoy,
- double dWdith ,double dHeight );
- void OnSize() ;
- };
复制代码
类实现文件MatGraph.cpp
- #include "stdafx.h"
- #include "MatGraph.hpp"
- CMatGraph::CMatGraph()
- {
- libmmfileInitialize() ;
- libmwsglmInitialize() ;
- int argc ;
- argc=0 ;
- const char *p = NULL ;
- mlfHGInitialize(&argc,&p) ;
- m_hFigure=Nfigure(1,"name" , "Figure" ,
- "numbertitle" , "off" ,
- "color" , "w" ,
- "visible" , "off" ) ;
- m_bIniStart = false ;
- }
- CMatGraph::~CMatGraph()
- {
- if (tobool(ishandle(m_hFigure)))
- {
- delete_func(mwVarargin(m_hFigure));
- }
- mlfHGWaitForFiguresToDie() ;
- mlfHGTerminate() ;
- libmmfileTerminate() ;
- libmwsglmTerminate() ;
- }
- void CMatGraph::Create(CWnd *mHPar,
- double dPox ,double dPoy,
- double dWdith ,double dHeight )
- {
- HWND hFig = ::FindWindow(NULL,"Figure") ;
- long lStyle = ::GetWindowLong(hFig,GWL_STYLE) ;
- ::SetWindowLong(hFig,GWL_STYLE,
- lStyle &(~WS_CAPTION) & (~WS_THICKFRAME));
- ::SetParent(hFig,mHPar->GetSafeHwnd()) ;
- Vset(m_hFigure,"visible" ,"on") ;
- Vaxes("parent",m_hFigure);
- m_bIniStart = true ;
- m_wParentWnd = mHPar ;
- m_HwndFig = hFig ;
- m_dPosition[0] = dPox ;
- m_dPosition[1] = dPoy ;
- m_dPosition[2] = dWdith ;
- m_dPosition[3] = dHeight ;
- OnSize() ;
- drawnow(mwArray::DIN) ;
- }
- void CMatGraph::OnSize()
- {
- if(m_bIniStart)
- {
- RECT PlotRec ;
- m_wParentWnd->GetWindowRect(&PlotRec) ;
- long Width = PlotRec.right - PlotRec.left ;
- long Height = PlotRec.bottom - PlotRec.top ;
- mwArray Position = ones(1,4) ;
- Position(1) = 0 ;
- Position(2) = 0 ;
- Position(3) = Width*m_dPosition[2] ;
- Position(4) = Height*m_dPosition[3] ;
- Vset(m_hFigure,"visible" ,"on",
- "units" ,"pixels",
- "Position" ,Position) ;
- ::SetWindowPos(m_HwndFig, NULL,
- int(Width*m_dPosition[0]),
- int(Height*m_dPosition[1]),
- int(Width*m_dPosition[2]),
- int(Height*m_dPosition[3]),
- SWP_NOZORDER | SWP_NOACTIVATE);
- }
- }
复制代码
[ 本帖最后由 shunfly 于 2007-12-4 20:43 编辑 ] |
|