我从CEditView基类派生了一个CMyEditView类,然后在CMainFrame中定义了一个CMyEditView的成员变量m_wndEdit,在用m_wndEdit成员变量调用Create成员函数时将用到7个参数,参照msdn上,如下:
virtual BOOL Create( LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext = NULL);请问lpszClassName和lpszWindowName参数应该如何填写,我试过都用NULL,编译后可以通过,但运行程序后出错.请高手指教一二.

解决方案 »

  1.   

    我用的可以啊。这是在我程序中的写法。
    CRect Rect;
    Rect.top = ...;
    ...
    const CRect& CellRect = Rect;
    m_wndEdit->Create( NULL, Text, WS_VISIBLE, CellRect, this, NULL, NULL);
      

  2.   

    我是根据VC知识库中的一篇关于仿VC++界面的文章来做的程序.这样做出了类似vc++编译器中的output栏.我在CMainFrame中用CEditView的成员变量m_wndEdit创建一个CEditView的写法如下:
    ////////编辑控件///////////
    if(!m_wndEdit.Create(NULL,"1212",WS_VSCROLL|WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN,CRect(0,0,0,0),&m_wndMyBar2,101))
    return -1;
    问题是当我进入程序对这个创建好的视图进行字符输入的时候抱错,内存不能为"read";
    当我将该视图设为只读后,写法如下
    if(!m_wndEdit.Create(NULL,"12121",ES_READONLY|WS_VSCROLL|WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN,CRect(0,0,0,0),&m_wndMyBar2,101))
    return -1;
    虽然这样程序运行时没问题,当然也不能对视图进行字符输入了,但是程序退出以后抱错.
    -----------------------------------------------------------------------------
    我用CEdit类,而不用CEditView类就完全没有什么问题.CEdit类的成员变量调用Create函数的写法如下:
    if(!m_wndEdit.Create(WS_VSCROLL|WS_CHILD|WS_VISIBLE|ES_AUTOVSCROLL|ES_MULTILINE|ES_WANTRETURN,CRect(0,0,0,0),&m_wndMyBar2,101))
    return -1;
    -------------------------------------------------------------------------------
    有人用相同的方法做过类似vc++界面,遇到过这种问题嘛?
      

  3.   

    View需要文档-视图结构,和一般的CWnd子类不一样。你可以用CFrameWnd::CreateView()来创建。
    CWnd* CreateView( CCreateContext* pContext, UINT nID = AFX_IDW_PANE_FIRST );Return ValuePointer to a CWnd object if successful; otherwise NULL.ParameterspContextSpecifies the type of view and document.nIDThe ID number of a view.ResCall CreateView to create a view within a frame. Use this member function to create “views” that are not CView-derived within a frame. After calling CreateView, you must manually set the view to active and set it to be visible; these tasks are not automatically performed by CreateView.创建成功后,注意:you must manually set the view to active and set it to be visible!!
      

  4.   

    DirTreeCtrl允许用户显示文件夹和文件名(可选)。该控制使用系统的图象列表
    显示每项的图标。你不必管理图标资源。项排序首先通过文件夹,然后通过文件名(如果选择了)。你可以获得每项的全路径名;你可以设置它的其始路径;你可以选择一个子路径。在对话框里使用该控制:1、在对话框资源加入树控制2、在对话框头文件定义成员变量CDirTreeCtrl m_DirTree;
    3、在InitDialog中加入下列代码:BOOL CTreeDialog::OnInitDialog() 
    {
    CDialog::OnInitDialog();
    TCHAR szWorkDir[MAX_PATH];// TODO: Add extra initialization here
    // Here we subclass our CDirTreeCtrl
    if ( !m_TreeCtrl.m_hWnd )
    {
    if ( m_TreeCtrl.SubclassDlgItem( IDC_TREE1, this ) )

    m_TreeCtrl.DisplayTree( NULL /*Display all*/, 
    TRUE /* TRUE = Display Files*/ );_getcwd( szWorkDir, 256 );
    // set the Path to the current Work-Directory
    m_TreeCtrl.SetSelPath( szWorkDir );
    }
    }return TRUE; // return TRUE unless you set the focus to a control
    // EXCEPTION: OCX Property Pages should return FALSE
    }在视图类里使用该控制:在视图的头文件中定义该控制的成员变量和标识符ID_TREECTRL;修改视图类的Create函数;修改视图类的OnSize函数。BOOL CLeftView::Create(LPCTSTR lpszClassName, 
    LPCTSTR lpszWindowName, 
    DWORD dwStyle, 
    const RECT& rect, 
    CWnd* pParentWnd, 
    UINT nID, 
    CCreateContext* pContext) 
    {
    // TODO: Add your specialized code here and/or call the base classBOOL bRet;bRet = CWnd::Create(lpszClassName, 
    lpszWindowName, 
    dwStyle, 
    rect, 
    pParentWnd, 
    nID, 
    pContext);// this part creates the TreeCtrl and use the CLeftView
    // as his parent Windowif ( m_DirTree.m_hWnd == NULL && bRet )
    {
    bRet = m_DirTree.Create(WS_CHILD | TVS_LINESATROOT | 
    TVS_HASBUTTONS | WS_VISIBLE | 
    TVS_HASLINES, 
    CRect(0, 0, 0, 0), 
    this
    ID_TREECTRL );
    if ( bRet )
    m_DirTree.DisplayTree( NULL, TRUE );
    }return bRet;
    }void CLeftView::OnSize(UINT nType, int cx, int cy) 
    {
    CView::OnSize(nType, cx, cy);// TODO: Add your message handler code here
    if ( m_DirTree.m_hWnd )
    m_DirTree.SetWindowPos( NULL, 0, 0, cx, cy, SWP_NOZORDER | SWP_NOMOVE );
    }     
     
     
      

  5.   

    我在程序中并没有使用切分窗口,是参照vc知识库中第11期的一篇文章<轻松实现类VC界面>来编制的程序.它最后生成了多个控制条窗口,但是作者是向这些控制条窗口中添加了动态生成的控件,我想将一个CEditView类的派生类CMyEditView对应到程序所生成的下面的控制条窗口中.如上面给出的仿照作者添加控件的方法,但是好象不行.
       是不是只有当用到切分窗口的时候才能创建与某个切分后的窗口相对应的视图呢?