Wednesday, April 13, 2005

resize web browser control

I have a dialog based MFC application using Microsoft web browser control(IWebBrowser2). From the first version, I disabled the maximize box and used non-resizable border to avoid the painful layout of GUI elements. Now I want to make it resizable, so I edited the properties in resources: now the dialog itself is resizable, but the Active X control doesn't.

I truned to google and hope it can be sovled in 5 minutes, but the search is
not very successful. After about an hour I solved the problem myself, even though it is very simple, I decided to write it down so that another poor man can get helped.

The solution is to use the OnSize() Event to size our control:

BEGIN_MESSAGE_MAP(CWebBrwoserDlg, CDialog)

void CWebBrwoserDlg::OnSize(UINT nType, int cx, int cy)
CDialog::OnSize(nType, cx, cy);//Call parent's OnSize first

if (m_browser.GetSafeHwnd() != NULL))//Make sure the windows is created.
m_browser.MoveWindow(0, 0, cx, cy);//resize browser control


Post a Comment

<< Home