Where can I put the MFC Control initialization code

I am writing an MFC CEdit control and I need to add the initialization code after populating the m_hwnd control.

What function can I override or what message can I process for this?

I tried with OnCreate but it seems to work only for dialogs

EDIT: The thing I initialize is the cue edit banner

thanks

+6
source share
3 answers

Following the prompt of Mark Ransom, I finally found a better function to implement my initialization. Although overloading CWnd :: SubclassWindow is a good idea, this function is not virtual and will require a call from a subclass pointer. Calling SubclassWindow from CWnd * will not work.

I found the function CWnd :: PreSubclassWindow . It is virtual and is called immediately before SubclassWindow. Since m_hwnd is really there, this is a good place to write the code I need. In addition, this function is virtual and is automatically called a wireframe, so I don’t have to worry about having a good pointer type

+7
source

OnCreate does not work if the control is in the dialog box, because the control is created before it is subclassed into your window class - this happens in the DoDataExchange dialog box.

You can override CWnd :: SubclassWindow and call the base method before your own code.

+5
source

Depending on what you initialize, you can override OnPaint() or add the initialization code to OnInitDialog() in the Dialog class that contains the control.

0
source

Source: https://habr.com/ru/post/920428/


All Articles