• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 316
  • Last Modified:

How to control IE WebBrowser Control from an ActiveX control inside it?

 I create an ActiveX Control,and use it inside IE WebBrowser Control, my question is how to control the IE WebBrowser Control.
  I can get the IE WebBrowser Control Wnd by call the function FindWindow(), but I cann't get IUnknown Pointer to the Control.
  Can anyone help me?
  Thank you!
0
linyf
Asked:
linyf
  • 2
  • 2
1 Solution
 
fstabCommented:
By doing a QueryInterface on your control, and if this is successful, you should be able to get to the IUnknown pointer too, by doing one more QueryInterface to IUnknown. This is because of one of the rules of COM : when you can get from here to there, you can get from there to anywhere.
0
 
linyfAuthor Commented:
Thank you!
    But how can I get the IUnknown pointer?
    I used this way to get the IE WebBrowser Control that contains my control:

    CWnd * tWnd=GetParent();
    while(tWnd)
    {
      GCHAR tClassName[255];
      strcpy(tClassName,"");
      GetClassName(tWnd->m_hWnd,tClassName,250);
      if(strcmp(tClassName,"Internet Explorer_Server")==0)
      {
      }
      tWnd=tWnd->GetParent();
    }

    How can I get an IUnknown pointer through the tWnd Object?
    Or there exists other way to do this?

0
 
fstabCommented:
You cannot get the IUnknown from the window handle.

The definition of QueryInterface is as follows :

HRESULT QueryInterface(
  REFIID iid,        //Identifier of the requested interface
  void ** ppvObject  //Address of output variable that receives the
                     //interface pointer requested in iid);

Do the following steps :

1. Open your system's Windows Registry - run regedit.
2. Open HKEY_CLASSES_ROOT
3. Search for the IE WebBrowser control entry - it'll usually be in the format : Vendor.Control.Version
4. Note this name down : for eg. MS***.WebBrowser.2
5. Use the function CLSIDtoProgID which returns the CLSID of this control
6. Use the CLSID returned from this function to QueryInterface

Good luck !
fstab.
0
 
linyfAuthor Commented:
Thank you very much!

    I know how to create an IE WebBrowser Control,but what I want to do is to seek for an existing WebBrowser Control that contains my own ActiveX control (because inside my control I want to call such methods as "Navigate","GoBack" and so on.),
I know CWnd class has a method called GetControlUnknown() for getting an IUnknown pointer of an OleControl,that is why I want to get an IUnknown pointer from a CWnd object. If this way is not possible, can you tell me other ways?
    Thank you again!

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now