How to know when CWnd's Create function was ca

2019-07-27 11:30发布

问题:

I've wrote a class wrapping a grid controls. I want to init the custom grid class when it is created by calling Create function.

Is there a way that i can catch the event?

回答1:

Yes, if CWnd:Create or Cwd:CreateEx is used, it is possible to catch the Win32 event with:

afx_msg int OnCreate(
   LPCREATESTRUCT lpCreateStruct 
);

See CWnd::OnCreate

With the corresponding mapping:

BEGIN_MESSAGE_MAP(MyGrid, CWnd)
ON_WM_CREATE()
END_MESSAGE_MAP()

Attention: If your control is directly added on a dialog template by the designer (ie, using DDX), the function CWnd:.OnCreate() is not called.

In all cases, the following function is called at creation, after the Hwnd (handle of window) is initialized:

virtual void PreSubclassWindow( );

See PreSubclassWindow

Best regards, Alain



标签: mfc message