Comment exposer un fournisseur UI Automation Server-Side
Cette rubrique contient un exemple de code qui montre comment exposer un fournisseur UI Automation côté serveur pour un contrôle personnalisé.
L’Automation d’interface utilisateur Microsoft envoie le message WM _ GETOBJECT à une application fournisseur pour récupérer des informations sur un objet accessible pris en charge par le fournisseur. UI Automation envoie WM _ GETOBJECT lorsqu’un client appelle IUIAutomation :: ElementFromHandle, ElementFromPointet GetFocusedElement, et lors de la gestion des événements pour lesquels le client s’est inscrit.
Lorsqu’un fournisseur reçoit un message WM _ GETOBJECT , il doit vérifier si le paramètre lParam est égal à UiaRootObjectId. Si c’est le cas, le fournisseur doit retourner l’interface IRawElementProviderSimple de l’objet. Le fournisseur retourne l’interface en appelant la fonction UiaReturnRawElementProvider .
L’exemple suivant montre comment répondre à WM _ GETOBJECT.
// Expose the custom button's server-side provider to UI Automation.
case WM_GETOBJECT:
{
// If lParam matches UiaRootObjectId, return IRawElementProviderSimple.
if (static_cast<long>(lParam) == static_cast<long>(UiaRootObjectId))
{
// Retrieve the pointer to the custom button object from the
// window data.
CustomButton* pControl = reinterpret_cast<CustomButton*>(
GetWindowLongPtr(hwnd, GWLP_USERDATA));
// Call an application-defined method to get the
// IRawElementProviderSimple pointer.
IRawElementProviderSimple* pRootProvider =
pControl->GetUIAutomationProvider(hwnd);
// Return the IRawElementProviderSimple pointer to UI Automation.
return UiaReturnRawElementProvider(hwnd, wParam, lParam,
pRootProvider);
}
return 0;
}