Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using derived Class from CEdit in my DIalog

Tags:

c++

mfc

cedit

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?

like image 868
Artie Avatar asked Nov 04 '22 09:11

Artie


1 Answers

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.

like image 78
l33t Avatar answered Nov 10 '22 14:11

l33t