Embedding an external application into the Delphi application [Edit]

Hi guys,
I am trying to embed Mozilla Firefox into my Delphi application with the following code,
The code works with "Notepad" but it doesn't work with the Mozilla Firefox.

Any help will be extremely appreciated.

{code}
unit unitMain;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ExtCtrls, ShellApi;

type
  TfrmMain = class(TForm)
    pnlTop: TPanel;
    panBottom: TPanel;
    btnLoadApp: TButton;
    btnKill: TButton;
    procedure btnLoadAppClick(Sender: TObject);
    procedure btnKillClick(Sender: TObject);
  private
    AppWnd : DWORD;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.btnLoadAppClick(Sender: TObject);
var
  ExecuteFile : string;
  SEInfo: TShellExecuteInfo;
begin
  //ExecuteFile := 'C:\Windows\notepad.exe'; //This works like charm.
  ExecuteFile := 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'; //This doesn't work :(

  FillChar(SEInfo, SizeOf(SEInfo), 0) ;
  SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
  with SEInfo do
  begin
    fMask := SEE_MASK_NOCLOSEPROCESS;
    Wnd := pnlTop.Handle;
    lpFile := PChar(ExecuteFile) ;
    nShow := SW_HIDE;
  end;
  if ShellExecuteEx(@SEInfo) then
  begin
    //AppWnd := FindWindow(nil, PChar('Untitled - Notepad')); //This works like charm.
    AppWnd := FindWindow(nil, PChar('Apple - Mozilla Firefox')); //This doesn't work :(
    if AppWnd  >0 then
    begin
      Windows.SetParent(AppWnd, SEInfo.Wnd);
      ShowWindow(AppWnd, SW_SHOWMAXIMIZED);
      ShowWindow(AppWnd, SW_SHOWMAXIMIZED);
    end;
  end
  else
    ShowMessage('Error starting notepad!') ;
end;

procedure TfrmMain.btnKillClick(Sender: TObject);
begin
  if (AppWnd  >0) then
  begin
    PostMessage(AppWnd, WM_Close, 0, 0);
    AppWnd := 0;
  end;
end;

end.
{code}

Thanks in advance

-daniel
0
daniel
1/6/2011 8:59:25 PM
embarcadero.delphi.vcl.using 2297 articles. 2 followers. Follow

12 Replies
5415 Views

Similar Articles

[PageSpeed] 15
Get it on Google Play
Get it on Apple App Store

<daniel Legrand> wrote in message news:318737@forums.embarcadero.com...
> Hi guys,
> I am trying to embed Mozilla Firefox into my Delphi application with the 
> following code,
> The code works with "Notepad" but it doesn't work with the Mozilla 
> Firefox.

This question comes up frequently, and the answer is that you may
be able to get it to work with certain applications, but there is no 
definitive
way to get it to work reliably with all applications. Windows is just not 
designed
that way. Firefox creates multiple top-level windows which run in the same 
process,
whereas each Notepad window is a separate process. Firefox may have a hidden
parent window which gets in the way of your re-parenting.
If you really want to get embed firefox, look at its source code to 
determine how
the top-level windows are created.

cheers,

Chris
0
Chris
1/7/2011 12:39:22 AM
"Chris Morgan" <chrisXXX at lynxinfo.co.uk> wrote in message 
news:318790@forums.embarcadero.com...
> If you really want to get embed firefox, look at its source code to 
> determine how
> the top-level windows are created.


Most likely, as with IE, it has a COM interface that can be used and, using 
that, will embed just fine.


-- 
Wayne Niddery (TeamB)
"Do not consider Collectivists as 'sincere but deluded idealists.' The 
proposal to enslave some men for the sake of others is not an ideal; 
brutality is not 'idealistic,' no matter what its purpose. Do not ever say 
that the desire to 'do good' by force is a good motive. Neither power-lust 
nor stupidity are good motives." -Ayn Rand"
0
Wayne
1/7/2011 2:24:34 AM
I think you need to double quote the filename, because it contains 
spaces and can not be interpreted correctly:

ExecuteFile := '"C:\Program Files (x86)\Mozilla Firefox\firefox.exe"'; 
//This doesn't work :(


On 1/6/11 9:59 PM, daniel Legrand wrote:
> Hi guys,
> I am trying to embed Mozilla Firefox into my Delphi application with the following code,
> The code works with "Notepad" but it doesn't work with the Mozilla Firefox.
>
> Any help will be extremely appreciated.
>
> {code}
> unit unitMain;
>
> interface
>
> uses
>    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
>    Dialogs, StdCtrls, ExtCtrls, ShellApi;
>
> type
>    TfrmMain = class(TForm)
>      pnlTop: TPanel;
>      panBottom: TPanel;
>      btnLoadApp: TButton;
>      btnKill: TButton;
>      procedure btnLoadAppClick(Sender: TObject);
>      procedure btnKillClick(Sender: TObject);
>    private
>      AppWnd : DWORD;
>      { Private declarations }
>    public
>      { Public declarations }
>    end;
>
> var
>    frmMain: TfrmMain;
>
> implementation
>
> {$R *.dfm}
>
> procedure TfrmMain.btnLoadAppClick(Sender: TObject);
> var
>    ExecuteFile : string;
>    SEInfo: TShellExecuteInfo;
> begin
>    //ExecuteFile := 'C:\Windows\notepad.exe'; //This works like charm.
>    ExecuteFile := 'C:\Program Files (x86)\Mozilla Firefox\firefox.exe'; //This doesn't work :(
>
>    FillChar(SEInfo, SizeOf(SEInfo), 0) ;
>    SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
>    with SEInfo do
>    begin
>      fMask := SEE_MASK_NOCLOSEPROCESS;
>      Wnd := pnlTop.Handle;
>      lpFile := PChar(ExecuteFile) ;
>      nShow := SW_HIDE;
>    end;
>    if ShellExecuteEx(@SEInfo) then
>    begin
>      //AppWnd := FindWindow(nil, PChar('Untitled - Notepad')); //This works like charm.
>      AppWnd := FindWindow(nil, PChar('Apple - Mozilla Firefox')); //This doesn't work :(
>      if AppWnd>0 then
>      begin
>        Windows.SetParent(AppWnd, SEInfo.Wnd);
>        ShowWindow(AppWnd, SW_SHOWMAXIMIZED);
>        ShowWindow(AppWnd, SW_SHOWMAXIMIZED);
>      end;
>    end
>    else
>      ShowMessage('Error starting notepad!') ;
> end;
>
> procedure TfrmMain.btnKillClick(Sender: TObject);
> begin
>    if (AppWnd>0) then
>    begin
>      PostMessage(AppWnd, WM_Close, 0, 0);
>      AppWnd := 0;
>    end;
> end;
>
> end.
> {code}
>
> Thanks in advance
>
> -daniel


-- 
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
0
Willem
1/7/2011 11:49:12 AM
> {quote:title=Willem van Deursen wrote:}{quote}
> I think you need to double quote the filename, because it contains 
> spaces and can not be interpreted correctly:
> 

> -- 
> Willem van Deursen, The Netherlands
> wvandeursen_nospam@nospam_carthago.nl
> replace _nospam@nospam_ for @ to get a valid email address
> www.carthago.nl

No, Willem
That doesn't help anything.

-daniel
0
daniel
1/7/2011 1:20:11 PM
This code works for me. Note that I set nShow to SW_SHOW to actually see 
firefox starting up....

     ExecuteFile := 'C:\Program Files\Mozilla Firefox\firefox.exe';
     FillChar(SEInfo, SizeOf(SEInfo), 0) ;
     SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
     with SEInfo do
     begin
       fMask := SEE_MASK_NOCLOSEPROCESS;
       lpFile := PChar(ExecuteFile) ;
       nShow := SW_SHOW;
     end;
     if ShellExecuteEx(@SEInfo) then
       begin
       end
     else
       ShowMessage('Error starting firefox!') ;
  end;




On 1/7/11 2:20 PM, daniel Legrand wrote:
>> {quote:title=Willem van Deursen wrote:}{quote}
>> I think you need to double quote the filename, because it contains
>> spaces and can not be interpreted correctly:
>>
>
>> --
>> Willem van Deursen, The Netherlands
>> wvandeursen_nospam@nospam_carthago.nl
>> replace _nospam@nospam_ for @ to get a valid email address
>> www.carthago.nl
>
> No, Willem
> That doesn't help anything.
>
> -daniel


-- 
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
0
Willem
1/7/2011 1:53:06 PM
> {quote:title=Willem van Deursen wrote:}{quote}
> This code works for me. Note that I set nShow to SW_SHOW to actually see 
> firefox starting up....
> 
>      ExecuteFile := 'C:\Program Files\Mozilla Firefox\firefox.exe';
>      FillChar(SEInfo, SizeOf(SEInfo), 0) ;
>      SEInfo.cbSize := SizeOf(TShellExecuteInfo) ;
>      with SEInfo do
>      begin
>        fMask := SEE_MASK_NOCLOSEPROCESS;
>        lpFile := PChar(ExecuteFile) ;
>        nShow := SW_SHOW;
>      end;
>      if ShellExecuteEx(@SEInfo) then
>        begin
>        end
>      else
>        ShowMessage('Error starting firefox!') ;
>   end;
> 
> 
> -- 
> Willem van Deursen, The Netherlands
> wvandeursen_nospam@nospam_carthago.nl
> replace _nospam@nospam_ for @ to get a valid email address
> www.carthago.nl

Thanks Willem,
Sorry,
I have never said it doesn't start.
It always does start.
The problem is,
It doesn't start in inside of my delphi form, it starts as an external separate window.

Notepad opens nicely in inside of my delphi form.

-daniel
0
daniel
1/7/2011 2:07:09 PM
On 1/7/11 3:07 PM, daniel Legrand wrote:

Sorry, I was on the wrong track! Hope someone else will be able to 
provide better support than I did ;-)

