I need to get control value / text through automation interface (coding with C ++ / C #). I tried with the UI Automation API , and this is some result obtained using Check :

pane, / .
, MSAA, Automation Spy .
, , ListView20WndClass, Slider20WndClass,... Visual Basic 6.
, - API, ?
1:
Ranorex ( , 3490 ), , API:


2
, UI Automation :
- ThunderRT6FormDC:
- ThunderRT6CommandButton:
- ThunderRT6CheckBox:
- ....
- , ListView20WndClass Slider20WndClass,
1
, ( ):
#include <iostream>
using namespace std;
#include <UIAutomation.h>
#include <atlstr.h>
#include <Commctrl.h>
CString getListViewItemText(HWND hwnd, int nItem, int nSubItem) {
LVITEM item;
memset(&item, 0, sizeof(LVITEM));
item.iSubItem = nSubItem;
CString string;
int Length = 64;
int ReturnCode;
do {
Length *= 2;
item.cchTextMax = Length;
item.pszText = string.GetBufferSetLength(Length);
ReturnCode = (int)::SendMessage(hwnd, LVM_GETITEMTEXT,
(WPARAM)nItem, (LPARAM)&item);
printf("len = %d \n", ReturnCode);
} while (ReturnCode == Length - 1);
string.ReleaseBuffer();
return string;
}
void UI_Spy() {
CoInitialize(NULL);
IUIAutomation *pAuto;
CoCreateInstance(CLSID_CUIAutomation, NULL,
CLSCTX_INPROC_SERVER, IID_IUIAutomation, reinterpret_cast<void**>(&pAuto));
if (pAuto) {
IUIAutomationElement *pElm;
POINT p;
for (int i = 0; i < 10; i++) {
for (int j = 5; j > 0; j--) {
Sleep(1000);
printf("%d ", j);
}
GetCursorPos(&p);
if (pAuto->ElementFromPoint(p, &pElm) == S_OK) {
wprintf(L"\nPOSITION x = %d, y = %d\n", p.x, p.y);
BSTR str;
pElm->get_CurrentName(&str);
wprintf(L"-Name = %s\n", str);
SysFreeString(str);
pElm->get_CurrentLocalizedControlType(&str);
wprintf(L"-Type = %s\n", str);
SysFreeString(str);
CONTROLTYPEID typeId;
pElm->get_CurrentControlType(&typeId);
switch (typeId) {
case UIA_CheckBoxControlTypeId:
IUIAutomationTogglePattern *toggle;
pElm->GetCurrentPattern(UIA_TogglePatternId, (IUnknown**)&toggle);
ToggleState state;
toggle->get_CurrentToggleState(&state);
printf("-Checkbox = %s\n", state == ToggleState::ToggleState_On ? "TRUE"
: (state == ToggleState::ToggleState_Off ? "FALSE" : "INTER"));
break;
case UIA_PaneControlTypeId:
pElm->get_CurrentClassName(&str);
if (str != nullptr && wcscmp(str, L"ListView20WndClass") == 0) {
HWND hwnd;
pElm->get_CurrentNativeWindowHandle((UIA_HWND*)&hwnd);
printf("-VB6 Listview: %p\n", hwnd);
CString txt = getListViewItemText(hwnd, 0, 0);
printf("-[0,0] = %S\n", (const wchar_t*)txt);
}
SysFreeString(str);
break;
case UIA_ListControlTypeId:
HWND hwnd;
pElm->get_CurrentNativeWindowHandle((UIA_HWND*)&hwnd);
printf("-Normal Listview: %p\n", hwnd);
CString txt = getListViewItemText(hwnd, 0, 0);
printf("-[0,0] = %S\n", (const wchar_t*)txt);
break;
}
wprintf(L"\n");
pElm->Release();
}
printf("\n");
}
pAuto->Release();
}
CoUninitialize();
}
int main()
{
UI_Spy();
cin.get();
return 0;
}
5..4..3..2..1, - , .
:
- VB6 (ListView20WndClass): (,
101 ) - MFC/Winform (SysListView32): ( )