1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| char currentCursorName[256];
void CALLBACK WinEventProc(HWINEVENTHOOK hEvent, DWORD event, HWND hwndMsg, LONG idObject, LONG idChild, DWORD idThread, DWORD dwmsEventTime)
{
// If idObject is not OBJID_CURSOR we return
if(idObject != OBJID_CURSOR)
return;
char bufferName[256];
IAccessible *pacc=NULL;
VARIANT varChild;
VariantInit(&varChild);
// Get a pointer to IAccessible and a child ID for the event
HRESULT hr = AccessibleObjectFromEvent(hwndMsg, idObject, idChild, &pacc, &varChild);
if(!SUCCEEDED(hr))
{
VariantClear(&varChild);
return;
}
VARIANT varRetVal;
// Get the role and verify that the event corresponds to the cursor
hr = pacc->get_accRole(varChild, &varRetVal);
if (hr != S_OK || varRetVal.vt != VT_I4 || varRetVal.lVal != ROLE_SYSTEM_CURSOR)
{
pacc->Release();
return;
}
// Get the name of the cursor
BSTR bstrName;
hr = pacc->get_accName(varChild, &bstrName);
if (hr == S_OK && bstrName)
{
WideCharToMultiByte(CP_ACP, 0, bstrName, -1, bufferName, sizeof(bufferName), NULL, NULL);
SysFreeString(bstrName);
}
else
lstrcpyn(bufferName, "unknown name", sizeof(bufferName));
// Verify if the name is the requested one
// Note that this comparison will not work on localized builds
if(!strstr(bufferName, currentCursorName))
//TODO : cursor has changed => here do what you have to !
strncpy_s(currentCursorName, 256, bufferName, 256);
pacc->Release();
return;
} |
Partager