16,551
社区成员
发帖
与我相关
我的任务
分享
if( !myfunInitialize())
{
MessageBox(_T("初始化失败"));
}
fun();//这个函数就是matlab窗体生成的函数
// terminate MCR
mclTerminateApplication();
CString wnd_name = "Topo Image";
HWND hFig=::FindWindow(NULL,wnd_name);//wnd_name为matlab figure的名称,
//此处需循环多次才能得到句柄,不知为啥
while(hFig==NULL)
{
hFig=::FindWindow(NULL,wnd_name);
}
long IStyle=::GetWindowLong(hFig,GWL_STYLE); //获得figure的属性
::SetWindowLong(hFig,GWL_STYLE,IStyle&(~WS_CAPTION));//设置figure的属性,去掉标题栏
CRect figure_rect;
CWnd *myfigure=GetDlgItem(IDC_STATIC_MATLABWND);
myfigure->GetWindowRect(&figure_rect);
long fig_width=figure_rect.Width();
long fig_height=figure_rect.Height();
::SetParent(hFig,myfigure->GetSafeHwnd());//设置figure的父窗口
::SetWindowPos(hFig,NULL,0,0,fig_width,fig_height,SWP_NOZORDER|SWP_NOACTIVATE);//
::ShowWindow(hFig,SW_SHOW); //显示设置完后的figure
::SetForegroundWindow(this->m_hWnd);
void Cmdi_matlab_movewindow20140810View::OnMatlab()
{
// TODO: 在此添加命令处理程序代码
if( !myfunInitialize())
{
MessageBox(_T("初始化失败"));
}
fun();
// terminate MCR
mclTerminateApplication();
CString wnd_name = "Topo Image";
HWND hFig=::FindWindow(NULL,wnd_name);//wnd_name为matlab figure的名称,
//此处需循环多次才能得到句柄,不知为啥
while(hFig==NULL)
{
hFig=::FindWindow(NULL,wnd_name);
}
//::ShowWindow(hFig, SW_HIDE);
ModifyStyle(hFig,WS_POPUP,WS_CHILD,NULL);
long IStyle=::GetWindowLong(hFig,GWL_STYLE); //获得figure的属性
//ModifyStyle(hFig,WS_POPUP,WS_CHILD,NULL);
//CWnd* pMainWnd =AfxGetMainWnd();
//CRect client_rect;
CRect figure_rect;
CWnd *myfigure = GetDlgItem(IDC_STATIC_MATLABWND);
myfigure->GetClientRect(&figure_rect);
//pMainWnd->GetClientRect(&client_rect);
long fig_width=figure_rect.Width();
long fig_height=figure_rect.Height();
//long client_width = client_rect.Width();
//long client_height = client_rect.Height();
::SetParent(hFig,myfigure->GetSafeHwnd());//设置figure的父窗口
::SetWindowLong(hFig,GWL_STYLE,IStyle & (~WS_CAPTION) & (~WS_THICKFRAME));//设置figure的属性,去掉标题栏
::SetWindowPos(hFig,NULL,0,0,fig_width,fig_height,SWP_NOZORDER|SWP_NOACTIVATE);//
//::SetWindowPos(myfigure->GetSafeHwnd(),HWND_TOP,0,0,fig_width,fig_height,SWP_NOZORDER);
::ShowWindow(hFig,SW_SHOW); //显示设置完后的figure
::SetForegroundWindow(this->m_hWnd);
//::UpdateWindow(hFig); //刷新
//::UpdateWindow(myfigure->m_hWnd); //刷新
//CWnd* pMainWnd =AfxGetMainWnd();
//::UpdateWindow(pMainWnd->m_hWnd); //刷新
}
跟上面代码主要就是这个代码里面属性改了改:
::SetWindowLong(hFig,GWL_STYLE,IStyle & (~WS_CAPTION) & (~WS_THICKFRAME));//
完后matlab代码这样写,先隐藏一个figure完后,再显示:
figure('NumberTitle','off','menubar','none','toolbar','none','name','Topo Image','Visible','off');
x=0:pi/100:2*pi;
y=2*exp(-0.5*x).*sin(2*pi*x);
plot(x,y)
figure(1);