比如说 我在菜单栏建立个二叉树选项想和对话框IDD_DIALOG1 相连,如何设置啊? 请详细说明(‘二叉树’选项属性您可以自己设置)

解决方案 »

  1.   

    什么是“相连”弹出 IDD_DIALOG1 对应的对话框?
      

  2.   

    二叉树选项属性中设置好ID值,如果不是弹出式的菜单去除pop-up选项,填入ID值,比如ID_TREE,右键点击菜单中的二叉树选项,选择进入向导对话框,添加ID_TREE的Command消息响应函数onTree(),加入你要关联的对话框资源,比如IDD_DIALOG1,添加相应的基于对话框的类,比如CTreeDlg类,在OnTree()函数中加入如下代码:
    CTreeDlg treedlg;
    treedlg.DoModal();
    最后别忘了加入头文件。
      

  3.   

    是这样吗?但是出错了啊!
    // MainFrm.cpp : implementation of the CMainFrame class
    //#include "stdafx.h"
    #include "数据结构演示系统.h"#include "MainFrm.h"
    #include "Splash.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_COMMAND(ID_TREE, OnTree)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()static UINT indicators[] =
    {
    ID_SEPARATOR,           // status line indicator
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
    };/////////////////////////////////////////////////////////////////////////////
    // CMainFrame construction/destructionCMainFrame::CMainFrame()
    {
    // TODO: add member initialization code here

    }CMainFrame::~CMainFrame()
    {
    }int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    } if (!m_wndStatusBar.Create(this) ||
    !m_wndStatusBar.SetIndicators(indicators,
      sizeof(indicators)/sizeof(UINT)))
    {
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
    } // TODO: Delete these three lines if you don't want the toolbar to
    //  be dockable
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar); // CG: The following line was added by the Splash Screen component.
    CSplashWnd::ShowSplashScreen(this);
    return 0;
    }BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs return TRUE;
    }/////////////////////////////////////////////////////////////////////////////
    // CMainFrame diagnostics#ifdef _DEBUG
    void CMainFrame::AssertValid() const
    {
    CFrameWnd::AssertValid();
    }void CMainFrame::Dump(CDumpContext& dc) const
    {
    CFrameWnd::Dump(dc);
    }#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
    // CMainFrame message handlers
    void CMainFrame::OnTree() 
    {IDD_DIALOG1 Cdialog; 
    Cdialog.DoModal();  // TODO: Add your command handler code here

    }错误:
    --------------------Configuration: 数据结构演示系统 - Win32 Debug--------------------
    Compiling...
    MainFrm.cpp
    F:\数据结构演示系统\MainFrm.cpp(112) : error C2146: syntax error : missing ';' before identifier 'Cdialog'
    F:\数据结构演示系统\MainFrm.cpp(112) : error C2275: 'Cdialog' : illegal use of this type as an expression
            f:\数据结构演示系统\dialog.h(13) : see declaration of 'Cdialog'
    F:\数据结构演示系统\MainFrm.cpp(113) : error C2143: syntax error : missing ';' before '.'
    F:\数据结构演示系统\MainFrm.cpp(113) : error C2143: syntax error : missing ';' before '.'
    执行 cl.exe 时出错.数据结构演示系统.exe - 1 error(s), 0 warning(s)
      

  4.   

    第一:工程底下的文件要用西文命名;
    第二:为对话框资源IDD_DIALOG1创建一个基于对话框的类,不是“IDD_DIALOG1 Cdialog;”这么做的。如果你是从VB或其他语言刚转行过来,那么这些问题就暂且不跟你追究了。
    你先看十分钟的关于为对话框资源创建对话框派生类的VC教程再来答复这个帖子吧。
      

  5.   


    // MainFrm.cpp : implementation of the CMainFrame class
    //#include "stdafx.h"
    #include "tt.h"
    #include "TreeDlg.h"#include "MainFrm.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // CMainFrameIMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ON_WM_CREATE()
    ON_COMMAND(ID_TREE, OnTree)
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()static UINT indicators[] =
    {
    ID_SEPARATOR,           // status line indicator
    ID_INDICATOR_CAPS,
    ID_INDICATOR_NUM,
    ID_INDICATOR_SCRL,
    };/////////////////////////////////////////////////////////////////////////////
    // CMainFrame construction/destructionCMainFrame::CMainFrame()
    {
    // TODO: add member initialization code here

    }CMainFrame::~CMainFrame()
    {
    }int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
    {
    if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
    return -1;

    if (!m_wndToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_TOP
    | CBRS_GRIPPER | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC) ||
    !m_wndToolBar.LoadToolBar(IDR_MAINFRAME))
    {
    TRACE0("Failed to create toolbar\n");
    return -1;      // fail to create
    } if (!m_wndStatusBar.Create(this) ||
    !m_wndStatusBar.SetIndicators(indicators,
      sizeof(indicators)/sizeof(UINT)))
    {
    TRACE0("Failed to create status bar\n");
    return -1;      // fail to create
    } // TODO: Delete these three lines if you don't want the toolbar to
    //  be dockable
    m_wndToolBar.EnableDocking(CBRS_ALIGN_ANY);
    EnableDocking(CBRS_ALIGN_ANY);
    DockControlBar(&m_wndToolBar); return 0;
    }BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
    {
    if( !CFrameWnd::PreCreateWindow(cs) )
    return FALSE;
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs return TRUE;
    }/////////////////////////////////////////////////////////////////////////////
    // CMainFrame diagnostics#ifdef _DEBUG
    void CMainFrame::AssertValid() const
    {
    CFrameWnd::AssertValid();
    }void CMainFrame::Dump(CDumpContext& dc) const
    {
    CFrameWnd::Dump(dc);
    }#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////
    // CMainFrame message handlers
    void CMainFrame::OnTree() 
    {
    // TODO: Add your command handler code here
    CTreeDlg treedlg;
    treedlg.DoModal();

    }
    红的是你要注意的地方,CTreeDlg是新建的基于CDialog的一个类,与IDD_DIALOG1关联,具体怎么关联的在class wizard里新建这个类的时候可以操作,建议你还是看看vc教程吧,这个其实不难的。
      

  6.   

    晕,字体怎么不显红,简单说一下,你要改的部分就是在OnTree()里面加两行代码,然后在文件开始的地方加入头文件“TreeDlg.h”,其他工作在类向导里都可以完成。