PreCreateWindow和OnCreate的区别?GetDlgItem(IDC_EDIT)与 GetDlgItem(IDC_EDIT)->m_hWnd的区别

解决方案 »

  1.   

    GetDlgItem(IDC_EDIT)获得的是一个指向CWnd(或者其派生类)的指针,而m_hWnd成员是handler,这个不一定是指针,要依赖于Windows具体的解释……
      

  2.   

    CWnd::PreCreateWindow
    Called by the framework before the creation of the Windows window attached to this CWnd object.Never call this function directly.The default implementation of this function checks for a NULL window class name and substitutes an appropriate default. Override this member function to modify the CREATESTRUCT structure before the window is created. Each class derived from CWnd adds its own functionality to its override of PreCreateWindow. By design, these derivations of PreCreateWindow are not documented. To determine the styles appropriate to each class and the interdependencies between the styles, you can examine the MFC source code for your application’s base class. If you choose to override PreCreateWindow, you can determine whether the styles used in your application’s base class provide the functionality you need by using information gathered from the MFC source code.
    CWnd::OnCreate  
    The framework calls this member function when an application requests that the Windows window be created by calling the Create or CreateEx member function. The CWnd object receives this call after the window is created but before it becomes visible. OnCreate is called before the Create or CreateEx member function returns. 
    Override this member function to perform any needed initialization of a derived class. The CREATESTRUCT structure contains copies of the parameters used to create the window.Note   This member function is called by the framework to allow your application to handle a Windows message. The parameters passed to your function reflect the parameters received by the framework when the message was received. If you call the base-class implementation of this function, that implementation will use the parameters originally passed with the message and not the parameters you supply to the function.
      

  3.   

    OnCreate函数一般用来创建窗口;需要响应WM_CREATE消息,才能处理该函数.PreCreateWindow函数是在创建窗口之前一刻调用该函数,如:想改变窗口的外观,可以在这里添加代码.GetDlgItem函数是获取某个控件相对应的窗口指针,如,GetDlgItem(IDC_EDIT)是获取IDC_EDIT这个ID所对应的控件指针;m_hWnd是CWnd的一个成员函数,指窗口句柄.只要是CWnd及CWnd的派生类,那么就都有这个成员函数;以后在编程时,若需要用到窗口句柄,那么取他们的成员变量是比较简单的方法.
      

  4.   

    The WM_CREATE message is sent when an application requests that a window be created by calling the CreateWindowEx or CreateWindow function. (The message is sent before the function returns.) The window procedure of the new window receives this message after the window is created, but before the window becomes visible. 因此,一个是在创建之前(PreCreateWindow),一个是在创建之后(OnCreate)