Willem
-- 
Willem van Deursen, The Netherlands
wvandeursen_nospam@nospam_carthago.nl
replace _nospam@nospam_ for @ to get a valid email address
www.carthago.nl
0
Willem
1/7/2011 2:10:07 PM
> {quote:title=Willem van Deursen wrote:}{quote}
> On 1/7/11 3:07 PM, daniel Legrand wrote:
> 
> Sorry, I was on the wrong track! Hope someone else will be able to 
> provide better support than I did ;-)
> 
> Willem
> -- 
> Willem van Deursen, The Netherlands
> wvandeursen_nospam@nospam_carthago.nl
> replace _nospam@nospam_ for @ to get a valid email address
> www.carthago.nl

No problem!
I will wait and see if there would be someone who knows these things and could give us some light :)

-daniel
0
daniel
1/7/2011 2:22:32 PM
daniel Legrand wrote:

> I am trying to embed Mozilla Firefox into my Delphi application with
> the following code, The code works with "Notepad" but it doesn't work
> with the Mozilla Firefox.

The approach only works with very simple applications.

You may want to look at this link:

http://www.paranoia.clara.net/articles/taming_the_lizard_with_delphi.html

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
0
Peter
1/7/2011 6:54:14 PM
> 
> You may want to look at this link:
> 
> http://www.paranoia.clara.net/articles/taming_the_lizard_with_delphi.html
> 
> -- 
> Peter Below (TeamB)  
> Don't be a vampire (http://slash7.com/pages/vampires), 
> use the newsgroup archives :
> http://codenewsfast.com
> http://groups.google.com

