Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7577733
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:15:50+00:00 2026-05-30T17:15:50+00:00

I have created a subclass of the TextBox class so that I can capture

  • 0

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

The problem with this is that it effectively disables the TextBox, as it bypasses the control’s internal keyboard handling entirely. The obvious solution is to call OnKeyDown in the superclass.

How do I do that in Windows Runtime? Just calling TextBox::OnKeyDown(…) won’t work, as it will effectively take me to my override.

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:15:52+00:00Added an answer on May 30, 2026 at 5:15 pm

    Inheritance in C++/CX is not the same as inheritance in C++. This is because C++/CX ref classes are in fact COM objects, which implements inheritance through a variety of aggregation.

    The example I was working with was

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

    which won’t work, because TextBox::OnKeyDown() will effectively call MyTextBox::OnKeyDown(). This is because of how virtual methods are implemented in C++/CX and COM, an in-depth overview can be read here.

    Visual Studio 11 Developer Preview Solution

    The short version is that the OnKeyDown() method is part of the IControlOverrides interface, implemented by both MyTextBox and TextBox, thanks to some clever compiler tricks. To get hold of the interface pointer for the TextBox implementation, we first need to ask the TextBox for it – if we ask MyTextBox we end up where we started. And because this is inheritance in COM, not C++, we do that through a pointer to the baseclass object instead of this:

      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 Beta Solution

    As with so many other things, this has been improved in the VS 11 Beta. While “__super::” still won’t work, it now works fine just to make the call explicitly to the interface in which it is defined:

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

    The Object Browser in VS will show you which interface the OnKeyDown() method is defined in (IControlOverrides).

    Problem solved!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a subclass of UITableViewController that is used as the custom class
I have created a Class (subclass of NSObject) which will hold all my SQLs/dbConnections
I have created a subclass of a generic list so that I could implement
I have created an abstract base class Animal which has public virtual abstract method
I'm working on a Java project where I have created a class that looks
I have created a subclass of QGLwidget and I was hoping that I could
I have created a custom subclass of UIView for an interface element that I
I have created a class named ListCell which is a subclass of UITableViewCell .
I have created a File class, which takes care of all operations on files,
I have created a UIView subclass in order to implement a custom drawRect method.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.