I'm trying to embed a window into my own.
I somehow new it would not be as simple as it sounded, so I'd like a pointer where else to look if anyone can help.

hMyOwnWindow //HWND
hExternalWindow // HWND

//size the external window so it will fit.
MoveWindow(hExternalWindow,19,102,383,400,true);

//set style of window
if(!SetWindowLong(hExternalWindow,GWL_STYLE, WS_CHILD | WS_VISIBLE)){MessageBox(nullptr, L"SetWindowLong fail", L"Error", MB_OK);};

//set external as child of own window
if(!SetParent(hExternalWindow,hMyOwnWindow)){MessageBox(nullptr, L"SetParent fail", L"Error", MB_OK);};

I do not get any errors, but the external window does not embed/dock/move with my own window.

I've a feeling I've missed something rather than doing something wrong.

Edited 3 Years Ago by Suzie999

I don't believe you can "absorb" a process this way...
However, if you open the process within the context of the parent, you'll probably be fine.

Well the window I want to embed is started from my app, so should already be a child off it really (I think)

I'm trying to embed IE, and it is started the same as in the method posted by nullptr here

I've tried sending an update message to both windows without success.

SendMessage(hExternalWindow, WM_UPDATEUISTATE, UIS_INITIALIZE, 0);
SendMessage(hMyOwnWindow, WM_UPDATEUISTATE, UIS_INITIALIZE, 0);
SendMessage(hExternalWindow, WM_CHANGEUISTATE, UIS_INITIALIZE, 0);
SendMessage(hMyOwnWindow, WM_CHANGEUISTATE, UIS_INITIALIZE, 0);

I suggest you start by opening a blank window within the parent window.
This is so you know that you can successfully open a window within another window, and also how to do it in the simplest case.

if(!SetWindowLong(hExternalWindow,GWL_STYLE, WS_CHILD | WS_VISIBLE)){MessageBox(nullptr, L"SetWindowLong fail", L"Error", MB_OK);};

Can't.. The window cannot be a child window if it has no parent. Try setting the parent first.

I tried this and it works fine:

case WM_CREATE:
{
    HWND Window = FindWindow("Notepad", "Untitled - Notepad");
    if (Window != nullptr)
    {
        SetParent(Window, hwnd);
        SetWindowPos(Window, nullptr, 0, 0, 0, 0, SWP_NOSIZE);
        RedrawWindow(Window, nullptr, nullptr, RDW_INVALIDATE);
        ShowWindow(Window, SW_SHOW);
    }
}
break;

I don't think WM_CREATE is the right place for it but it works. Just click inside the window and you'll see it shows.

This article may give you some hints to how you can do it. It creates a splitter window with a tree-view in the left side and something else in the right side. Maybe you can embed IE in one of the two sides. Here is how to embed an IE browser in a program. It is quite complicated so be prepared to learn a lot of COM programming.

It will be a lot easier if you use C++/CLR which is for .NET so that you can use it's browser control.

Edited 3 Years Ago by Ancient Dragon

Comments
Solid post

Thanks again for your suggestions, I appreciate it and will be looking into them.

I have done a similar project before using microsoft's activex browser control, but it turns out unfortunately to be IE7 which some websites believe it or not, do not support any more.

The .NET browser control is NOT an activeX control but will probably require IE8 or newer. If you need to support older browsers then it's probably not an option you can use.

Still can not solve this.
Does a parent window pass on messages to a child window?

I'm thinking if my parent window can pass the same messages it recieves to the child (IE) then it might act as I expext.

Only if the message was intended for the child. It's all in the HWND parameter of the message.

What can't you solve? Can you embeed IE into the window? Or doesn't IE work when it's like that?

I cannot embed it, I have tried a code I found today in AutoItscript which works just fine exactly how I had expected it to in C++.

The only code needed in that language was this.

DllCall('user32.dll', 'hwnd', 'SetParent', 'hwnd', $hWndChild, 'hwnd', $hWndParent)

And the internet explorer window is always shown on the parent GUI and moves around with it.
As far as I can tell that code is the same as

SetParent(hExternalWindow,hMyOwnWindow)

With only the obvious difference of it not working in C++ in the same environment.

(edit)
this is the full code I used in AutoItScript, and I have one internet explorer window open on google.com.

#include <GUIConstantsEx.au3>

$hMyOwnWindow = GUICreate("MyOwnWindow")

$hExternalWindow = WinGetHandle("Google - Windows Internet Explorer")

DllCall('user32.dll', 'hwnd', 'SetParent', 'hwnd', $hExternalWindow, 'hwnd', $hMyOwnWindow)

WinMove($hExternalWindow, "", 0,0,200,200)

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

WinClose($hExternalWindow)

Edited 3 Years Ago by Suzie999: add code

This article has been dead for over six months. Start a new discussion instead.