菜单连接问题 比如说 我在菜单栏建立个二叉树选项想和对话框IDD_DIALOG1 相连,如何设置啊? 请详细说明(‘二叉树’选项属性您可以自己设置) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 什么是“相连”弹出 IDD_DIALOG1 对应的对话框? 二叉树选项属性中设置好ID值,如果不是弹出式的菜单去除pop-up选项,填入ID值,比如ID_TREE,右键点击菜单中的二叉树选项,选择进入向导对话框,添加ID_TREE的Command消息响应函数onTree(),加入你要关联的对话框资源,比如IDD_DIALOG1,添加相应的基于对话框的类,比如CTreeDlg类,在OnTree()函数中加入如下代码: CTreeDlg treedlg; treedlg.DoModal();最后别忘了加入头文件。 是这样吗?但是出错了啊!// 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_FILEstatic 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_MAPEND_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 _DEBUGvoid CMainFrame::AssertValid() const{ CFrameWnd::AssertValid();}void CMainFrame::Dump(CDumpContext& dc) const{ CFrameWnd::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CMainFrame message handlersvoid CMainFrame::OnTree() {IDD_DIALOG1 Cdialog; Cdialog.DoModal(); // TODO: Add your command handler code here }错误:--------------------Configuration: 数据结构演示系统 - Win32 Debug--------------------Compiling...MainFrm.cppF:\数据结构演示系统\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) 第一:工程底下的文件要用西文命名;第二:为对话框资源IDD_DIALOG1创建一个基于对话框的类,不是“IDD_DIALOG1 Cdialog;”这么做的。如果你是从VB或其他语言刚转行过来,那么这些问题就暂且不跟你追究了。你先看十分钟的关于为对话框资源创建对话框派生类的VC教程再来答复这个帖子吧。 // 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_FILEstatic 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_MAPEND_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 _DEBUGvoid CMainFrame::AssertValid() const{ CFrameWnd::AssertValid();}void CMainFrame::Dump(CDumpContext& dc) const{ CFrameWnd::Dump(dc);}#endif //_DEBUG/////////////////////////////////////////////////////////////////////////////// CMainFrame message handlersvoid CMainFrame::OnTree() { // TODO: Add your command handler code here CTreeDlg treedlg; treedlg.DoModal();}红的是你要注意的地方,CTreeDlg是新建的基于CDialog的一个类,与IDD_DIALOG1关联,具体怎么关联的在class wizard里新建这个类的时候可以操作,建议你还是看看vc教程吧,这个其实不难的。 晕,字体怎么不显红,简单说一下,你要改的部分就是在OnTree()里面加两行代码,然后在文件开始的地方加入头文件“TreeDlg.h”,其他工作在类向导里都可以完成。 关于类的一个小问题 改变图像亮度图像颜色部分出现偏差问题 MSDN为什么不能用呢?请解答 release版的程序在其它没装vc的机器中运行时,调用Access数据库报“应用程序内部错误”,请问应该怎样处理?我用的是DAO。 问一个并口的问题(急)小妹谢谢!!!! 如何利用CrectTracker类实现多个元件的拖动 控件拦哪去了!(急) 关于全局函数的问提. 用CSplitterWnd生成的动态分隔窗口,如何把分隔栏变细或变没? 初学者的疑惑,小问题,59分求解 unhandled exception 0xc0000005 错误 打印控制,要控制行数和编码
CTreeDlg treedlg;
treedlg.DoModal();
最后别忘了加入头文件。
// 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)
第二:为对话框资源IDD_DIALOG1创建一个基于对话框的类,不是“IDD_DIALOG1 Cdialog;”这么做的。如果你是从VB或其他语言刚转行过来,那么这些问题就暂且不跟你追究了。
你先看十分钟的关于为对话框资源创建对话框派生类的VC教程再来答复这个帖子吧。
// 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教程吧,这个其实不难的。