This is a Console code and hwnd is probably NULL
Call
HWND hwnd = GetConsoleWindow();
instead to get the Console window
or
HWND hwnd = GetForegroundWindow();
for the foreground window
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello guys,
I'm new developer windows.
I want to get ROLE_SYSTEM_TEXT
of application in window but I got trouble with function AccessibleObjectFromWindow
I read the docs and try to use this fuction but it not work
Please help me fix it.
This is my code :
#include <iostream>
#include <Windows.h>
#include <OleAcc.h>
#include <unistd.h>
void get_role_system_text(){
HWND hwnd = GetActiveWindow();
IAccessible* pAccessible = nullptr;
VARIANT varChild;
varChild.vt = VT_EMPTY;
HRESULT hr = AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, IID_IAccessible, (void**)&pAccessible);
std::cout << "AccessibleObjectFromWindow pAccessible : " << pAccessible << std::endl;
std::cout << "AccessibleObjectFromWindow SUCCEEDED(hr) : " << SUCCEEDED(hr) << std::endl;
if (SUCCEEDED(hr)) {
VARIANT varRole;
hr = pAccessible->get_accRole(varChild, &varRole);
if (SUCCEEDED(hr) && varRole.vt == VT_I4) {
std::cout << "Role value: " << varRole.lVal << std::endl;
}
pAccessible->Release();
}
}
int main() {
// Initialize COM
CoInitialize(nullptr);
while(1){
Sleep(1000);
get_role_system_text();
}
// Uninitialize COM
CoUninitialize();
return 0;
}
Comand build: g++ role.cpp -loleacc -lole32
This is a Console code and hwnd is probably NULL
Call
HWND hwnd = GetConsoleWindow();
instead to get the Console window
or
HWND hwnd = GetForegroundWindow();
for the foreground window