Overridden functions for IAccessible interface do not work in cwnd-drived class
Asked Answered
N

2

7

I have a CWnd-derived class named button, and want to use CWnd accessibility functions, I override this function in my class:

virtual HRESULT get_accName(VARIANT varChild, BSTR *pszName);
virtual HRESULT get_accChildCount(long *pcountChildren);
virtual HRESULT get_accDefaultAction(VARIANT varChild, BSTR *pszDefaultAction);
virtual HRESULT get_accDescription(VARIANT varChild, BSTR *pszDescription);
virtual HRESULT get_accKeyboardShortcut(VARIANT varChild, BSTR *pszKeyboardShortcut);
virtual HRESULT get_accParent(IDispatch **ppdispParent);
virtual HRESULT get_accRole(VARIANT varChild, VARIANT *pvarRole);
virtual HRESULT get_accState(VARIANT varChild, VARIANT *pvarState);
virtual HRESULT get_accValue(VARIANT varChild, BSTR *pszValue);

When I run the program, and set break a point in implementation of any of these functions, program does not enter these functions, and instead uses parent function, can any help me?

implementation of get_accName:

HRESULT Button::get_accName(VARIANT varChild, BSTR *pszName)
{
   //*pszName = SysAllocString(lpstrTitle);
   return S_OK;
}

I call EnableActiveAccessibility() in constructor of this class, but does not work yet.

Necessaries answered 10/5, 2012 at 6:17 Comment(2)
When I override the get_accName method in IAccessible Interface for a combo Box in a dialog based MFC application, the method gets executed. But when it is overridden for other standard controls like Button, Edit, Checkbox the execution does not get there.Aleppo
Don't you pretend to use get_accValue?Slaw
T
0

Have you tried something like:

class CWnd {
  virtual HRESULT  get_accChildCount(long *pcountChildren);
};

class Button : public CWnd {

  virtual HRESULT  get_accChildCount(long *pcountChildren) {

    HRESULT childCount = CWnd:get_accChildCount(long *pcountChildren);

    //you can use the value from the ancestor class if it is of any use 
    //to you or add your own code 
    childCount = 1234;

    return childCount;
  } 
};
Thoreau answered 15/5, 2012 at 8:28 Comment(1)
When a "Button" class is inherited from "CButton", the "get_accName" not execute.Aleppo
C
0

You may be invoking these overriden methods incorrectly. Try renamed overriding. It can make things clearer and point out if anything is wrong. See below for an example implementation.

ref class Base
{
public:    
    virtual void Boo()
    {
        Show("Base::Boo");
    }    
};

ref class Derived : Base
{
public:    
    //Overrides Base::Boo
    virtual void Woo() = Base::Boo
    {
        Show("Derived::Woo");
    }
};

Invoke it like:

void _tmain()
{ 
    Base* r = new Derived();

    Derived* d = dynamic_cast<Derived*>(r);
    d->Woo();
}

From CodeProjects

Carburize answered 21/5, 2012 at 15:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.