Recent

Author Topic: External program in my form  (Read 3476 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
External program in my form
« on: March 30, 2017, 03:58:12 pm »
Hello guys, a question. If I wanted to launch an external programa but both graphically within my form, can be done? There is a component to see the execution of the external program as if it were inside a canvas? And you can interact? Thank you
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1575
    • Lebeau Software
Re: External program in my form
« Reply #1 on: March 31, 2017, 07:07:44 am »
If I wanted to launch an external programa but both graphically within my form, can be done? There is a component to see the execution of the external program as if it were inside a canvas? And you can interact?

I don't know about cross-platform, but on Windows at least, it is *possible*.  You would first have to retrieve the HWND of the launched app, which you have to hunt for, the Win32 API does not give it to you directly. You can use the Win32 API EnumWindows() function (filtering use GetWindowThreadProcessId()) or EnumThreadWindows() function for that.  And then, once found, you can use the Win32 API SetParent() function to set your own window (or a child window, like a Panel) as its new parent.

However, this is *not advisable* to do, unless *both apps are specifically designed* to support this.  See this blog article on MSDN:

Is it legal to have a cross-process parent/child or owner/owned window relationship?
« Last Edit: March 31, 2017, 09:21:24 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: External program in my form
« Reply #2 on: March 31, 2017, 08:14:42 am »
I did not understand Your last Question
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1575
    • Lebeau Software
Re: External program in my form
« Reply #3 on: March 31, 2017, 09:18:13 am »
I did not understand Your last Question

It wasn't a question. It is a link to an MSDN blog article that explains why NOT to do what you are asking to do.
« Last Edit: March 31, 2017, 09:22:04 am by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

xinyiman

  • Hero Member
  • *****
  • Posts: 2261
    • Lazarus and Free Pascal italian community
Re: External program in my form
« Reply #4 on: March 31, 2017, 10:30:40 am »
Ok, thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

 

TinyPortal © 2005-2018