// ui123.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <UIAutomation.h>
int main()
{
	IUIAutomation *g_pAutomation;
	CoInitialize(NULL);
	HRESULT hr = CoCreateInstance(__uuidof(CUIAutomation), NULL,
		CLSCTX_INPROC_SERVER, __uuidof(IUIAutomation),
		(void**)&g_pAutomation);
	if (FAILED(hr))
		return (hr);
	// High DPI
	POINT pt;
	GetPhysicalCursorPos(&pt);
	IUIAutomationElement *pAtMouse;
	hr = g_pAutomation->ElementFromPoint(pt, &pAtMouse);
	if (FAILED(hr))
		return hr;
	// Get the element's name and print it
	BSTR name;
	hr = pAtMouse->get_CurrentName(&name);
	if (SUCCEEDED(hr))
	{
		wprintf(L"Element's Name: %s \n", name);
		SysFreeString(name);
	}
	// Get the element's Control Type (in the current languange)
	// and print it
	BSTR controlType;
	hr = pAtMouse->get_CurrentLocalizedControlType(&controlType);
	if (SUCCEEDED(hr))
	{
		wprintf(L"Element's Control Type: %s \n", controlType);
		SysFreeString(controlType);
	}
	// Clean up our COM pointers
	pAtMouse->Release();
	g_pAutomation->Release();
	CoUninitialize();
	system("PAUSE");
    return 0;
}