When Will oncreate precreatewindow presubclasswindow be called?

Source: Internet
Author: User

Oncreateprecreatewindowpresubclasswindow
Author: chenyongsuda and C/C ++ 2010/08/09

Introduction: This is the details page of oncreateprecreatewindowpresubclasswindow. It introduces the knowledge, skills, and experience related to C/C ++, C ++ oncreate precreatewindow presubclasswindow, and some C/C ++ source code.

Oncreate precreatewindow presubclasswindow

Precreatewindow and presubclasswindow are virtual functions, while oncreate is a message response function.

Compare the status of the three functions in the two creation modes in the dialog box:

  Oncreate Precreatewindow Presubclasswindow
Cdialog: Create Yes No Yes
Cdialog: domodal Yes No Yes

Compare the status of the three functions in the two creation modes of the control:

  Oncreate Precreatewindow Presubclasswindow
Use the create function of the cwnd derived class Yes Yes Yes
Create a template in the dialog box No No Yes

 

We can see that presubclasswindow is the most reliable function and can be called in any situation. Presubclasswindow is the first function called by a cwnd class object after attach to a Windows window handle (also called subclass, or subclass. This is a virtual function. Generally, child classes derived from the control class of MFC reload this function and call the modifystyle function internally to modify the window style. In particular, if you use a dialog box template to create a form, the control on the dialog box is generally created in the form of Dynamic Data Exchange (cdialog: oninitdialog will call the dodataexchange function, call ddx_control to subclass control). In this case, presubclasswindow is the best place to modify the control style during runtime.

Precreatewindow is the function called before the window is created. By modifying the parameter of the type passed to this function as createstruct, the derived class can modify the window style. However, the two tables above indicate that there is only one chance for this function to be called: When you create a form using the create function of the cwnd derived class. In particular, the precreatewindow of the dialog box class will never be called.

As a virtual function, classwizard adds code to the base class function call when adding this function. Generally, this code only calls the cwnd: precreatewindow function, and this function is only used to ensure that the class name of the window is not null. Therefore, the call to the base class function can be omitted as appropriate.

Oncreate is a function that responds to the wm_create message after the window is created. Unfortunately, the oncreate functions of the controls created through the dialog box template are not called at all.

Summary: The dialog box class generally adds the oncreate message processing function to do some work after the window is created, such as creating timer or something. The control class generally reloads the presubclasswindow function to modify the control style, for example, set it to ownerdraw.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.