C++/subclasses and hotkeys
Expert: Eddie - 6/13/2005
QuestionHi, 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
AnswerHello 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
{
public:
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