MFC窗体中打开第三方exe程序到指定区域(二)

参考文章: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函数如

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值