Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

com - How to retrieve URL from a browser with UIautomation and plain C

I want to obtain the URL of the browser Internet Explorer. I found the following code (Get active Tab URL in Chrome with C++) in C++ and I am trying to convert it to plain C.

IUIAutomationCondition *pCondition = NULL;
VARIANT url;
VARIANT varProp;
varProp.vt = VT_I4;
varProp.lVal = UIA_EditControlTypeId;
hr = IUIAutomation_CreatePropertyCondition(pAutomation,UIA_ControlTypePropertyId,varProp,&pCondition);
if(SUCCEEDED(hr)){
  hr = IUIAutomationElement_FindFirst(pNode,TreeScope_Descendants,pCondition,&urlBar);
  if(urlBar!= NULL){
    IUIAutomationElement_GetCurrentPropertyValue(urlBar,UIA_ValueValuePropertyId,&url);
    MessageBox(0, url.bstrVal, L"success", 0);
  }
}
IUnknown_Release(pCondition);

This code prints the text URL "h" in the message box when I want to retrieve the value from the browser and the value should be www.amazon.com. I do not know what I am doing incorrectly. I really appreciate if someone could help me out.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The variable url.bstrVal is BSTR, then I should use MessageBoxW. With MessageBox, the code was printing only the first letter of the url. With MessageBoxW, I could print the whole URL.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...