Question

I have an MSVC 2010 solution that contains 2 projects:

  • ATL DLL project, that contains DHTML control (named DHTMLControl, which is pretty much built by wizard). I think I could have placed this control into the second project though.
  • ATL EXE project, that contains main dialog (CMainDialog), also created by wizard.

I have managed to add DHTMLControl to the dialog:

  1. added DHTMLControl to Toolbox
  2. dragged it onto the main dialog in resource view
  3. removed DHTMLControl from Toolbox (to avoid access denial on build)

However, my problem is that I do not know how to use this control!

Assuming I am in the scope of MainDialog, say in:

LRESULT CMainDialog::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)

What would be the right way to invoke DHTMLControl's methods? Say, I would like to navigate to another url or the like after a button on main dialog is pressed.

How can I get a pointer/reference to DHTMLControl (CDHTMLControl? IDHTMLControl?) being inside of CMainDialog class?

Sorry if that sounds a bit messy but I am really struggling with ATL.

Thank you.

Was it helpful?

Solution

Include the generated _i.h into the dialog's header (Do not include the actual control's header - it is not meant to be included).

Then use something like this:

CComPtr<IDHTMLControl> ptr;
HRESULT hr = GetDlgControl(IDC_DHTML_CONTROL, IID_IDHTMLControl, (void**)&ptr);

BSTR url = SysAllocString(L"http://example.com/");
// Call control's prop method
ptr->put_Url(url);
SysFreeString(url);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top