Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I normally program windows using win32 API.Please how are controls subclassed in MFC?
H.Brydon 1-Feb-14 17:41pm    
Come on now, if you put this search into Google, you get a multitude of good to great hits on useful information.

You are being really lazy.

Your questions don't belong in this forum...
Sergey Alexandrovich Kryukov 1-Feb-14 18:53pm    
The question is not really as simple. I believe, from all the documentation, understanding of essence of things is not easy at all. That's why I tried to provide some basic explanation; please see Solution 1.
H.Brydon 1-Feb-14 19:16pm    
OP submitted around 10 questions on the forum all at the same time. All were pretty basic. This was perhaps the most complicated question. I would not have replied as I did if it was the only question. My comments here reflect the bigger picture.

... although I think OP is being lazy and stand by that comment.

Good answer from you (+5 for that)...
Sergey Alexandrovich Kryukov 1-Feb-14 19:37pm    
Thank you, Harvey. A am not saying that OP is a good enquirer in general. Just the opposite; I remember this member by name as the one posting many not very productive, or pointless requests.
Sergey Alexandrovich Kryukov 1-Feb-14 20:53pm    
And you were so right about OP's wrong behavior. He just readily confirmed it — please see the comments to my answer.
I wanted to blacklist certain inquirers, to avoid wasting my time on them, but with time, I start to answering them, perhaps in vain...

1 solution

The question is not so trivial as it may seem.

There are two different understanding of "sub-classing". First one is related to pure raw Windows API. This interface, from the standpoint of the application developer, is not object-oriented (some say "object based"). Even though the objects themselves are based on OOP inside, from the standpoint of the API users, they are just objects, without "classes". Everything is done inside the API implementation. If you obtain some object, say a window handle, you can use it only by passing it back to the API. The application program remains agnostic about the nature of such objects and the internal structure of the object "handled" by the handles. Using this approach, it was possible to use non-OOP languages for application development, such as C, Pascal (even non-OOP Pascal, not Borland or Free Pascal) or other languages like that. Based on this approach, API introduced so called "windows classes". From the standpoint of application developers, they are not real classes. Rather, they play the role of meta-objects:[^].

You can read about those "Windows Classes" here:[^].

On top of that, you can use object-oriented languages to derive classes from other classes. In this sense, you are using the classes how they are understood in the OOP language.

As to MFC, it uses both approaches. The trend is: the library itself uses both approaches, while an application programmer tends to use C++ OOP. This way, most or all user classes do not create new windows classes, use the same defined in Windows and MFC, changing its behavior based on C++ OOP. This approach provides enough expressing capabilities, just because, in particular, the user can override methods handling any events, which leverage all the Windows power.

In general, to use MFC effectively, the user should have in-depth knowledge of "classical" OOP: virtual methods, overriding, late binding and polymorphism.

My final note: in my opinion, MFC is too old and morally obsolete, the level of maintainability of code is lower then in later technologies. However, comparison of the quality of API and techniques is complicated and never straightforward.

Share this answer
Gbenbam 1-Feb-14 20:28pm    
I am sorry , your answer does not answer my question.By subclassing I mean the process of instructing wimdows to stop sending messages meant for a control to its parent window but rather to a new window procedure called subclass procedure.
Sergey Alexandrovich Kryukov 1-Feb-14 20:51pm    
No, what you say is not sub-classing, but it is related. And no, your question was not about "instructing windows to stop sending messages", it was about sub-classing, that's why I tried to explain you what I tried. Do you think you can trick anyone into thinking you were right? Who will deal with you and waste one's time answering your questions if you cannot be a fair player?

And you can easy find out how to override a windows proc (message-handling proc). Please do you by yourself. Everyone is supposed to be able to find such basic facts in documentation.

Gbenbam 1-Feb-14 21:43pm    
To SA :
I appreciate ur responses to my questns.In fact I really value you.May be my understang of sunclassing controls is different.I have used SetWindowLong functn to a achieve d above in the past. What I wish to know is how ds is done in MFC and that you did not address.I just wanted you to know that hoping you will offer another solution that ends my quest.

Believe me you have been a huge resource to me.I really value you.I really do. Its just that your response doesn't end my quest.

You know I recognise that you are more knowledge able and experiencef programmer than I am.I am not trying to trick anybody.I just want to explain what I meant with the hope that having now understood what I mean you can now give a pertinent answer.

Maybe my question shld be , how do I perform the equivalent of my own understanding of subclassing controls in MFC.
Sergey Alexandrovich Kryukov 1-Feb-14 21:56pm    
No problem. Basically, without creation of a new windows class (see my answer and the reference I provided), you either handle a separate message, or, ultimately, override the whole function WindowProc. This is well explained, for example, here:

Please see:

Gbenbam 1-Feb-14 22:34pm    
Thanks that is exactly what I need.It turns out the process is exactly what I used to do in native coding.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900