{"id":224,"date":"2014-07-23T05:21:38","date_gmt":"2014-07-23T14:21:38","guid":{"rendered":"http:\/\/blog.box.kr\/?p=224"},"modified":"2014-07-23T05:21:38","modified_gmt":"2014-07-23T14:21:38","slug":"handling-html-element-events","status":"publish","type":"post","link":"https:\/\/blog.box.kr\/?p=224","title":{"rendered":"Handling HTML Element Events"},"content":{"rendered":"<div class=\"topic\" style=\"color: #000000;\">\n<address class=\"title\" style=\"color: #000000;\"><a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx\">http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx<\/a><\/address>\n<h1 class=\"title\" style=\"color: #000000;\"><\/h1>\n<h1 class=\"title\" style=\"color: #000000;\">Handling HTML Element Events<\/h1>\n<div id=\"ratingCounter\"><span id=\"rcA\" class=\"ratingText\" style=\"color: #5d5d5d;\">9 out of 10 rated this helpful\u00a0<span id=\"rateThisPrefix\">&#8211;\u00a0<\/span><a id=\"rateThisTopic\" style=\"color: #03697a;\" title=\"Rate this topic\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#feedback\">Rate this topic<\/a><\/span>\n<\/div>\n<div class=\"clsDocBody\">\n<p style=\"color: #2a2a2a;\">The\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa741864(v=vs.85).aspx\">HTMLElementEvents2<\/a>\u00a0interface is an event sink interface that enables an application to receive events for HTML elements. Your custom application can receive these events, which are fired in response to user actions on HTML elements, when hosting the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752040(v=vs.85).aspx\">WebBrowser Control<\/a>\u00a0or automating Windows Internet Explorer.<\/p>\n<p style=\"color: #2a2a2a;\">The\u00a0<strong>HTMLElementEvents2<\/strong>\u00a0interface is introduced and the steps required to receive notification of HTML element events from the browser are described, using Microsoft Visual Studio 5 or later.<\/p>\n<p style=\"color: #2a2a2a;\">It is assumed that a Microsoft Foundation Classes (MFC) application is hosting the\u00a0<strong>WebBrowser Control<\/strong>, or launching Internet Explorer.<\/p>\n<p style=\"color: #2a2a2a;\">This article is divided into the following sections.<\/p>\n<ul>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#Document\">Accessing the DHTML Object Model<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#get_all\">Accessing an Element on the Page<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#Sink\">Receiving Element Events<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#MFC\">Handling Events using MFC<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#ATL\">Handling Events using ATL<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx#RelatedTopics\">Related Topics<\/a><\/li>\n<\/ul>\n<h2 style=\"color: #000000;\"><a id=\"Document\" style=\"color: #1364c4;\"><\/a>Accessing the DHTML Object Model<\/h2>\n<p style=\"color: #2a2a2a;\">The\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752134(v=vs.85).aspx\">IWebBrowser2::Navigate2<\/a>\u00a0method of the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752127(v=vs.85).aspx\">IWebBrowser2<\/a>\u00a0interface allows you to navigate the browser to a URL. Once an HTML page is loaded, you can access the HTML elements through the Dynamic HTML (DHTML) Object Model.<\/p>\n<p style=\"color: #2a2a2a;\">The DHTML Object Model is used to access and manipulate the contents of an HTML page and is not available until the page is loaded. Your application determines that the page is loaded by handling the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa768282(v=vs.85).aspx\">DWebBrowserEvents2::DocumentComplete<\/a>\u00a0event of the<strong>WebBrowser Control<\/strong>. This event may be fired once for each frame in the page, and once when the top frame of the document is loaded. You can determine if the\u00a0<strong>DWebBrowserEvents2::DocumentComplete<\/strong>\u00a0event is for the top frame by comparing the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms221608(v=vs.85).aspx\">IDispatch<\/a>interface pointer passed by this event with that of the\u00a0<strong>WebBrowser Control<\/strong>.<\/p>\n<p style=\"color: #2a2a2a;\">This sample handler code for the\u00a0<strong>DWebBrowserEvents2::DocumentComplete<\/strong>\u00a0event demonstrates how to determine if this event is for the top frame, which indicates that the HTML page has loaded. This sample also demonstrates how to create a stream from a block of memory\u2014in this case a string that contains the HTML content to be displayed. The variable\u00a0<code>m_pBrowser<\/code>\u00a0contains the\u00a0<strong>IWebBrowser2<\/strong>\u00a0interface pointer obtained from the\u00a0<strong>WebBrowser Control<\/strong>.<\/p>\n<div id=\"code-snippet-1\" class=\"codeSnippetContainer\">\n<div class=\"codeSnippetContainerTabs\">\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\">\n<div class=\"codeSnippetToolBar\">\n<\/div>\n<div id=\"CodeSnippetContainerCode_c798b60a-b210-4b0f-9675-27863107f84d\" class=\"codeSnippetContainerCode\" dir=\"ltr\">\n<pre>void CMyClass::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)\n{\n    HRESULT hr;\n    IUnknown* pUnkBrowser = NULL;\n    IUnknown* pUnkDisp = NULL;\n    IDispatch* pDocDisp = NULL;\n    IHTMLDocument2* pDoc = NULL;\n\n    \/\/ Is this the DocumentComplete event for the top frame window?\n    \/\/ Check COM identity: compare IUnknown interface pointers.\n    hr = m_pBrowser-&gt;QueryInterface(IID_IUnknown, (void**)&amp;pUnkBrowser);\n\n    if (SUCCEEDED(hr))\n    {\n        hr = pDisp-&gt;QueryInterface(IID_IUnknown, (void**)&amp;pUnkDisp);\n\n        if (SUCCEEDED(hr))\n        {\n            if (pUnkBrowser == pUnkDisp)\n            {\n                \/\/ This is the DocumentComplete event for the top frame.\n                \/\/ This page is loaded, so we can access the DHTML Object Model.\n                hr = m_pBrowser-&gt;get_Document(&amp;pDocDisp);\n\n                if (SUCCEEDED(hr))\n                {\n                    \/\/ Obtained the document object.\n                    pDocDisp-&gt;QueryInterface(IID_IHTMLDocument2, (void**)&amp;pDoc);\n                    if (SUCCEEDED(hr))\n                    {\n                        \/\/ Obtained the IHTMLDocument2 interface for the document object\n                        ProcessDocument(pDoc);\n                    }\n\n                    pDocDisp-&gt;Release();\n                }\n            }\n\n            pUnkDisp-&gt;Release();\n        }\n\n        pUnkBrowser-&gt;Release();\n    }\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"color: #2a2a2a;\">The\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752116(v=vs.85).aspx\">IWebBrowser2::get_Document<\/a>\u00a0property on the\u00a0<strong>WebBrowser Control<\/strong>\u00a0retrieves the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms531073(v=vs.85).aspx\">document<\/a>\u00a0object that represents the DHTML Object Model for the top frame.<\/p>\n<h2 style=\"color: #000000;\"><a id=\"get_all\" style=\"color: #1364c4;\"><\/a>Accessing an Element on the Page<\/h2>\n<p style=\"color: #2a2a2a;\">Using the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752574(v=vs.85).aspx\">IHTMLDocument2<\/a>\u00a0interface pointer, you can request a collection of all elements in the HTML document through the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752582(v=vs.85).aspx\">all<\/a>\u00a0property.<\/p>\n<div id=\"code-snippet-2\" class=\"codeSnippetContainer\">\n<div class=\"codeSnippetContainerTabs\">\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\">\n<div class=\"codeSnippetToolBar\">\n<\/div>\n<div id=\"CodeSnippetContainerCode_3573c896-06bf-4e11-9718-1b8557258bbe\" class=\"codeSnippetContainerCode\" dir=\"ltr\">\n<pre>void CMyClass::ProcessDocument(IHTMLDocument2* pDoc)\n{\n    IHTMLElementCollection* pElemColl = NULL;\n\n    hr = pDoc-&gt;get_all(&amp;pElemColl);\n    if (SUCCEEDED(hr))\n    {\n        \/\/ Obtained element collection.\n        ProcessElementCollection(pElemColl);\n        pElemColl-&gt;Release();\n    }\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"color: #2a2a2a;\">The\u00a0<strong>all<\/strong>\u00a0property returns a collection of all the HTML elements on the page through an\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa703928(v=vs.85).aspx\">IHTMLElementCollection<\/a>\u00a0interface pointer. You can use the\u00a0<strong>IHTMLElementCollection<\/strong>\u00a0interface to call the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms536460(v=vs.85).aspx\">item<\/a>\u00a0method and pass the name or\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms533880(v=vs.85).aspx\">id<\/a>\u00a0of an element as a parameter, as shown in the following code.<\/p>\n<div class=\"clsNote\"><strong>Note<\/strong>\u00a0\u00a0The\u00a0<strong>item<\/strong>\u00a0method will return a collection if there is more than one element with the specified name or\u00a0<strong>id<\/strong>. To prevent a collection from being returned, provide an index as the second parameter of\u00a0<strong>item<\/strong>\u00a0to specify which element should be returned.\n<\/div>\n<div id=\"code-snippet-3\" class=\"codeSnippetContainer\">\n<div class=\"codeSnippetContainerTabs\">\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\">\n<div class=\"codeSnippetToolBar\">\n<\/div>\n<div id=\"CodeSnippetContainerCode_61378388-18d9-41bf-a272-702d0f9fddca\" class=\"codeSnippetContainerCode\" dir=\"ltr\">\n<pre>void CMyClass::ProcessElementCollection(IHTMLElementCollection* pElemColl)\n{\n    IDispatch* pElemDisp = NULL;\n    IHTMLElement* pElem = NULL;\n    _variant_t varID(\"myID\", VT_BSTR);\n    _variant_t varIdx(0, VT_I4);\n\n    hr = pElemColl-&gt;item(varID, varIdx, &amp;pElemDisp);\n\n    if (SUCCEEDED(hr))\n    {\n        hr = pElemDisp-&gt;QueryInterface(IID_IHTMLElement, (void**)&amp;pElem);\n\n        if (SUCCEEDED(hr))\n        {\n            \/\/ Obtained element with ID of \"myID\".\n            ConnectEvents(pElem);\n            pElem-&gt;Release();\n        }\n\n        pElemDisp-&gt;Release();\n    }\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"color: #2a2a2a;\">If you are working with HTML tags of a specific type, such as\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms535173(v=vs.85).aspx\">a<\/a>\u00a0tags, the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa703932(v=vs.85).aspx\">IHTMLElementCollection::tags<\/a>\u00a0method returns a collection of all the elements that have the requested HTML tag name, also through an\u00a0<strong>IHTMLElementCollection<\/strong>\u00a0interface pointer.<\/p>\n<h2 style=\"color: #000000;\"><a id=\"Sink\" style=\"color: #1364c4;\"><\/a>Receiving Element Events<\/h2>\n<p style=\"color: #2a2a2a;\">Each element in the DHTML Object Model supports an outgoing\u00a0<strong>HTMLElementEvents2<\/strong>\u00a0interface. This interface defines the events that an HTML element can fire. You implement this interface to provide an\u00a0<em>event sink<\/em>, which is a Component Object Model (COM) object that implements an outgoing interface and is used as the mechanism for firing events.<\/p>\n<div class=\"clsNote\"><strong>Note<\/strong>\u00a0\u00a0Interfaces implemented by a server usually have their methods called by the client, but to fire an event, the server calls the respective method on the client event sink. These interface are called\u00a0<em>outgoing interfaces<\/em>. A COM object that implements an outgoing interface is also known as a\u00a0<em>connectable object<\/em>.\n<\/div>\n<p style=\"color: #2a2a2a;\">The following steps are required to receive events from an outgoing interface:<\/p>\n<ol>\n<li>\n<p style=\"color: #2a2a2a;\">Implement the event sink.<\/p>\n<p style=\"color: #2a2a2a;\">The event sink implements the appropriate outgoing interface and methods. Internet Explorer event interfaces are\u00a0<em>dispinterfaces<\/em>, so calls to event methods are made through\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms221479(v=vs.85).aspx\">IDispatch::Invoke<\/a>. This means that you only need to implement the\u00a0<strong>IDispatch<\/strong>\u00a0interface to handle events.<\/p>\n<\/li>\n<li>\n<p style=\"color: #2a2a2a;\">Determine if the server is a connectable object.<\/p>\n<p style=\"color: #2a2a2a;\">Call\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms682521(v=vs.85).aspx\">QueryInterface<\/a>\u00a0to retrieve a pointer to the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms683857(v=vs.85).aspx\">IConnectionPointContainer<\/a>\u00a0interface.<\/p>\n<\/li>\n<li>\n<p style=\"color: #2a2a2a;\">Find the appropriate connection point.<\/p>\n<p style=\"color: #2a2a2a;\">Call the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms692476(v=vs.85).aspx\">IConnectionPointContainer::FindConnectionPoint<\/a>\u00a0method to find the connection point you need. For Internet Explorer\u00a0<strong>WebBrowser Control<\/strong>\u00a0events, such as\u00a0<strong>DWebBrowserEvents2::DocumentComplete<\/strong>, this is\u00a0<strong>DWebBrowserEvents2<\/strong>. For element events, this is\u00a0<strong>HTMLElementEvents2<\/strong>. You can also call the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms682460(v=vs.85).aspx\">IConnectionPointContainer::EnumConnectionPoints<\/a>\u00a0to enumerate through all the connection points a server supports.<\/p>\n<\/li>\n<li>\n<p style=\"color: #2a2a2a;\">Advise the connection point that you want to receive events.<\/p>\n<p style=\"color: #2a2a2a;\">Using the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms694318(v=vs.85).aspx\">IConnectionPoint<\/a>\u00a0interface pointer returned in the previous step, call\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms678815(v=vs.85).aspx\">IConnectionPoint::Advise<\/a>, passing the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms680509(v=vs.85).aspx\">IUnknown<\/a>\u00a0interface pointer of your event sink.<\/p>\n<div class=\"clsNote\"><strong>Note<\/strong>\u00a0\u00a0The connectable object will use the\u00a0<strong>IUnknown<\/strong>\u00a0interface pointer to query the client for the event sink interface. If the event sink does not support the outgoing interface, Internet Explorer will query the client for the\u00a0<strong>IDispatch<\/strong>\u00a0interface.\n<\/div>\n<\/li>\n<li>When you no longer want to receive events, you can call the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms686608(v=vs.85).aspx\">IConnectionPoint::Unadvise<\/a>\u00a0method, passing the cookie you received from the call to\u00a0<strong>IConnectionPoint::Advise<\/strong>.<\/li>\n<\/ol>\n<p style=\"color: #2a2a2a;\">The following sample code demonstrates how to begin receiving HTML element events for an element on an HTML page.<\/p>\n<div id=\"code-snippet-4\" class=\"codeSnippetContainer\">\n<div class=\"codeSnippetContainerTabs\">\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\">\n<div class=\"codeSnippetToolBar\">\n<\/div>\n<div id=\"CodeSnippetContainerCode_b6e65657-a46c-496b-bd36-624f7fe2ffc5\" class=\"codeSnippetContainerCode\" dir=\"ltr\">\n<pre>void CMyClass::ConnectEvents(IHTMLElement* pElem)\n{\n    HRESULT hr;\n    IConnectionPointContainer* pCPC = NULL;\n    IConnectionPoint* pCP = NULL;\n    DWORD dwCookie;\n\n    \/\/ Check that this is a connectable object.\n    hr = pElem-&gt;QueryInterface(IID_IConnectionPointContainer, (void**)&amp;pCPC);\n\n    if (SUCCEEDED(hr))\n    {\n        \/\/ Find the connection point.\n        hr = pCPC-&gt;FindConnectionPoint(DIID_HTMLElementEvents2, &amp;pCP);\n\n        if (SUCCEEDED(hr))\n        {\n            \/\/ Advise the connection point.\n            \/\/ pUnk is the IUnknown interface pointer for your event sink\n            hr = pCP-&gt;Advise(pUnk, &amp;dwCookie);\n\n            if (SUCCEEDED(hr))\n            {\n                \/\/ Successfully advised\n            }\n\n            pCP-&gt;Release();\n        }\n\n        pCPC-&gt;Release();\n    }\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<p style=\"color: #2a2a2a;\">The following sample code demonstrates how you would detect the firing of an\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa769647(v=vs.85).aspx\">HTMLElementEvents2::onclick<\/a>\u00a0event in your implementation of\u00a0<strong>IDispatch::Invoke<\/strong>.<\/p>\n<div id=\"code-snippet-5\" class=\"codeSnippetContainer\">\n<div class=\"codeSnippetContainerTabs\">\n<\/div>\n<div class=\"codeSnippetContainerCodeContainer\">\n<div class=\"codeSnippetToolBar\">\n<\/div>\n<div id=\"CodeSnippetContainerCode_3ec0b0fb-068f-4bda-b2f1-26a970588b30\" class=\"codeSnippetContainerCode\" dir=\"ltr\">\n<pre>STDMETHODIMP CEventSink::Invoke(DISPID dispidMember,\n                                REFIID riid,\n                                LCID lcid,\n                                WORD wFlags,\n                                DISPPARAMS* pdispparams,\n                                VARIANT* pvarResult,\n                                EXCEPINFO* pexcepinfo,\n                                UINT* puArgErr)\n{\n    switch (dispidMember)\n    {\n        case DISPID_HTMLELEMENTEVENTS2_ONCLICK:\n        OnClick();\n        break;\n\n        default:\n        break;\n    }\n\n    return S_OK;\n}\n<\/pre>\n<\/div>\n<\/div>\n<\/div>\n<h2 style=\"color: #000000;\"><a id=\"MFC\" style=\"color: #1364c4;\"><\/a>Handling Events using MFC<\/h2>\n<ul>\n<li>The MFC\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/x9w7txst(VS.71).aspx\" target=\"_top\">CCmdTarget<\/a>\u00a0class implements the\u00a0<strong>IDispatch<\/strong>\u00a0interface, which means that any class derived from this class can implement an event sink. The\u00a0<strong>IDispatch<\/strong>\u00a0feature requires a call to the\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/564b17z4(VS.71).aspx\" target=\"_top\">CCmdTarget::EnableAutomation<\/a>\u00a0method.<\/li>\n<li>The MFC\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/b9h84ebk(VS.71).aspx\" target=\"_top\">AfxConnectionAdvise<\/a>\u00a0and\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/y722wx18(VS.71).aspx\" target=\"_top\">AfxConnectionUnadvise<\/a>\u00a0functions find a specified connection point and then advise or unadvise appropriately.<\/li>\n<li>The DECLARE_DISPATCH_MAP, BEGIN_DISPATCH_MAP, DISP_FUNCTION, DISP_FUNCTION_ID and END_DISPATCH_MAP macros are used to map each event method to your event handler function.<\/li>\n<li>When handling events from a Microsoft ActiveX control you are hosting in your MFC applications, use the DECLARE_EVENTSINK_MAP, BEGIN_EVENTSINK_MAP, ON_EVENT and END_EVENTSINK_MAP macros.<\/li>\n<li>If you are hosting the\u00a0<strong>WebBrowser Control<\/strong>\u00a0on a dialog box, you can use the Microsoft Visual C++ ClassWizard to map events to event handlers.<\/li>\n<li>The MFC\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/42h6dke4(VS.71).aspx\" target=\"_top\">CHtmlView<\/a>\u00a0class hosts the\u00a0<strong>WebBrowser Control<\/strong>\u00a0and provides overridable methods for the\u00a0<strong>WebBrowser Control<\/strong>\u00a0events.<\/li>\n<\/ul>\n<h2 style=\"color: #000000;\"><a id=\"ATL\" style=\"color: #1364c4;\"><\/a>Handling Events using ATL<\/h2>\n<ul>\n<li>When implementing an event sink using the Active Template Library (ATL), your object class will usually derive from the\u00a0<span class=\"unresolvedLink\">IDispatchImpl<\/span>\u00a0class, which provides a default implementation of the\u00a0<strong>IDispatch<\/strong>\u00a0interface. You can the override the ATL implementation of the<strong>IDispatch::Invoke<\/strong>\u00a0method to handle events.<\/li>\n<li>ATL provides two helper functions,\u00a0<span class=\"unresolvedLink\">AtlAdvise<\/span>\u00a0and\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/7s2bbwhc(VS.71).aspx\" target=\"_top\">AtlUnadvise<\/a>, for advising and unadvising a connection point. These find a specified connection point and then advise or unadvise appropriately.<\/li>\n<li>You can also use the ATL\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/d7eecxta(VS.71).aspx\" target=\"_top\">IDispEventImpl<\/a>\u00a0and\u00a0<a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/fwy24613(VS.71).aspx\" target=\"_top\">IDispEventSimpleImpl<\/a>\u00a0classes and BEGIN_SINK_MAP, SINK_ENTRY, SINK_ENTRY_EX and END_SINK_MAP macros to implement an event sink. If you need to host the\u00a0<strong>WebBrowser Control<\/strong>, you can use the ATL Object Wizard to create an HTML object.<\/li>\n<\/ul>\n<h2 style=\"color: #000000;\"><a id=\"RelatedTopics\" style=\"color: #1364c4;\"><\/a>Related Topics<\/h2>\n<p style=\"color: #2a2a2a;\">The following articles provide information about the\u00a0<strong>WebBrowser Control<\/strong>\u00a0and\u00a0<span class=\"clsGlossary\">MSHTML<\/span>.<\/p>\n<ul>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752044(v=vs.85).aspx\">Reusing the WebBrowser Control<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/aa752046(v=vs.85).aspx\">Using MFC to Host a WebBrowser Control<\/a><\/li>\n<li><strong>MSHTML Event DispInterfaces<\/strong><\/li>\n<\/ul>\n<p style=\"color: #2a2a2a;\">The following articles provide information about Visual Studio.<\/p>\n<ul>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=204333\" target=\"_top\">Visual Studio Developer Center<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=203617\" target=\"_top\">HOWTO: Create a Sink Interface in MFC-Based COM Client<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=203616\" target=\"_top\">AtlSink Uses ATL to Create a Dispinterface Sink<\/a><\/li>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=203619\" target=\"_top\">SAMPLE: AtlEvnt.exe Creates ATL Sinks Using IDispEventImpl<\/a><\/li>\n<\/ul>\n<p style=\"color: #2a2a2a;\">The following articles provide information about COM.<\/p>\n<ul>\n<li><a style=\"color: #03697a;\" href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=203663\" target=\"_top\">The Component Object Model Specification<\/a><\/li>\n<li><em>Inside OLE<\/em>, 2nd Edition, by Kraig Brockschmidt (Microsoft Press)<\/li>\n<li><em>Understanding ActiveX and OLE<\/em>, by David Chappell (Microsoft Press)<\/li>\n<li><em>Inside COM<\/em>, by Dale Rogerson (Microsoft Press)<\/li>\n<\/ul>\n<\/div>\n<\/div>\n<div class=\"communityContentContainer\" style=\"color: #000000;\">\n<div id=\"CommunityContentHeader\" class=\"communityContentHeader\">\n<div class=\"communityContentHeaderTitleContainer\">\n<h2 style=\"color: green;\">Community Additions<\/h2>\n<p><a class=\"communityContentAddLink\" style=\"color: #ffffff;\" href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/community\/add\/bb508508(v=vs.85).aspx\"><span class=\"communityContentAddButton\" style=\"color: #2c729c;\" title=\"Add\">ADD<\/span><\/a><\/p>\n<\/div>\n<div>\n<\/div>\n<\/div>\n<div id=\"CommunityComments\" data-url=\"\/en-us\/library\/community\/comments\/bb508508(v=vs.85).aspx\">\n<div class=\"communityContentAnnotation\" style=\"color: #2a2a2a;\"><a name=\"2\"><\/a><\/p>\n<h3 style=\"color: #000000;\">Eventobject has not found when click in case of few pages<\/h3>\n<div class=\"communityContentAnnotationBody\">Hi,<br \/>\nFirst of all thanks for providing help.The above code works most of the time as expected.<br \/>\nBut the it fails in case of few pages.<br \/>\nIn such page, event is being successfully attached i.e. connect event method works.<br \/>\nBut, I couldn&#8217;t found the element on which the event has being generating, once someone click(in my case)<\/p>\n<p>Thanks, any help would really appreciate.<\/p>\n<\/div>\n<div class=\"communityContentAnnotationInfo\">\n<div class=\"communityContentAnnotationAvatarContainer\"><a class=\"communityContentAnnotationAvatar\" title=\"\" href=\"http:\/\/social.msdn.microsoft.com\/profile\/harishladhani\/\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/i1.social.s-msft.com\/profile\/u\/avatar.jpg?resize=34%2C34\" alt=\"\" width=\"34\" height=\"34\" data-recalc-dims=\"1\" \/><\/a>\n<\/div>\n<div class=\"communityContentAnnotationUserDateContainer\">\n<div class=\"communityContentAnnotationUserContainer\" style=\"color: #2c729c;\"><a style=\"color: #2c729c;\" href=\"http:\/\/social.msdn.microsoft.com\/profile\/harishladhani\/\">harishladhani<\/a>\n<\/div>\n<div class=\"communityContentAnnotationDateContainer\">2\/3\/2012\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<div class=\"communityContentAnnotation\" style=\"color: #2a2a2a;\"><a name=\"1\"><\/a><\/p>\n<h3 style=\"color: #000000;\">ConnectEvents &#8211; unclear what pUnk is<\/h3>\n<div class=\"communityContentAnnotationBody\">\n<div>\n<p>It&#8217;s unclear as to how one would get the IUnknown pUnk in the ConnectEvents function (especially when using ATL to handle events ) ? How should the event sink be declared and initialized &#8211; for this purpose?\n<\/p><\/div>\n<div>\n<\/div>\n<\/div>\n<div class=\"communityContentAnnotationInfo\">\n<div class=\"communityContentAnnotationAvatarContainer\"><a class=\"communityContentAnnotationAvatar\" title=\"\" href=\"http:\/\/social.msdn.microsoft.com\/profile\/gotamye\/\"><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/i0.wp.com\/i1.social.s-msft.com\/profile\/u\/avatar.jpg?resize=34%2C34\" alt=\"\" width=\"34\" height=\"34\" data-recalc-dims=\"1\" \/><\/a>\n<\/div>\n<div class=\"communityContentAnnotationUserDateContainer\">\n<div class=\"communityContentAnnotationUserContainer\" style=\"color: #2c729c;\"><a style=\"color: #2c729c;\" href=\"http:\/\/social.msdn.microsoft.com\/profile\/gotamye\/\">GotAmye<\/a>\n<\/div>\n<div class=\"communityContentAnnotationDateContainer\">7\/15\/2009\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/msdn.microsoft.com\/en-us\/library\/bb508508(v=vs.85).aspx Handling HTML Element Events 9 out of 10 rated this helpful\u00a0&#8211;\u00a0Rate this topic The\u00a0HTMLElementEvents2\u00a0interface is an event sink interface that enables an application to receive events for HTML elements. Your custom application can receive these events, which are fired in response to user actions on HTML elements, when hosting the\u00a0WebBrowser Control\u00a0or automating Windows Internet Explorer. The\u00a0HTMLElementEvents2\u00a0interface is introduced and the steps required to receive notification of HTML element events from the browser are described, using Microsoft Visual Studio 5 or later. It is assumed that a Microsoft Foundation Classes (MFC) application is hosting the\u00a0WebBrowser Control, or launching Internet Explorer. This article is divided into the following sections. Accessing the DHTML Object Model Accessing an Element on the Page Receiving Element Events Handling Events using MFC Handling Events using ATL Related Topics Accessing the DHTML Object Model The\u00a0IWebBrowser2::Navigate2\u00a0method of the\u00a0IWebBrowser2\u00a0interface allows you to navigate the browser to a URL. Once an HTML page is loaded, you can access the HTML elements through the Dynamic HTML (DHTML) Object Model. The DHTML Object Model is used to access and manipulate the contents of an HTML page and is not available until the page is loaded. Your application determines that the page is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"ngg_post_thumbnail":0,"spay_email":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[9,19,7],"tags":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p5q9Zn-3C","jetpack-related-posts":[{"id":234,"url":"https:\/\/blog.box.kr\/?p=234","url_meta":{"origin":224,"position":0},"title":"Using the WebBrowser Control from C\/C++","date":"2014-07-23","format":false,"excerpt":"Using the WebBrowser Control from C\/C++ \u00a0 This section describes some of the common implementations of the WebBrowser control, including: Adding Internet browsing functionality to your application Printing Web pages with the WebBrowser control Changing fonts with the WebBrowser control Working with WebBrowser events Adding Internet Browsing Functionality to Your\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":762,"url":"https:\/\/blog.box.kr\/?p=762","url_meta":{"origin":224,"position":1},"title":"Install and configure Nginx, MariaDB &amp; PHP-FPM in CentOS 7 (RHEL7)","date":"2015-05-08","format":false,"excerpt":"https:\/\/stavrovski.net\/blog\/install-and-configure-nginx-mariadb-php-fpm-in-centos-7-rhel7 \u00a0 The following is a quick-N-dirty write-up on\u00a0how to install and configure the LEMP stack (Nginx, MariaDB and PHP-FPM) in\u00a0CentOS 7. I use this as a reference\/guide whenever I need to deploy the\u00a0LEMP stack\u00a0on RHEL based machines. TABLE OF CONTENTS Enable EPEL Repository Update CentOS 7 Install and configure\u2026","rel":"","context":"In &quot;Linux&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":248,"url":"https:\/\/blog.box.kr\/?p=248","url_meta":{"origin":224,"position":2},"title":"[\uac1c\ubc1c\/VC++] WebBrowser Control \uc774\ubca4\ud2b8 \uc5f0\uacb0 &#8211; C++","date":"2014-07-23","format":false,"excerpt":"IT\/\uac1c\ubc1c\u00a02011\/02\/10 12:12 [\uac1c\ubc1c\/VC++] WebBrowser Control \uc774\ubca4\ud2b8 \uc5f0\uacb0 - C++ WebBrowser Control IDispatch IWebBrowser2 .ReadyState READYSTATE_COMPLETE .Navigate2() .get_Document() \/\/ IDispatch -> IHTMLDocument2 .get_StatusText() on DownloadBegin on DocumentComplete on DownloadComplete IOleObject \u00a0 IHTMLWindow2 IHTMLDocument2 .get_all() .get_parentWindow() \/\/ IHTMLWindow2 IHTMLElementCollection .item() .tags \/\/ IHTMLElementCollection IHTMLElement a connectable object IConnectionPointContainer .FindConnectionPoint() \/\/ DHTMLElementEvents2 DHTMLElementEvents2\u2026","rel":"","context":"In &quot;C\/C++&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":135,"url":"https:\/\/blog.box.kr\/?p=135","url_meta":{"origin":224,"position":3},"title":"Tomcat MySQL Connection &#8211; Using JDBC to Connect Tomcat to MySQL","date":"2014-06-24","format":false,"excerpt":"Tomcat MySQL Connection - Using JDBC to Connect Tomcat to MySQL Stumped by Tomcat JDBC connections? Can't get your head around MySQL drivers, connection pools, and JNDI resources? This article will guide you step-by-step through\u00a0connecting your MySQL database to Tomcat, in plain English. Along the way, we'll also cover setting\u2026","rel":"","context":"In &quot;WAS, Servet Containers&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":80,"url":"https:\/\/blog.box.kr\/?p=80","url_meta":{"origin":224,"position":4},"title":"WebTob + Jeus \uc5f0\ub3d9\ud6c4 \ucc98\ub9ac","date":"2014-06-12","format":false,"excerpt":"WebTob + Jeus \uc5f0\ub3d9\ud6c4 \ucc98\ub9ac webtob\ub294 ws(webserver)\uc785\ub2c8\ub2e4. ws\uac00 \ucc98\ub9ac \ud560 \uc218 \uc788\ub294 \uac74 html, htm, gif, jpg, cgi \ub4f1 \uc815\uc801\uc778 \ud30c\uc77c\ub4e4 \uc774\uba70, jsp, servlet, ejb\uc640 \uac19\uc740 \ub3d9\uc801\uc778 \ud30c\uc77c\ub4e4\uc740 was\uc778 jeus\uc5d0\uc11c \ucc98\ub9ac \ud569\ub2c8\ub2e4. \uadf8\ub7ec\ubbc0\ub85c, jsp \ud30c\uc77c\ub4e4\uc740 jeus\uc5d0 \ub4f1\ub85d\ub41c context\uc758 WEB-INF\/jeus-web-dd.xml \ud30c\uc77c\uc758 docbase (\ub610\ub294, jeus-web-dd.xml \ud30c\uc77c\uc774 \uc5c6\ub2e4\uba74, JEUSMain.xml \uc5d0 \ub4f1\ub85d\ub41c application\uc758 path)\u2026","rel":"","context":"In &quot;JEUS &amp; WEBToB&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":945,"url":"https:\/\/blog.box.kr\/?p=945","url_meta":{"origin":224,"position":5},"title":"TCPDump: Capture and Record Specific Protocols \/ Port","date":"2015-07-28","format":false,"excerpt":"http:\/\/www.cyberciti.biz\/faq\/tcpdump-capture-record-protocols-port\/ Q. How do I capture specific protocol or port such as 80 ( http ) using TCPDump tool under Linux \/ UNIX? How do I recording Traffic with TCPDump and find problems later on? A. TCPDump is a tool for network monitoring and data acquisition. It can save lots\u2026","rel":"","context":"In &quot;\uae30\uc220&quot;","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/224"}],"collection":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=224"}],"version-history":[{"count":0,"href":"https:\/\/blog.box.kr\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.box.kr\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}