描述:
I write down some test code to work with IHTMLDocument2. However, I found the IHTMLDocument2 can’t control the specific HTML document as expected. For example, I create the following code to change background color.
BOOL CALLBACK EnumChildProc(HWND hwnd,LPARAM lParam)
{
TCHAR buf[100];
::GetClassName( hwnd, (LPTSTR)&buf, 100 );
if ( System::String::Compare(buf, "Internet Explorer_Server") == 0 )
{
*(HWND*)lParam = hwnd;
return FALSE;
}
else
return TRUE;
};
void html()
{
HWND hWnd =FindWindow(NULL, "C:\\Documents and Settings\\v-yhyang\\Desktop\\test.html - Microsoft Internet Explorer");
if ( hWnd != NULL )
{
HWND hWndChild=NULL;
::EnumChildWindows( hWnd, EnumChildProc, (LPARAM)&hWndChild );
if ( hWndChild )
{
IHTMLDocument2* spDoc;
IHTMLElement* ele;
LRESULT lRes;
HRESULT hr;
UINT nMsg = ::RegisterWindowMessage( "WM_HTML_GETOBJECT");
::SendMessageTimeout( hWndChild, nMsg, 0L, 0L, SMTO_ABORTIFHUNG, 1000, (DWORD*)&lRes );
hr = ObjectFromLresult( lRes, IID_IHTMLDocument, 0, (void**)&spDoc );
if ( SUCCEEDED(hr) )
{
VARIANT v;
您可能想查找下面的文章:
- 为什么获取的IHTMLDocument2指针不能用
- 网页里有一个封装好的htc控件,该控件中有一些input输入框,我能不能通过IHTMLDocument2指针获取htc控件中的这些输入框内容
- 为什么在可编辑模式下的IHTMLDocument2接口取不到子element?
- 用IHTMLDocument2::execCommand的saveas将一个html文件保存为txt执行,为什么不行?
- 如何得到IID_IHTMLDocument2的指针呢?
- 在IE点击弹出一个新的窗口页面,如何获得这个页面的IHTMLDocument2?
- IHTMLDocument2,IHTMLElement如何释放?
- IHTMLDocument::getElementByName函数的问题。
- 100分请教个IHTMLDocument2问题
- 通过IHTMLDocument2接口只能得到body源码,有设呢方法可以到的head的源码?