Embed Internet Explorer inside a Custom Dialog

Example scripts and tips (replaces Old Scripts & Tips archive)

Moderators: Dorian (MJT support), JRL, Phil Pendlebury

Post Reply
User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Embed Internet Explorer inside a Custom Dialog

Post by Marcus Tettmar » Fri May 02, 2014 1:11 pm

There's an old script on the forums that does something similar to this but I'm not sure if it still works for the later versions of IE and it also pre-dates the built in IE functions. So here's a new one. Requires v14. Paste the code into the editor and run and watch the dialog load up with IE inside it.

Code: Select all

//Set IGNORESPACES to 1 to force script interpreter to ignore spaces.
//If using IGNORESPACES quote strings in {" ... "}
//Let>IGNORESPACES=1
 
Dialog>Dialog1
object Dialog1: TForm
  Left = 597
  Top = 264
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  BorderStyle = bsSingle
  Caption = 'CustomDialog'
  ClientHeight = 641
  ClientWidth = 1022
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object Panel1: TPanel
    Left = 0
    Top = 0
    Width = 1022
    Height = 41
    Align = alTop
    TabOrder = 0
    ExplicitWidth = 714
    object Edit1: TEdit
      Left = 10
      Top = 12
      Width = 319
      Height = 21
      TabOrder = 0
      Text = 'http://www.google.com/'
    end
    object MSButton1: tMSButton
      Left = 333
      Top = 12
      Width = 75
      Height = 23
      Caption = 'Go'
      TabOrder = 1
      DoBrowse = False
      BrowseStyle = fbOpen
    end
  end
  object Panel2: TPanel
    Left = 0
    Top = 41
    Width = 1022
    Height = 559
    Align = alClient
    Caption = 'Panel2'
    TabOrder = 1
    ExplicitWidth = 714
    ExplicitHeight = 308
  end
  object Panel3: TPanel
    Left = 0
    Top = 600
    Width = 1022
    Height = 41
    Align = alBottom
    Caption = 'Look: I'#39've put IE inside my dialog!'
    TabOrder = 2
    ExplicitTop = 349
    ExplicitWidth = 714
  end
end
EndDialog>Dialog1
 
AddDialogHandler>Dialog1,msButton1,OnClick,doNav
 
//create an IE instance
IECreate>ie
 
//put that IE instance inside my dialog - sneaky eh!?
IEGetHWND>ie,ieHwnd
LibFunc>user32,SetParent,r,IEhwnd,DIALOG1.PANEL2.HANDLE
GoSub>MaximizeIE
 
//now go to a web page or html file in that IE window ...
 
//this could be a file://c:\temp\somefile.html reference which you could have created ...
IENavigate>ie,http://www.mjtnet.com/,ie_res
 
//show my dialog ....
Show>Dialog1,r
 
//make sure we close IE when we're done and the dialog is closed ...
IEQuit>ie,ie_res
 
SRT>MaximizeIE
   Let>WIN_USEHANDLE=1
   WindowAction>1,IEhWnd
   Let>WIN_USEHANDLE=0
END>MaximizeIE
 
SRT>doNav
  GetDialogProperty>Dialog1,Edit1,Text,newURL
  IENavigate>ie,newURL,ie_res
END>doNav
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Sat Dec 23, 2017 8:58 pm

Is there any way this script could be used to just get the youtube player itself into the dialog panel? Like Embedding the player on a website?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Embed Internet Explorer inside a Custom Dialog

Post by Marcus Tettmar » Tue Dec 26, 2017 10:17 pm

Since this script embeds IE into the dialog then, yes, I guess it must be possible. Create a html page with the embedded youtube code on it and navigate to that page (it could be stored locally) inside the IE frame you have embedded in the dialog.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Wed Jan 31, 2018 10:23 pm

Thanks for this Marcus, it really helped.

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Wed Feb 14, 2018 2:54 am

Hi marcus is there anyway to embed a different browser/program window into the panel inside the dialog? like you did with the IE browser in the script example?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Wed Feb 14, 2018 3:46 am

Also when I run the example script IE opens up two processes and MS seems to not know which one to embed in the panel? Is this fixable or at least explainable to why this happens for me? I usually don't use IE browser but I have been trying to use it recently and i am having nothing but browser issues.... Any chance there is other browser API integration planned for the future? A fix for my first issue would be great though as I have to manually go and end the second process of IE to get the browser window into the custom dialog

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Embed Internet Explorer inside a Custom Dialog

Post by Marcus Tettmar » Mon Feb 19, 2018 8:04 pm

Notice that the script gets the handle of the specified window and makes it's parent the dialog. Ergo, you could *try* this with pretty much any application. Once you have a handle you can set it's parent to anything you like. Only way of knowing what that will do is to try it.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Mon Feb 19, 2018 10:14 pm

Ok thanks, what about the fact that the script opens two processes for IE? is it supposed to do that?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Mon Feb 19, 2018 10:42 pm

Could you also explian what this line is doing for the example script

Code: Select all

LibFunc>user32,SetParent,r,IEhwnd,DIALOG1.PANEL2.HANDLE
I have never used LibFunc> and do not understand what it is doing or what it can be used for exactly. Sorry for being a newbie! Its the only way I learn lol

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Embed Internet Explorer inside a Custom Dialog

Post by Marcus Tettmar » Tue Feb 20, 2018 2:46 pm

It's setting the parent of one window to another:
https://msdn.microsoft.com/en-us/librar ... s.85).aspx
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Tue Feb 20, 2018 3:44 pm

Once again you only answer one of the questions I asked Marcus? Why is the example script opening two processes for IE? The script will not grab any IE instance and parent it to the panel until only only process exists? Is there anyway to fix this?

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Tue Feb 20, 2018 3:45 pm

And your not being very helpfull this time round when explaining LibFunc> The URL you left is broken or missing

MadQuestion
Pro Scripter
Posts: 70
Joined: Wed Nov 08, 2017 6:54 pm

Re: Embed Internet Explorer inside a Custom Dialog

Post by MadQuestion » Tue Feb 20, 2018 3:47 pm

I was more interested in knowing what this bit of the code does!
r,IEhwnd,DIALOG1.PANEL2.HANDLE

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: Embed Internet Explorer inside a Custom Dialog

Post by Marcus Tettmar » Tue Feb 20, 2018 6:36 pm

Erm, they're the parameters. You need to look at the help for LibFunc:

https://www.mjtnet.com/manual/libfunc.htm

And the documentation for the SetParent function I sent you earlier:

https://msdn.microsoft.com/en-us/librar ... s.85).aspx

So:
r,IEhwnd,DIALOG1.PANEL2.HANDLE
r is the return value for LibFunc. The second two are the parms for SetParent. The first is the child handle, the second the parent handle. In our case IEhwnd is the handle of IE, and DIALOG.PANEL2.HANDLE is the handle of the panel on the dialog. So the child is IE and the parent is the dialog panel. So SetParent sets IE's parent to the dialog panel.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts