我有一个名为CWnd
的派生类,并希望使用CWnd
辅助功能,我在我的班级中覆盖了这个函数:
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);
当我运行程序,并在执行任何这些函数时设置中断点,程序不会进入这些函数,而是使用父函数,可以帮助我吗?
实现get_accName:
HRESULT Button::get_accName(VARIANT varChild, BSTR *pszName)
{
//*pszName = SysAllocString(lpstrTitle);
return S_OK;
}
我在这个类的构造函数中调用了EnableActiveAccessibility()
,但是还没有工作。
答案 0 :(得分:0)
你有没有试过像:
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;
}
};
答案 1 :(得分:0)
您可能错误地调用了这些重写方法。尝试重命名覆盖。它可以使事情更清晰,并指出是否有任何错误。请参阅下面的示例实现。
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");
}
};
像以下一样调用它:
void _tmain()
{
Base* r = new Derived();
Derived* d = dynamic_cast<Derived*>(r);
d->Woo();
}