Thanks Peter,
That was my first try and I have spent more than week to make it work with no success because they all are outdated.

I still believe there should be a way of running it via Delphi application as I am trying to.

-daniel
0
daniel
1/7/2011 7:24:57 PM
On 8/01/2011 6:24 AM, daniel Legrand wrote:
>>
>> You may want to look at this link:
>>
>> http://www.paranoia.clara.net/articles/taming_the_lizard_with_delphi.html
>>
>> --
>> Peter Below (TeamB)
>> Don't be a vampire (http://slash7.com/pages/vampires),
>> use the newsgroup archives :
>> http://codenewsfast.com
>> http://groups.google.com
>
> Thanks Peter,
> That was my first try and I have spent more than week to make it work with no success because they all are outdated.
>
> I still believe there should be a way of running it via Delphi application as I am trying to.
>
> -daniel

A quick Google search came up with this:
https://developer.mozilla.org/en/Embedding_Mozilla

Looks to have the tools and documentation you need.

Cheers,
Andrew
0
Andrew
1/7/2011 10:34:32 PM
> 
> A quick Google search came up with this:
> https://developer.mozilla.org/en/Embedding_Mozilla
> 
> Looks to have the tools and documentation you need.
> 
> Cheers,
> Andrew

Andrew,
I did spent lot of time on trying to use all founded in the google with no success.
If you follow the links,  you can see that they all are crap/dead end and all outdated and all with none support (I have became Mozilla MDN member and made question, wait about 4 weeks no one has answered anything).

There is nothing which works with Delphi!!
I have tryed the Lazarus as well and it doesn't work in there either.
They have some crap called Gecko which opens only very basic sites and doesn't even understand HTTPS and doesn't work with the latest firefox.

Now,
The help I need is for my code which is described as question.
If I can make it work, all my problems will be solved because I really don't need to create a Firefox I just need to use it as full screen in my application.

