获取鼠标选中文字 MFC

来源:互联网 发布:正规赌球软件 编辑:程序博客网 时间:2024/04/30 12:49

 

继承CDHTMLDialog的类中获取IHTMLDocument2指针,从而简单实现获取鼠标选中文字
 
没涉及frame的多层嵌套,光考虑获取IHTMLDocument2指针就搞的人头大了,
貌似CDHtmlDialog::GetDHtmlDocument()可以直接取IHTMLDocument2指针的吧
可取出来肿么都是null咧?
 
先留着下面能用的以后再研究吧 

 

 

CString strSource=_T("");BSTR bStrSelText = NULL; CComPtr<IDispatch> spDispDoc; this->m_pBrowserApp->get_Document(&spDispDoc); CComPtr<IHTMLDocument2> spHtmlDoc = NULL;      HRESULT hr = spDispDoc->QueryInterface(IID_IHTMLDocument2,(void**)&spHtmlDoc);//获取IHTMLDocument2指针,对html文件操作全靠它了 if (SUCCEEDED(hr) && spHtmlDoc != NULL) { IHTMLSelectionObject *pSelectObj=NULL; HRESULT hrObj=spHtmlDoc->get_selection(&pSelectObj); if (hrObj==S_OK && pSelectObj != NULL) { IDispatch *pDipsRange=NULL; HRESULT hrCreateRange=pSelectObj->createRange(&pDipsRange); if (hrCreateRange==S_OK && pDipsRange != NULL) { IHTMLTxtRange *pRange=NULL;  pDipsRange->QueryInterface(IID_IHTMLTxtRange,(void**)&pRange);  if (pRange!=NULL)  {  pRange->get_text(&bStrSelText);  strSource = (CString)bStrSelText;  //拿到字了  pRange->Release();  }  pDipsRange->Release(); } pSelectObj->Release(); } }


 

原创粉丝点击