Sometimes need to do the framework integration of things, you need to integrate other clients like components into a client, similar to a software integration platform client, unified with a central management of the client to do similar to the control panel of the same thing to invoke different software. At this point, the corresponding different click-icon events must be embedded in the main interface. The following is a simple description of the computer program that is embedded in the system from the QT interface on the Windows platform.
First, the window class name to get the computer program, as long as the use of the VS Spy + + tool, in the VS menu "tools" after opening. Look for the window handle of the calculator and get to the specific class name.
Ctrl+f, the search handle, gets to the corresponding class name.
The handle of the Software process window is obtained through the Windows system function.
[CPP]View PlainCopy
- #include <Windows.h>
- Wid wid = (WID) FindWindow (L"Calcframe", L"calculator");
The first parameter in the interface is the class name, that is, in the interface "class" has a title, the second parameter is the window name, open "General", fill in the title, the software window name is "Calculator", fill in the parameters.
Iii. acquisition of Qwindow.
Qwindow*m_window;
m_window= Qwindow::fromwinid (WID);
M_window->setflags (M_window->flags () | Qt::customizewindowhint| Qt::windowtitlehint); This way you can set properties
Iv. Obtaining Agent Qwidget.
M_widget = Qwidget::createwindowcontainer (M_window, this->ui->widget); The second parameter is either the parent class of window or the layout
The code is shown below, and the code is placed in the constructor of a widget.
WinId.h
[CPP]View PlainCopy
- #pragma once
- #include <QtWidgets/QWidget>
- #include "Ui_winid.h"
- Class WinId: Public qwidget
- {
- Q_object
- Public
- WinId (Qwidget *parent = q_nullptr);
- ~winid ();
- Private
- Ui::winidclass *ui;
- };
WinId.cpp
[CPP]View PlainCopy
- #include "stdafx.h"
- #include "WinId.h"
- Winid::winid (Qwidget *parent)
- : Qwidget (parent), UI (new Ui::winidclass)
- {
- UI->SETUPUI (this);
- //Create process
- //qstring cmd= "C:/Program Files/r/r-3.3.1/bin/x64/rgui.exe";
- QString cmd = "C:/windows/system32/calc.exe";
- Startupinfo si = { sizeof (SI)};
- Process_information Pi;
- Si.dwflags = Startf_useshowwindow;
- Si.wshowwindow = true;
- bool BRet = CreateProcess (
- Null
- (LPWStr) cmd.tostdwstring (). C_STR (),
- Null
- Null
- FALSE,
- Create_new_console,
- Null
- NULL, &si, &PI);
- Sleep (5000);
- Wid wid = (WID) FindWindow (L"Calcframe", L"calculator");
- //wid wid = (WID) FindWindow (L "Rgui Workspace", NULL);
- Qwindow *m_window;
- M_window = Qwindow::fromwinid (WID);
- M_window->setflags (M_window->flags () | Qt::customizewindowhint | Qt::windowtitlehint); //
- Qwidget *m_widget;
- M_widget = Qwidget::createwindowcontainer (M_window, this->ui->widget);
- M_widget->setminimumsize (400, 300);
- }
- Winid::~winid ()
- {
- Delete UI;
- }
The final operating effect is as follows.
In addition to git, there is an example, the path is: https://github.com/snasoft/qt-windows-composition-example
http://blog.csdn.net/u013394556/article/details/78534833
External processes embedded in the QT process interface (using Qwindow::fromwinid)