Re: Destroy webbrowser control - CAxWindow2
Igor Tandetnik schrieb:
"AFons" <alfonsnewslet46@hotmail.com> wrote in message
news:epUkv2NBIHA.1164@TK2MSFTNGP02.phx.gbl
I have a CWindowImpl derived class that creates a CAxWindow2 window
holding a webbrowser control.
The WB Control spawns several threads (up to 10-13) while using
Navigate2 e.g.
The problem is, that all these threads keep alive after destroying
the window.
Any idea how to destroy the webbrowser (-threads) completely with
the window?
Make sure you have released all interface pointers you may have acquired
on WebBrowser or the document it contains, and unadvised all event
sinks.
Hello Igor,
thank you for your reply.
Following your advise to check all interface pointers and unadvising all
event sinks I??m pretty sure that open references are not the problem.
To isolate the problem I wrote a minimalistic class to reduce the
problem - but - the webbrowser ctrl after closing the window
still keeps it??s threads.
Maybe it??s somethink stupid I??m just do not see.
Here??s the source:
/// atlbrowse.h
#define _ATL_DEBUG_INTERFACES
#include <atlbase.h>
#include <atlwin.h>
///////////////////////////////////////////////////////////////////////////////////
// CATLWindow - a browser window using CAxWindow
//
///////////////////////////////////////////////////////////////////////////////////
class CATLWindow : public CWindowImpl<CATLWindow>,
public CAtlDllModuleT<CATLWindow>
{
public:
DECLARE_WND_CLASS(_T("ATLBROWSE"));
CATLWindow();
~CATLWindow() {};
public:
BEGIN_MSG_MAP(CATLWindow)
MESSAGE_HANDLER(WM_CREATE, OnCreate);
MESSAGE_HANDLER(WM_SIZE, OnSize);
MESSAGE_HANDLER(WM_DESTROY, OnDestroy);
END_MSG_MAP()
// MESSAGE - HANDLER
LRESULT OnCreate (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
LRESULT OnSize (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
LRESULT OnDestroy (UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
&bHandled);
private:
CAxWindow2 m_ie;
};
/// atlbrowse.cpp
#include "atlbrowse.h"
CATLWindow::CATLWindow()
{
if (!AtlAxWinInit()) return;
// Create Main Window
RECT r = {0,0,600,600};
Create(NULL, r, _T("******** SIMPLE BROWSER"),WS_OVERLAPPEDWINDOW);
ShowWindow(SW_NORMAL);
}
//////////////////////////////////////////////////////////////////
// MESSAGE - HANDLER
//////////////////////////////////////////////////////////////////
LRESULT CATLWindow::OnCreate (UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL &bHandled)
{
// 1. Create the host window
RECT r;GetClientRect(&r);
HWND hCont = m_ie.Create(m_hWnd, r, 0,WS_CHILD|WS_VISIBLE);
// 2. Create Control inside the host-window
HRESULT hr;
CComPtr<IAxWinHostWindow> pHost;
hr = m_ie.QueryHost(&pHost);
hr = pHost->CreateControl(L"http://www.google.de", hCont, NULL);
return S_OK;
}
LRESULT CATLWindow::OnSize (UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL &bHandled)
{
RECT r; GetClientRect(&r);
m_ie.MoveWindow(r.top, r.left, r.right, r.bottom);
return S_OK;
}
LRESULT CATLWindow::OnDestroy (UINT nMsg, WPARAM wParam, LPARAM lParam,
BOOL &bHandled)
{
m_ie.DestroyWindow();
PostQuitMessage(0);
return S_OK;
}
/// main.cpp
#include "atlbrowse.h"
int main(int argc, char* argv[])
{
CATLWindow win;
MSG msg;
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
AtlAxWinTerm();
char c =getchar();
return 0;
}