コード例 #1
0
ファイル: ExplorerElement.cpp プロジェクト: SoffidIAM/esso
std::string ExplorerElement::getComputedStyle(const char* style)
{
	std::string value;


	// pDoc = element.document
	IHTMLDocument2 *pDoc = m_pApp->getHTMLDocument2();
	if (pDoc != NULL)
	{
		IHTMLWindow2 *w = NULL;
		// w = pDoc.parentWindow
		HRESULT hr = pDoc->get_parentWindow(&w);
		if (! FAILED (hr))
		{
			IHTMLWindow7 *w7 = NULL;
			w->QueryInterface(local_IID_IHTMLWindow7, reinterpret_cast<void**>(&w7));
			if (FAILED(hr) || w7 == NULL)
			{
//				MZNSendDebugMessageA("Cannot get w7");
			}
			else
			{
				IHTMLDOMNode *node;
				HRESULT hr = m_pElement->QueryInterface(IID_IHTMLDOMNode, reinterpret_cast<void**>(&node));
				if (FAILED(hr) || node == NULL)
				{
//					MZNSendDebugMessageA("Cannot cast to htmldomnode");
				}
				else {
					IHTMLCSSStyleDeclaration *pComputedStyle;
					hr = w7->getComputedStyle(node, NULL, &pComputedStyle);
					if ( FAILED(hr))
					{
//						MZNSendDebugMessage("Cannot get computedStyle");
					} else {
						BSTR bstr = Utils::str2bstr(style);
						BSTR bstr2 = NULL;
						hr = pComputedStyle->getPropertyValue(bstr, &bstr2);
						if (FAILED(hr))
						{
//							MZNSendDebugMessage("Cannot get property on computedStyle %s", style);
						}
						else
						{
							Utils::bstr2str(value, bstr2);
							if (bstr2 != NULL)
								SysFreeString(bstr2);
						}
						SysFreeString(bstr);
						pComputedStyle -> Release();
					}
					node->Release();
				}
				w7->Release();
			}
			w->Release();
		}
	}

	return value;
}