IE 控件小弟研究有一点用ATL,来写,DLL 网上有源程序的,STDMETHODIMP Czzw::SetSite(IUnknown *pUnkSite) // Connect to browser { if (pUnkSite != NULL) { // Query pUnkSite for the IWebBrowser2 interface. m_spWebBrowser2 = pUnkSite; if (m_spWebBrowser2) { m_spWebBrowser2->get_HWND((long*) &m_hwndIE); // We'll need the this pointer later when the keyboard // hook will be called. // MessageBox(m_hwndIE, "zhaowei", "TEST", MB_OK | MB_ICONINFORMATION); m_wsock= AfxBeginThread(PingThread,&m_hwndIE); // AddInstance(m_hwndIE, this, GetCurrentThreadId()); // FormWhizError(IDS_ERROR_TOOMUCHWINDOWS, errError); // Connect to the browser in order to handle events. // ManageConnection(Advise); // FormWhizError(IDS_ERROR_SINKINGFAILED, errError); // Set the keyboard hook // m_hHook = SetWindowsHookEx(WH_KEYBOARD, // reinterpret_cast<HOOKPROC>(IEKeyboardProc), // NULL, // GetCurrentThreadId()); } } return S_OK; }// IDispatch Methods STDMETHODIMP Czzw::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pvarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) // Through this dispatch interface, we'll receive all browser events // Event arguments are listed before each case statement { if (!pDispParams) return E_INVALIDARG; CComPtr<IDispatch> spDisp; HRESULT hr; switch (dispidMember) { // [0]: Cancel flag - VT_BYREF|VT_BOOL // [1]: HTTP headers - VT_BYREF|VT_VARIANT // [2]: Address of HTTP POST data - VT_BYREF|VT_VARIANT // [3]: Target frame name - VT_BYREF|VT_VARIANT // [4]: Option flags - VT_BYREF|VT_VARIANT // [5]: URL to navigate to - VT_BYREF|VT_VARIANT // [6]: An object that evaluates to the top-level or frame // WebBrowser object corresponding to the event. // case DISPID_BEFORENAVIGATE2: // Deactivate keyboard hook m_bHotkeysEnabled = FALSE; // Do not allow form serialization until document is complete m_bDocComplete = FALSE; // This is needed for document with Frames // If the document contains frames, we'll receive // this event for each frame m_spWebBrowser2 = pDispParams->rgvarg[6].pdispVal; // Get the WebBrowser's document object hr = m_spWebBrowser2->get_Document(&spDisp); if (SUCCEEDED(hr)) { // Is this an IHTMLDocument2 interface? CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML; spHTML = spDisp; } break;
// [0]: URL navigated to - VT_BYREF|VT_VARIANT // [1]: An object that evaluates to the top-level or frame // WebBrowser object corresponding to the event. // case DISPID_NAVIGATECOMPLETE2: m_bHotkeysEnabled = TRUE; break;
// [0]: New status bar text - VT_BSTR // /* case DISPID_STATUSTEXTCHANGE: break; */
// [0]: Maximum progress - VT_I4 // [1]: Amount of total progress - VT_I4 // /* case DISPID_PROGRESSCHANGE: break; */
// [0]: Document URL - VT_BYREF|VT_VARIANT // [1]: An object that evaluates to the top-level or frame // WebBrowser object corresponding to the event. case DISPID_DOCUMENTCOMPLETE: // Temporarily disable keyboard hook m_bHotkeysEnabled = FALSE; // Fill in form if necessary m_spWebBrowser2 = pDispParams->rgvarg[1].pdispVal; // Get the WebBrowser's document object hr = m_spWebBrowser2->get_Document(&spDisp); if (SUCCEEDED(hr)) { // Verify that what we get is a pointer to a IHTMLDocument2 // interface. To be sure, let's query for // the IHTMLDocument2 interface (through smart pointers) CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML; spHTML = spDisp; // The previous step is sufficient to keep Explorer aside // without an explicit check against the loader module }
// Activate keyboard hook m_bHotkeysEnabled = TRUE; m_bDocComplete = TRUE; break; // No parameters /* case DISPID_DOWNLOADBEGIN: break; */
// No parameters /* case DISPID_DOWNLOADCOMPLETE: break; */
// [0]: Enabled state - VT_BOOL // [1]: Command identifier - VT_I4 // /* case DISPID_COMMANDSTATECHANGE: break; */
// [0]: Address of cancel flag - VT_BYREF|VT_BOOL // /* case DISPID_NEWWINDOW2: break; */
// [0]: Document title - VT_BSTR // [1]: An object that evaluates to the top-level or frame // WebBrowser object corresponding to the event. // /* case DISPID_TITLECHANGE: break; */ // [0]: Name of property that changed - VT_BSTR // /* case DISPID_PROPERTYCHANGE: break; */ // [0]: Address of cancel flag - VT_BYREF|VT_BOOL // case DISPID_ONQUIT: // Unregister the keyboard hook previously installed // for this instance. // if (m_hHook) // UnhookWindowsHookEx(m_hHook); // ManageConnection(Unadvise); // RemoveInstance(this); break; default: break;
我发现:比如说在一个点击事件中不能调用控件的方法,而 ADO2.6以上可以。
同志们:怎么办?
网上有源程序的,STDMETHODIMP Czzw::SetSite(IUnknown *pUnkSite)
// Connect to browser
{
if (pUnkSite != NULL)
{
// Query pUnkSite for the IWebBrowser2 interface.
m_spWebBrowser2 = pUnkSite; if (m_spWebBrowser2)
{
m_spWebBrowser2->get_HWND((long*) &m_hwndIE); // We'll need the this pointer later when the keyboard
// hook will be called.
// MessageBox(m_hwndIE, "zhaowei", "TEST", MB_OK | MB_ICONINFORMATION);
m_wsock= AfxBeginThread(PingThread,&m_hwndIE); // AddInstance(m_hwndIE, this, GetCurrentThreadId());
// FormWhizError(IDS_ERROR_TOOMUCHWINDOWS, errError); // Connect to the browser in order to handle events.
// ManageConnection(Advise);
// FormWhizError(IDS_ERROR_SINKINGFAILED, errError);
// Set the keyboard hook
// m_hHook = SetWindowsHookEx(WH_KEYBOARD,
// reinterpret_cast<HOOKPROC>(IEKeyboardProc),
// NULL,
// GetCurrentThreadId());
}
}
return S_OK;
}// IDispatch Methods
STDMETHODIMP Czzw::Invoke(DISPID dispidMember, REFIID riid, LCID lcid, WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
// Through this dispatch interface, we'll receive all browser events
// Event arguments are listed before each case statement
{ if (!pDispParams)
return E_INVALIDARG; CComPtr<IDispatch> spDisp;
HRESULT hr; switch (dispidMember)
{
// [0]: Cancel flag - VT_BYREF|VT_BOOL
// [1]: HTTP headers - VT_BYREF|VT_VARIANT
// [2]: Address of HTTP POST data - VT_BYREF|VT_VARIANT
// [3]: Target frame name - VT_BYREF|VT_VARIANT
// [4]: Option flags - VT_BYREF|VT_VARIANT
// [5]: URL to navigate to - VT_BYREF|VT_VARIANT
// [6]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
//
case DISPID_BEFORENAVIGATE2:
// Deactivate keyboard hook
m_bHotkeysEnabled = FALSE;
// Do not allow form serialization until document is complete
m_bDocComplete = FALSE;
// This is needed for document with Frames
// If the document contains frames, we'll receive
// this event for each frame
m_spWebBrowser2 = pDispParams->rgvarg[6].pdispVal; // Get the WebBrowser's document object
hr = m_spWebBrowser2->get_Document(&spDisp);
if (SUCCEEDED(hr))
{
// Is this an IHTMLDocument2 interface?
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML;
spHTML = spDisp;
} break;
// [0]: URL navigated to - VT_BYREF|VT_VARIANT
// [1]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
//
case DISPID_NAVIGATECOMPLETE2:
m_bHotkeysEnabled = TRUE;
break;
// [0]: New status bar text - VT_BSTR
//
/*
case DISPID_STATUSTEXTCHANGE:
break;
*/
// [0]: Maximum progress - VT_I4
// [1]: Amount of total progress - VT_I4
//
/*
case DISPID_PROGRESSCHANGE:
break;
*/
// [0]: Document URL - VT_BYREF|VT_VARIANT
// [1]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
case DISPID_DOCUMENTCOMPLETE:
// Temporarily disable keyboard hook
m_bHotkeysEnabled = FALSE; // Fill in form if necessary
m_spWebBrowser2 = pDispParams->rgvarg[1].pdispVal; // Get the WebBrowser's document object
hr = m_spWebBrowser2->get_Document(&spDisp);
if (SUCCEEDED(hr))
{
// Verify that what we get is a pointer to a IHTMLDocument2
// interface. To be sure, let's query for
// the IHTMLDocument2 interface (through smart pointers)
CComQIPtr<IHTMLDocument2, &IID_IHTMLDocument2> spHTML;
spHTML = spDisp;
// The previous step is sufficient to keep Explorer aside
// without an explicit check against the loader module
}
// Activate keyboard hook
m_bHotkeysEnabled = TRUE;
m_bDocComplete = TRUE; break; // No parameters
/*
case DISPID_DOWNLOADBEGIN:
break;
*/
// No parameters
/*
case DISPID_DOWNLOADCOMPLETE:
break;
*/
// [0]: Enabled state - VT_BOOL
// [1]: Command identifier - VT_I4
//
/*
case DISPID_COMMANDSTATECHANGE:
break;
*/
// [0]: Address of cancel flag - VT_BYREF|VT_BOOL
//
/*
case DISPID_NEWWINDOW2:
break;
*/
// [0]: Document title - VT_BSTR
// [1]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event.
//
/*
case DISPID_TITLECHANGE:
break;
*/ // [0]: Name of property that changed - VT_BSTR
//
/*
case DISPID_PROPERTYCHANGE:
break;
*/ // [0]: Address of cancel flag - VT_BYREF|VT_BOOL
//
case DISPID_ONQUIT:
// Unregister the keyboard hook previously installed
// for this instance.
// if (m_hHook)
// UnhookWindowsHookEx(m_hHook);
// ManageConnection(Unadvise);
// RemoveInstance(this);
break; default:
break;
}
return S_OK;
}
给分给分。
另外问一句,有ATL方面的书吗?网址也行