I'm doing an application using MFC. I just made a class that is derived from CEdit so I could intercept OnChar() and do data validation. How do I substitute the edit control in my application with the derived one I made?
Do NOT use GetDlgItem
!!
GetDlgItem()
returns a CWnd
-pointer and nothing else. This means you have a sliced CMyCustomEdit
pointer. Sure, it works in all cases where your method sends a message to the underlying HWND
. But that's just pure luck! You can read more about the problem here.
The right solution is to subclass your edit control using DDX_Control.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With