2个小问题!

lezi1022 2005-05-28 03:09:42
PreCreateWindow和OnCreate的区别?

GetDlgItem(IDC_EDIT)与 GetDlgItem(IDC_EDIT)->m_hWnd的区别
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
qrlvls 2005-05-28
  • 打赏
  • 举报
回复
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)
yjjbmk 2005-05-28
  • 打赏
  • 举报
回复
OnCreate函数一般用来创建窗口;需要响应WM_CREATE消息,才能处理该函数.

PreCreateWindow函数是在创建窗口之前一刻调用该函数,如:想改变窗口的外观,可以在这里添加代码.

GetDlgItem函数是获取某个控件相对应的窗口指针,如,GetDlgItem(IDC_EDIT)是获取IDC_EDIT这个ID所对应的控件指针;

m_hWnd是CWnd的一个成员函数,指窗口句柄.只要是CWnd及CWnd的派生类,那么就都有这个成员函数;以后在编程时,若需要用到窗口句柄,那么取他们的成员变量是比较简单的方法.
Hendy_So 2005-05-28
  • 打赏
  • 举报
回复
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.
newbiestar 2005-05-28
  • 打赏
  • 举报
回复
GetDlgItem(IDC_EDIT)获得的是一个指向CWnd(或者其派生类)的指针,而m_hWnd成员是handler,这个不一定是指针,要依赖于Windows具体的解释……

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