Click here to Skip to main content
15,896,153 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

Although it is so strange, but I need to change my MFC SDI's frame window class from CframeWnd to CMyframeWnd (a customized CframeWnd) dynamically at RUN-TIME.

Would you help me?

Thanks,
Mochenoo
Posted

1 solution

Yes, it looks strange. Down-casting is often the sign of bad code design.

Anyway, such problems can be solved using dynamic cast, when you are not sure what is the exact runtime type of some object:
http://en.wikipedia.org/wiki/Dynamic_cast[^],
http://msdn.microsoft.com/en-us/library/cby9kycs.aspx[^].

If, by some reason, you know what is that runtime type, it means that you are using wrong compile-time type. Anyway, see also: http://www.cplusplus.com/doc/tutorial/typecasting[^].

—SA
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 5-Mar-14 8:32am    
You should not re-post, this is considered as abuse. The problem is not that I didn't get the question, the problem is that you have no clue on OOP and programming in general. No, you cannot change a type of object during runtime. The object of the class is created using a constructor and remains unchanged.

This is also a bad question. If you want to do something, you should not tell us how. You need to explain your ultimate goals, at least try to. In your case, you should first 1) fix your big misconception on programming; 2) think on what you can do with it. For this period, you need to stop doing what you are doing. And also you need to understand: you are not ready for doing anything advanced, including UI. Before you understand fundamentals really well, it would be just the waste of time.

—SA

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