You are here:

C++/subclasses and hotkeys


Hi, i would like to ask you a question about subclasses in c++
What are subclasses and do you have an idea how to implement them in MFC
and what are hotkeys and how can we use them

Thank you very much

Mohamad Tarhini  

Hello Mohamad Tarhini, thank you for the question.

A sub class is another term for a class that is derived from another class. For a visual example:

class Base
Base() {}
virtual ~Base() {}

class Derived : public Base
// ...

The class Derived is a sub class of Base. When using MFC, subclassing is essential. You derive your own classes from any MFC class in order to be able to add your own functionality to them. Otherwise, you would be stuck with that Microsoft felt should be implemented.

Hotkeys are keyboard shortcuts. Ctrl+C is the Microsoft Visual Studio hotkey for copying text in the editor. In order to implement them, in your sub class of CWnd you would override the OnKeyDown method and determine the key code of the first parameter to that function, then implement your special hotkey method:

void MyCWnd::OnKeyDown(UINT nChar, UINT, UINT)
if(nChar == 'D')
// do special hotkey code here.

That should be sufficient to get you started. As always, if you have any other questions please do not hesitate to ask me another.

I hope this information was helpful.

- Eddie


All Answers

Answers by Expert:

Ask Experts




I can answer questions about the C++ language, object oriented design and architecture. I am knowledgable in a lot of the math that goes into programming, and am certified by I also know a good deal about graphics via OpenGL, and GUIs.


I have completed numerous games and demos created with the C++ programming language. Currently employed as a software engineer in the modeling and simulation field. I have about 7 years experience.

©2017 All rights reserved.