How can I name the implementation of the base class TextBox :: OnKeyDown () in my override?

I created a subclass of the TextBox class so that I can record all keyboard events in the OnKeyDown () method (the KeyDown event will not be fired for the entire keyboard of the event, including, but not limited to, backspace and arrow keys, but OnKeyDown will be).

The problem is that it effectively disables the TextBox, since it completely bypasses the control of the internal control keyboard. The obvious solution is to call OnKeyDown in the superclass.

How do I do this in Windows Runtime? Just a call to TextBox :: OnKeyDown (...) will not work, as it will effectively lead me to my redefinition.

The OnKeyDown () method is part of the IControlOverrides interface, and it seems that I cannot get a pointer to the interface for the instance of the TextBox, but only for my derived instance of the object.

+1
source share
1 answer

Inheritance in C ++ / CX does not match inheritance in C ++. This is because the C ++ / CX ref classes are actually COM objects that implement inheritance through a variety of aggregations.

The example I was working with was

public ref class MyTextBox : public TextBox {
  MyTextBox() {};
  ~MyTextBox() {};
  virtual void OnKeyDown(KeyEventArgs^ e) override {
    TextBox::OnKeyDown(e);
  };
};

, TextBox:: OnKeyDown() MyTextBox:: OnKeyDown(). , ++/CX COM, .

Visual Studio 11 Developer Preview Solution

, OnKeyDown() IControlOverrides, MyTextBox, TextBox, . TextBox, TextBox, MyTextBox, , . COM, ++, baseclass :

  virtual void OnKeyDown(KeyEventArgs^ e) override {
    struct IControlOverrides^ ico;
    HRESULT hr = __cli_baseclass->__cli_QueryInterface(const_cast<class Platform::Guid%>(reinterpret_cast<const class Platform::Guid%>(__uuidof(struct IControlOverrides^))),reinterpret_cast<void**>(&ico));
    if (!hr) {
        hr = ico->__cli_OnKeyDown(e);
    };
  };

- Visual Studio 11

, VS 11 Beta. "__super::" - , , , :

  virtual void OnKeyDown(KeyEventArgs^ e) override {
    IControlOverrides::OnKeyDown(e);
  };

VS , OnKeyDown() (IControlOverrides).

!

+1

All Articles