专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > VC

有些着急请来看下,该怎么处理

发布时间:2011-06-23 14:16:50 文章来源:www.iduyao.cn 采编人员:星星草
有些着急,请来看下
有一个主窗口DLG1,往里面插入一个窗口DLG2,现在想在DLG1的一个函数里面得到DLG2里面的一个EDIT空间指针适用下列语句

CEdit *Edit=(CEdit *)DLG2::GetDlgItem(IDC_EDIT1);
错误::“CWnd::GetDlgItem”: 非静态成员函数的非法调用

换一种
DLG2 dlg;
CEdit *Edit=(CEdit *)dlg.GetDlgItem(IDC_EDIT1);

在执行时出错,似乎是挺严重的错误

现在有点迷糊,请告诉我可以怎么做





------解决方案--------------------
C/C++ code
CDialog2 *dlg2;

BOOL CTest1Dlg::OnInitDialog()
{
    CDialog::OnInitDialog();

    // 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
    dlg2 = new CDialog2;
    dlg2->Create( IDD_DIALOG2, this );
    dlg2->ShowWindow( SW_SHOW );
    
    return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTest1Dlg::OnButton1()
{
    CEdit *pEdit = ( CEdit * )( dlg2->GetDlgItem( IDC_EDIT1 ) );
    char tt[ 100 ] = "";
    pEdit->GetWindowText( tt, sizeof( tt ) );
    AfxMessageBox( tt );
}

------解决方案--------------------
為什麼在void CTest1Dlg::OnButton1()這個函數裏面我定義CDialog2 dlg2,然後dlg2.GetDlgItem( IDC_EDIT1 )會不可以呢?? 
我的看法: 在onbutton中 定义 时,这个窗口对象只是个局部变量,所以如果你在此函数外边操作获得的edit内容
可能出错

我想在DLG1上面接收DLG2上面一个EDIT控件中的数据,但是用ShowWindow显示DLG2时候,DLG1程序仍在运行,也就是说程序不会暂停,用domodal函数,却有出错,即dlg2->domodal()会出错,有什么办法么。
我的看法:
这两种一个是模式对话框,一个是非模式,你去msdn看下两者的区别,可能有帮助
友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: