Monday, July 11, 2022

[FIXED] How to know when CWnd's Create function was called?

Issue

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?


Solution

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



Answered By - Alain
Answer Checked By - Katrina (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.