龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 软件开发 > VC开发 >

VC++深入详解:MFC框架窗口(2)[图]

时间:2009-12-30 15:42来源:未知 作者:admin 点击:
分享到:
2.创建窗口 按照Win32程序编写步骤,设计窗口类并注册窗口类之后,应该是创建窗口了。在MFC程序中,窗口的创建功能是由CWnd类的CreateEx函数实现的,该函数的声明位于AFXWin.h文件中,

  2.创建窗口

  按照Win32程序编写步骤,设计窗口类并注册窗口类之后,应该是创建窗口了。在MFC程序中,窗口的创建功能是由CWnd类的CreateEx函数实现的,该函数的声明位于AFXWin.h文件中,具体代码如下所示。

  BOOL CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
    LPCTSTR lpszWindowName, DWORD dwStyle,
    int x, int y, int nWidth, int nHeight,
    HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam = NULL);

  其实现代码位于WINCORE.CPP文件中,部分代码如例3-14所示。

  例3-14

  BOOL CWnd::CreateEx(DWORD dwExStyle, LPCTSTR lpszClassName,
    LPCTSTR lpszWindowName, DWORD dwStyle,
    int x, int y, int nWidth, int nHeight,
    HWND hWndParent, HMENU nIDorHMenu, LPVOID lpParam)
  {
    // allow modification of several common create parameters
    CREATESTRUCT cs;
    cs.dwExStyle = dwExStyle;
    cs.lpszClass = lpszClassName;
    cs.lpszName = lpszWindowName;
    cs.style = dwStyle;
  ……
    if (!PreCreateWindow(cs))
    {
      PostNcDestroy();
      return FALSE;
    }
   
    AfxHookWindowCreate(this);
    HWND hWnd = ::CreateWindowEx(cs.dwExStyle, cs.lpszClass,
      cs.lpszName, cs.style, cs.x, cs.y, cs.cx, cs.cy,
      cs.hwndParent, cs.hMenu, cs.hInstance, cs.lpCreateParams);
  ……
  }

  CFrameWnd类的Create函数的声明也位于AFXWin.h文件中,具体代码如下所示。
  BOOL Create(LPCTSTR lpszClassName,
        LPCTSTR lpszWindowName,
        DWORD dwStyle = WS_OVERLAPPEDWINDOW,

const RECT& rect = rectDefault,
        CWnd* pParentWnd = NULL,    // != NULL for popups
        LPCTSTR lpszMenuName = NULL,
        DWORD dwExStyle = 0,
        CCreateContext* pContext = NULL);

  其定义位于在WINFRM.CPP文件中,部分代码如例3-15所示。

收藏文章
表情删除后不可恢复,是否删除
取消
确定
图片正在上传,请稍后...
评论内容为空!
还没有评论,快来抢沙发吧!
按钮 内容不能为空!
立刻说两句吧! 查看0条评论
精彩图集

赞助商链接