在同一个基于MFC对话的应用程序中与不同对话框进行通信 [英] Communication with different dialogue box in same MFC dialogue based application

查看:61
本文介绍了在同一个基于MFC对话的应用程序中与不同对话框进行通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在MFC中设计了一个基于对话的应用程序,我想在主对话框打开之前添加两个对话框。我试图通过OnInitDialogue()函数调用其中一个新对话框,我在旧版中使用DoModal()方法应用程序,但我的条件是旧的主对话应该作为一些可变条件打开,而不是按下退出按钮或关闭新对话打开!

和另一个查询是:我在旧对话框上使用了Back按钮,它应显示之前的对话框!怎么做?

我从我的应用程序中复制一些代码:

I already designed one dialogue based application in MFC and I want to add two dialogues before the main dialogue open.I tried to call one of the new dialogue through OnInitDialogue() function and I do that using DoModal() method in old application,but my condition is that old main dialogue should be opened as some variable conditions and not opened with pressing escape button or closing new dialogue!
and another query is: I used Back button on old dialogue which should display previous dialogue! How to do that?
I copy some code from my application below:

CDialog::OnInitDialog();
	

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TODO: Add extra initialization here
	UpdateData(TRUE);
	CMainApp dlg;
	dlg.DoModal();



和下面的代码解释了我如何调用旧对话后退按钮的点击事件的新对话:


and code below explains how I called new dialogue on clicked event of Back button of old dialogue:

void CCheckout_Code::OnBnClickedBack()
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CPrevApp startDlg;
		startDlg.DoModal();
}

推荐答案

由于CCheckout_Code和CPrevApp都是你的代码,你可以简单地在感兴趣的类中添加一个指针到'其他'课程。如果你有两个需要指向对方的对话框,你可以在父类或拥有类中缓存指向每个对话框的指针,并根据需要向父/所有者询问指向其他类的指针。



如果您有想要在它们之间来回切换的对话框,您可能需要查看属性页和属性表范例。 Clickety [ ^ ]
Since CCheckout_Code and CPrevApp are both your code, you can simply add a pointer in the class of interest pointing to the 'other' class. If you have 2 dialogs that need to point to each other, you could cache a pointer to each in the parent or owning class and ask the parent/owner for the pointer to the 'other' class as needed.

If you have dialogs where you want to go back and forth between them, you probably want to look at Property Page and Property Sheet paradigms. Clickety[^]


这篇关于在同一个基于MFC对话的应用程序中与不同对话框进行通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