1. Add controls in the dialog box template and dynamically create controls for different presubclasswindow and oncreate calls
Adding a control in the dialog box template does not call the oncreate function of the control,ProgramThe generate dialog box is created by calling createdialog or dialogbox of the Windows API. In this way, all the controls are standard Windows controls at the time of creation of the dialog box, at that time, the message wm_create will only trigger the default window callback function, instead of calling the oncreate of the subclass. Then how can we replace this control with a custom control? In fact, As long as setwindowlong changes the window callback function, the function for doing this operation is subclasswindow, before the dialog box Initialization is completeCodeAutomatic call, and this function will call presubclasswindow to let the writer complete some initialization actions to replace the old wm_create message. If you manually call the create function, the callback function in this window will be replaced by the wh_cbt hook of MFC at the beginning of creation with the callback function of the subclass, in this way, the wm_create message can trigger oncreate of the subclass and complete initialization.
Both methods call the control's presubclasswindow function, but they have different meanings. For the template, MFC calls the create function of the parent class, creates a window handle, and attach the window handle to the subclass. Therefore, only presubclasswnd () is called (), instead of responding to the oncreate function of the subclass. For dynamic creation, presubclasswnd () is also called, but no create is yet. presubclasswindow should be called before the control window is created, and the window handle will not be created until after the create operation, if a window handle is used in the function, an exception is thrown. Note that the child window can be created only after the parent window is created.
2. when creating a build using the create method, you cannot nest create or createex in presubclasswindow. The reason is that when MFC calls create or ex, the build is created. After the creation, the _ afxcbtfilterhook function will handle the aftermath. For example, the m_pwndinit in the thread state will be cleared before the function is returned. If create or ex is nested in presubclasswindow, before afxcbtfilterhook is returned, afxcbtfilterhook is called once again, and the m_pwndinit value remains unchanged, resulting in two attach exceptions. In this case, if other nested controls in the control need to call create initialization, they should be placed in oncreate.