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

本文介绍了如何在MFC应用中启动第三方程序并将其移动到指定屏幕区域。主要涉及获取屏幕坐标、查找窗口句柄以及使用API函数如GetWindowRect、FindWindow、MoveWindow和SetWindowPos来实现窗口的移动和定位。
摘要由CSDN通过智能技术生成

流程如下:

1、CreateProcess创建外部EXE进程

2、获取指定区域的坐标

3、查找进程的主窗口

4、将外部程序移到指定区域

5、调用ShowWindow显示窗口


主程序如下:

handle=StartProcess("D:\\program tool\\SecureCRTPortable\\App\\SecureCRT\\SecureCRT.exe","");

	UpdateData(TRUE);  
    HWND hwnd = NULL;
	CRect rc;
	//GetDlgItem(IDC_CRT)->GetClientRect(&rc);
	GetDlgItem(IDC_CRT)->GetWindowRect(&rc);
	int nWidth = rc.Width();
	int nHeight = rc.Height();
	ScreenToClient(rc);

	while(!hwnd)
	{		
		hwnd =::FindWindow("VanDyke Software - SecureCRT","not connected - SecureCRT");
	}
	if( hwnd)
    {
        LONG style=GetWindowLong(hwnd,GWL_STYLE);// 14CF 0000
		
		style &=~WS_CAPTION;
		style &=~WS_THICKFRAME;
        //style |=WS_CHILD;
        SetWindowLong(hwnd,GWL_STYLE,style);

		 ::SetParent(hwnd,this->m_hWnd);
		//::MoveWindow(hwnd, rc.left, rc.top, nWidth, nHeight, true); //将外部程序移到自自身窗口里		
	    ::SetWindowPos(hwnd,HWND_TOP, rc.left, rc.top, nWidth, nHeight, SWP_SHOWWINDOW |SWP_HIDEWINDOW );
		// ::BringWindowToTop(hwnd);
		//Invalidate();
		//::UpdateWindow(hwnd);
		::ShowWindow(hwnd,SW_SHOW);
	}


一、启动外部程序

StarProcess函数如下:

HANDLE StartProcess(LPCTSTR program, LPCTSTR args)
{

     HANDLE hProcess = NULL;
     PROCESS_INFORMATION processInfo;
     STARTUPINFO startupInfo;
     ::ZeroMemory(&startupInfo, sizeof(startupInfo));
     startupInfo
  • 6
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值