Aracılığıyla paylaş


Nesnelere Yönelik Mevcut İşaretçileri Yeniden Kullanma

Bu senaryoda, sunucu her seferinde aynı IAccessible arabirim işaretçisini kullanarak bir OBJID_CLIENT isteğine yanıt verir.

Aşağıdaki örnek kodda, denetim nesnesi ek pencere verilerinden alınır ve varsa erişilebilirlik sunucusu nesnesini (uygulama tanımlı AccServer sınıfı) almak için denetimin bir yöntemi çağrılır. Erişilebilirlik sunucusu henüz yoksa oluşturulur.

Erişilebilirlik sunucusu nesnesi oluşturulduğunda, referans sayısı 1'dir. LresultFromObject başvuru sayısını defalarca artırır, ancak istemci nesne üzerindeki işlemlerini tamamladığında bu başvurular serbest bırakılır. Denetim penceresi yok edildiğinde sunucu referansını bırakır.

case WM_GETOBJECT:
    {
        // Return the IAccessible object. 
        if ((DWORD)lParam == (DWORD)OBJID_CLIENT)
        {
            // Get the control.  
            CustomListControl* pCustomList = (CustomListControl*)(LONG_PTR)GetWindowLongPtr(hwnd, 0);
            // Create the accessible object. 
            AccServer* pAccServer = pCustomList->GetAccServer();
            if (pAccServer == NULL)
            {
                pAccServer = new AccServer(hwnd, pCustomList);
                pCustomList->SetAccServer(pAccServer);
            }
            if (pAccServer != NULL)  // NULL if out of memory. 
            {
                LRESULT Lresult = LresultFromObject(IID_IAccessible, wParam, pAccServer);
                return Lresult;
            }
            else return 0;
        }
        break;
    }

    
case WM_DESTROY:
    {
    CustomListControl* pCustomList = (CustomListControl*)(LONG_PTR)GetWindowLongPtr(hwnd, 0);
    AccServer* pAccServer = pCustomList->GetAccServer();
    if (pAccServer!= NULL)
    {
        // Notify the accessibility object that the control no longer exists. 
        pAccServer->SetControlIsAlive(false);
        // Release the reference created in WM_GETOBJECT. 
        pAccServer->Release(); 
    }   
    // Destroy the control. 
    delete pCustomList;
     break;
    }