External processes embedded in the QT process interface (using Qwindow::fromwinid)

Source: Internet
Author: User

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
    1. #include <Windows.h>
    2. 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
  1. #pragma once
  2. #include <QtWidgets/QWidget>
  3. #include "Ui_winid.h"
  4. Class WinId: Public qwidget
  5. {
  6. Q_object
  7. Public
  8. WinId (Qwidget *parent = q_nullptr);
  9. ~winid ();
  10. Private
  11. Ui::winidclass *ui;
  12. };

WinId.cpp

[CPP]View PlainCopy
  1. #include "stdafx.h"
  2. #include "WinId.h"
  3. Winid::winid (Qwidget *parent)
  4. : Qwidget (parent), UI (new Ui::winidclass)
  5. {
  6. UI->SETUPUI (this);
  7. //Create process
  8. //qstring cmd= "C:/Program Files/r/r-3.3.1/bin/x64/rgui.exe";
  9. QString cmd = "C:/windows/system32/calc.exe";
  10. Startupinfo si = { sizeof (SI)};
  11. Process_information Pi;
  12. Si.dwflags = Startf_useshowwindow;
  13. Si.wshowwindow = true;
  14. bool BRet = CreateProcess (
  15. Null
  16. (LPWStr) cmd.tostdwstring (). C_STR (),
  17. Null
  18. Null
  19. FALSE,
  20. Create_new_console,
  21. Null
  22. NULL, &si, &PI);
  23. Sleep (5000);
  24. Wid wid = (WID) FindWindow (L"Calcframe", L"calculator");
  25. //wid wid = (WID) FindWindow (L "Rgui Workspace", NULL);
  26. Qwindow *m_window;
  27. M_window = Qwindow::fromwinid (WID);
  28. M_window->setflags (M_window->flags () | Qt::customizewindowhint | Qt::windowtitlehint); //  
  29. Qwidget *m_widget;
  30. M_widget = Qwidget::createwindowcontainer (M_window, this->ui->widget);
  31. M_widget->setminimumsize (400, 300);
  32. }
  33. Winid::~winid ()
  34. {
  35. Delete UI;
  36. }

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.