No matter what they do,
Firefox will never be as good as TWebBrowser of Delphi.

Thanks

-daniel
0
daniel
1/7/2011 11:13:06 PM
Reply:

Similar Artilces:

Cannot use Microsoft Excel when a Delphi application that uses automat. run [Edit]
Dear all, I built an application that connect to an Excel file using a OleObject: Excel := CreateOleObject('Excel.Application'); LCID := GetUserDefaultLCID; all works fine but I cannot use Microsoft Excel externally when my application is running. If I try to open another xls file, Excel tries to open the file in my Delphi application in read only mode. It does not even show it properly but opens a weir transparent application. I just want to be able to use Excel externally and I'd like the instance opened by my Delphi application to be independent from other Exc...

Run an external application as hide application and control it with Delphi
I need run a 3rd application (I think developed with Visual Studio) and hide it (the user don't must see it), then I need: 1. click on a menu to open a window, click on tab component; 2. set 2 edit fields, and choose a item from combobox; 3. click on a button and extract 2 text from 2 edit fields; 4. close the application; All this without user see nothing. Is it possible in anyway? I need do it with a Delphi (XE3) application. I don't have experience about control of 3rd application an I don't know if it possible. Is there a free library to use UIAutomation? Martin Masc...

I wrote an application and used cracked delphi 7, after i bought delphi 7
I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an application and used cracked delphi 7, I sold it, after i bought delphi 7 and recompiled application, is now my application legal or? "I embezzled some money from my employer, returned the funds, and then got it back as a bonus. Can I still be arrested?" Uhhh .... didn't you just confess to a crime? > {quote:title=Ivan Ivanov wrote:}{quote} > I wrote an appli...

Cannot use Excel when Delphi application run (more information) [Edit]
This is driving me insane... Following my previous message... When I run a Delphi application that uses automation I cannot access other files in Excel. Every time I double click on a different Excel file (not the one my application is using) Excel tries to open my file in read only mode and then it goes into a bizarre state: part of the Excel form goes transparent and I cannot use it. This does not happen if I start Excel using the shortcut in the start menu and then I open a file manually. I figure out that in order to be able to use Excel I need to force Excel not to use the ...

Using the WinUSB driver with Delphi 7 applications [Edit]
I have just discovered the generic Microsoft USB driver described here: http://www.microsoft.com/whdc/connect/usb/winusb_howto.mspx (I hope this comes out as a link, it does not when I view it using the Preview function...) Of course the document is just describing how to use it from C++, which I am not at all used to. Is there anyone here who has touched on this WinUSB who can direct me on how to use it from Delphi? Apparently the idea here is to use the generic driver WinUSB to talk to a device directly from an application. The device will not be able to talk to the operating system ...

Delphi XE2 DLL can't be used in C# application [Edit]
For testing I am trying to call a Delphi XE2 DLL (see code) in a C# application (developed in Visual C# 2010 Express). procedure CLP; stdcall; export; begin showmessage('TEST'); end; exports CLP; However when trying to add the DLL as reference to a C# project the following message appears: "A reference to 'D:\temp\test.dll' could not be added. Please make sure that the file is accessible, and that is a valid assembly or COM component." When the same DLL is compiled under Delphi 2010 it works without any problem. Any suggestions how to solve the p...

Using MySQL from a Delphi application
Hi All: How can I access a remote MySQL database (hosted by JumpLine.com or whatever ISP) from a Delphi application. It seems that the preferred tool for accessing MySQL´s databases is PHP. The scenario is simple: I have a Delphi application to manage support calls using a local MS SQL Server, but I need to access data from anywhere NOT using a browser. The application MUST be written in Delphi and running locally. Any ideas? Regards Francisco Alvarado Francisco Alvarado wrote: > Hi All: > How can I access a remote MySQL database (hosted by JumpLine.com or > whateve...

PLDelphi
I have just released PLDelphi, that will embed Perl into your Delphi applications and will enable the use of Perl objects and evaluations directly from Delhpi. Also you will be able to count with the Perl REGEXP resources and CPAN components. You can download it at: http://search.cpan.org/~gmpassos/PLDelphi-0.01/ PLDelphi is based in a previous work, PLJava, and both have similar intefaces: http://search.cpan.org/~gmpassos/PLJava-0.04/ Enjoy. ;-P Graciliano M. P. ...

Application to Application
Hi,  Curious on what different solutions there are for one application that is closing down to contact another application. I have the closing down applicaton sending something to the database and for the other application to monitor the database records, but I think that is a horrible solution. Another idea would be when the closing down application sends a message to the database for the database to then respond by sending a message to the other application, but that means the database would have to know where the other application is.  If possible, the security issue mak...

Microworld controlled by the Delphi application [Edit]
Here is the link folks: http://www.youtube.com/watch?v=SDXb5ITsQ0E&feature=sub Maybe a better link, showing the world: http://www.miniatur-wunderland.de/anlage/video/4-minuten-wunderland/ Edited by: Dimitrij Kowalski on Feb 8, 2010 12:33 PM Dimitrij Kowalski wrote: > Maybe a better link, showing the world: > > http://www.miniatur-wunderland.de/anlage/video/4-minuten-wunderland/ English version: http://www.miniatur-wunderland.com/exhibit/video/4-minutes-wunderland/ -- Pieter AMAZING BUT TRUE ... There is so much sand in Northern Africa that if it we...

Delphi applications
I just saw new ODBC switch in ASA602 named "Delphi applications". Anyone knows what it does do? Dubravko Solic dsolic@smartt.com >I just saw new ODBC switch in ASA602 named "Delphi applications". Anyone >knows what it does do? Delphi expects a certain ODBC behavior regarding bookmarks in cursors. It expects that if you ask for two bookmarks on the same row, the driver will return the same bookmark ID in both instances. By default, the SA/ASA ODBC driver does not. Sybase's position is that their driver is compatible with the ODBC spec. Ho...

LabView style Delphi application [Edit]
Hi, I would like to make a small application (with Delphi) where I would be able to draw a few (ex: 2) square shapes (blocks), attache some lines (pins) to it like in LabView and to be able to connect those pins, in this way I will be abel to define some names for those pins (ex: Pin1, Pin2) and define some names for connections (Con1) that connect those pins. The first block will calculate a value and set the Con1 variable connected to Pin1 with the caluclated value so the second block will see that the default value of the connection had been changed by someone (some block's pin) s...

Embedding HTML5 and Javascript in a Delphi application
Hi All, I'm looking for a solutions to embed HTML5/Javascript pages in a Delphi VCL applications. It seemed like CEF (Chromium Embedded Framework) would have been a very nice solutions, but as far as I understood the continuation of this open source project is a bit questionable at the moment as Henri Gourvest has stated that he has stopped working on the project so I'm no longer sure this would be the safest bet in the long run. I know there is also TWebBrowser..., but does anyone know of any other alternatives around? Any suggestions or views on this would be very welcome. ...

Application Delphi
Somebody knows some Drive for dbExpress for access to the Banco Sybase. Thank you. Ivan ...

Web resources about - Embedding an external application into the Delphi application [Edit] - embarcadero.delphi.vcl.using

Application - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Welfare experiment may have applications in Australia
A trial in Finland providing an obligation-free basic income could change how we think about welfare.

Second visa application 'likely' to be approved
The family of a terminally ill Pakistani student can 'hopefully come to Australia sooner rather than later' says Immigration Minister Peter Dutton. ...

Apple patent application reveals exciting possibilities for twin-camera system rumored for iPhone 7
We heard a report in November that Apple was testing an iPhone 7 model with dual rear cameras , and a patent application published today not ...

Panasonic Develops a Stretchable Resin Film and Its Application Materials for Stretchable Electronics ...
A stretchable film is developed. This film stretches to 2.5 times the original length and then returns to the original form. A conductive paste ...

MBA: Mortgage Applications Increase in Latest MBA Weekly Survey, Purchase Applications up 37% YoY
From the MBA: Refinance, Purchase Applications Both Up in Latest MBA Weekly Survey Mortgage applications increased 7.3 percent from one week ...

Mortgage applications sink after rush
A Fed rate hike pulled mortgage demand forward, and made for a steep drop-off in the past two weeks.

Visa application of San Bernardino shooter released
CNN Visa application of San Bernardino shooter released CNN (CNN) The visa application of one of the San Bernardino shooters was released ...

SURPRISE! Mizzou Sees Application Drop After Days Of Protests, Illusory Klan Hoods, Poop Swastika
SURPRISE! Mizzou Sees Application Drop After Days Of Protests, Illusory Klan Hoods, Poop Swastika

In Application To Move To Los Angeles, Rams Shit All Over City Of St. Louis
... to relocate to the greater Los Angeles metropolitan area. The relocation would be effective for the 2016 NFL League Year.” The Rams’ full application ...

Resources last updated: 1/10/2016 7:29:41 AM