参考文章:https://blog.csdn.net/bmjhappy/article/details/91844221
https://blog.csdn.net/bmjhappy/article/details/91858791
需求:C++加载外部exe程序到窗口指定区域,并随窗口尺寸变化而变化
流程如下:
1、CreateProcess创建外部EXE进程
2、获取指定区域的坐标
3、查找进程的主窗口
4、将外部程序移到指定区域
5、调用ShowWindow显示窗口
6、获取窗口指定区域大小尺寸变化缩放exe的尺寸显示
实践代码部分:
//.h
#include "resource.h"
#include <afxwin.h>
#include "windows.h"
//CMy3DECGDlg.cpp
主程序如下:
//实践是将InitStart();放在BOOL CMy3DECGDlg::OnInitDialog()中执行
void CMy3DECGDlg::InitStart()
{
///****************************************************/
HANDLE handle=StartProcess(_T("D:\\**.exe"),_T(""));
Sleep(4000);//等待exe程序完全显示,酌情可删除
UpdateData(TRUE);
/*HWND */m_hwnd = NULL;//.定义为全局
CRect rc;
//GetDlgItem(IDC_CRT)->GetClientRect(&rc);
GetDlgItem(IDC_ECGVIEW)->GetWindowRect(&rc);//IDC_ECGVIEW静态文本控件ID
//m_EcgPic.GetWindowRect(&rc);
int nWidth = rc.Width();
int nHeight = rc.Height();
ScreenToClient(rc);
while(!m_hwnd)
{
//hwnd =::FindWindow("类名","窗口标题");
m_hwnd =::FindWindow (NULL,_T("Develop"));//Develop Configuration
}
if( m_hwnd)
{
LONG style=GetWindowLong(m_hwnd,GWL_STYLE);// 14CF 0000
style &=~WS_CAPTION;
style &=~WS_THICKFRAME;
//style |=WS_CHILD;//*
SetWindowLong(m_hwnd,GWL_STYLE,style);
::SetParent(m_hwnd,this->m_hWnd);
::MoveWindow(m_hwnd, rc.left+10, rc.top+10, nWidth-20, nHeight-20, true); //将外部程序移到自自身窗口里//*
::SetWindowPos(m_hwnd,HWND_TOP, rc.left+10, rc.top+10, nWidth-20, nHeight-20, SWP_SHOWWINDOW |SWP_HIDEWINDOW );
// ::BringWindowToTop(m_hwnd);//*
// Invalidate();//*
//::UpdateWindow(m_hwnd);//*
::ShowWindow(m_hwnd,SW_SHOW);
}
/***************************************************************************/
}
一、启动外部程序
StarProcess函数如