Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
608 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 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...