create()

OnCreate是一個消息響應函數,是響應WM_CREATE消息的一個函數,而WM_CREATE消息是由Create函數調用的。  在view類中,Create 是虛函數由框架調用,是用來“生成一個窗口的子窗口”。 而OnCreate 函數是用來“表示一個窗口正在生成”。  一個窗口創建(Create)之後,會向操作系統發送WM_CREATE消息,OnCreate()函數主要是用來響應此消息的。因爲在MFC裏面用一種消息映射的機制來響應消息,也就是可以用函數來響應相應的消息。就拿CMainFrame類來說,當窗口創建後會產生WM_CREATE消息,我們可以在OnCreate函數裏實現我們要在窗口裏面增加的東西,例如按扭,狀態欄,工具欄等。這些子窗口一般是定義成類中的一個成員變量,因爲要保證生命週期。一般以m_開頭來表示成員(member)。  OnCreate()不產生窗口,只是在窗口顯示前設置窗口的屬性如風格、位置等,Create()負責註冊併產生窗口  Create()不是對應於消息WM_CREATE的,OnCreate()纔是。Create()只用於產生窗口,像動態創建控件中的Create()一樣。

LPCREATESTRUCT是一個指向結構CREATESTRUCT的指針  The CREATESTRUCT structure defines the initialization parameters passed to the window procedure of an   application.


typedef struct tagCREATESTRUCT { // cs

  LPVOID lpCreateParams;   

HINSTANCE hInstance;  

HMENU hMenu;   

HWND hwndParent;   

int cy;   

int cx;  

 int y;   

int x;   

LONG style;   

LPCTSTR lpszName;  

 LPCTSTR lpszClass;

DWORD dwExStyle;

  } CREATESTRUCT;

參數

 hInstance   Handle to the module that owns the new window.  

 hMenu   Handle to the menu to be used by the new window.  

 hwndParent   Handle to the parent window, if the window is a child window. If the window is owned, this member identifies the owner window. If the window is not a child or owned window, this member is NULL.  

 cy   Specifies the height of the new window, in pixels.  

 cx   Specifies the width of the new window, in pixels.  

 y   Specifies the y-coordinate of the upper left corner of the new window. If the new window is a child window, coordinates are relative to the parent window. Otherwise, the coordinates are relative to the screen origin.  

 x   Specifies the x-coordinate of the upper left corner of the new window. If the new window is a child window, coordinates are relative to the parent window. Otherwise, the coordinates are relative to the screen origin. 

 style   Specifies the style for the new window.

  lpszName   Pointer to a null-terminated string that specifies the name of the new window.   

lpszClass   Pointer to a null-terminated string that specifies the class name of the new window.  

 dwExStyle   Specifies the extended style for the new window.

註釋

  Windows NT: You should access the data represented by the lpCreateParams member using a pointer that   has been declared using the UNALIGNED type, because the pointer may not be DWORD aligned.


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章