How to use forms / dialog boxes with an ATL Project / BHO?
-
I am a noob just starting out trying to code extensions for IE, and I have an ATL project with a BHO working with very basic functionality right now. I have a button that displays in the IE Menu toolbar, but need to show a form when the user clicks the button and be able to submit and process data. I have been researching this a lot but am at a loss as to what the best approach would be. There seem to be no tutorials online for this. Has anyone done this before?
-
I am a noob just starting out trying to code extensions for IE, and I have an ATL project with a BHO working with very basic functionality right now. I have a button that displays in the IE Menu toolbar, but need to show a form when the user clicks the button and be able to submit and process data. I have been researching this a lot but am at a loss as to what the best approach would be. There seem to be no tutorials online for this. Has anyone done this before?
I was reading http://msdn.microsoft.com/en-us/library/bb250489.aspx[^] after I saw your post. Scrolling down to around 2/3 of the page under the heading Responding to Events, there is the following:
From MSDN:
Finally, add a simple OnDocumentComplete event handler.
void STDMETHODCALLTYPE CHelloWorldBHO::OnDocumentComplete(IDispatch *pDisp, VARIANT *pvarURL)
{
// Retrieve the top-level window from the site.
HWND hwnd;
HRESULT hr = m_spWebBrowser->get_HWND((LONG_PTR*)&hwnd);
if (SUCCEEDED(hr))
{
// Output a message box when page is loaded.
MessageBox(hwnd, L"Hello World!", L"BHO", MB_OK);
}
}Notice that the message box uses the top-level window of the site as its parent window, rather than simply passing NULL in that parameter. In Internet Explorer 6, a NULL parent window does not block the application, meaning that the user can continue to interact with the browser while the message box is waiting for user input. In some situations, this can cause the browser to hang or crash. In the rare case that a BHO needs to display a UI, it should always ensure that the dialog box is application modal by specifying a handle to the parent window.
Basically, where the MessageBox is, is *any* dialog box you want or create. The actual creation and display of the dialog inside a BHO is exactly the same as for a normal windows application. Just be sure to set the parent to the browser hWnd, as is suggested by this article. So, to learn how to do this, all you need to do is learn how to display a dialog in a normal 32 bits application. And then hook it up to your BHO and display it at the right time.