无模式对话变量传递 [英] modeless dialog variable passing

查看:63
本文介绍了无模式对话变量传递的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的程序中调用了一个无模式对话框。想要从父级初始化子对话框上的控件。子表单正确打开和关闭。我想要做的是使用父级的字符串初始化Edit控件。如何让父母看得见?





我从父母那里打电话:



I have a modeless dialog that I am calling in my program. Would like to initialize the controls on the child dialog from the parent. The child form opens and closes properly. What I am would like to do is to initialize the Edit controls with strings from the parent. How do I make the parent visible?


I call this from the parent:

void CBudgetDlg::OnViewUnpaidExpenses()
{
    // TODO: Add your command handler code here

    if (pUnpaidExpenses == NULL)
    {
        pUnpaidExpenses = new CUnpaidExpDlg(this);
    }
    else
    {
        delete pUnpaidExpenses;
        pUnpaidExpenses = NULL;
        pUnpaidExpenses = new CUnpaidExpDlg(this);
    }
}







这是孩子:






This is the child:

CUnpaidExpDlg::CUnpaidExpDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CUnpaidExpDlg::IDD, pParent)
{
    if(Create(CUnpaidExpDlg::IDD,pParent))
    {
        ShowWindow(SW_SHOW);
    }
    my_string = _T("");
}





[edit]

例如,如果我在父对话框中有CString m_string我想将值传递给子对话框CString my_string。这是我想要做的。不确定如何编码。



[edit]
For example if I have CString m_string in the parent dialog and I want to pass the value to the child dialog CString my_string. Here is what I am trying to do. Not sure how to code it.

CUnpaidExpDlg::CUnpaidExpDlg(CWnd* pParent /*=NULL*/)
    : CDialog(CUnpaidExpDlg::IDD, pParent)
    ,my_string = CBudgetDlg.m_string;
{
    if(Create(CUnpaidExpDlg::IDD,pParent))
    {
        ShowWindow(SW_SHOW);

    }
}

推荐答案

如果子对话框在构造时只需要一次值,然后你可以传递像上面提到的理查德这样的参数,或者为传递变量添加一些公共接口(添加一些公共的get / set方法,如果你需要传递很多变量,将它们包含在一个结构中)。如果需要在对话框启动时设置变量,请将消息添加到子对话框并通过Windows消息/处理程序传递数据。消息为您提供的优势是,它们可以轻松处理同步调用或异步调用。
If the child dialog only needs the values once while being constructed, then you can pass arguments like Richard mentioned above, or add some of public interface for passing variables (add some public get/set methods, if you need to pass a lot of variables, enclose them in a structure). If you need the variables to be set while the dialog is up, add messaging to the child dialog and pass data through Windows messages/handlers. Messages give you the advantage that they can easily handle either synchronous calls or asynchronous calls.


这篇关于无模式对话变量传递的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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