我想问一个很菜的问题:在本窗体,如何把别的窗体的控件的值赋掉?
请写得详细一点

解决方案 »

  1.   

    获得该窗口父窗口指针,然后EnumChildWindows 再SetWindowText
      

  2.   

    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=197448
      

  3.   

    别的窗体的控件?
    Just get the window handle for your desired window and 
    SetWindowText 
    if still couldn't pull through,use
    SendMessage(...) 
    to send the WM_CHAR message to the window 
    or
    simulate the keybord or mouse input by 
    kb_event(.....) mouse_event(...)
      

  4.   

    如果另一个的窗体的类为“CAnotherDlg”,其中有一个控件的ID为“IDC_EDIT”,和它绑定的变量名为“m_Edit”
    CString temp;
    CAnotherDlg dlg;
    dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
    这样可以吗?
      

  5.   

    应该是不行的,
    CAnotherDlg dlg;
    dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
    这里窗口句柄还未创建,用我上面那种方法,或者用别的方法找到控件句柄后再操作
      

  6.   

    CString temp;
    CAnotherDlg dlg;
    dlg.DoModal();
    dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
    这样呢?
      

  7.   

    如果另一个的窗体的类为“CAnotherDlg”,其中有一个控件的ID为“IDC_EDIT”,和它绑定的变量名为“m_Edit”
    CString temp;
    CAnotherDlg dlg;
    dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
    这样可以吗?
    肯定不行,你创建的只是CAnotherDlg的另一个实例窗口, 而非当前显示的CAnotherDlg.
    可以采用全局变量.
    CAnotherDlg g_pAnotherDlg = NULL;
    CAnotherDlg::CAnotherDlg()
    {
       g_pAnotherDlg = this;
    }然后再你调用代码的cpp文件里
    extern CAnotherDlg g_pAnotherDlg;然后就可以直接用这个指针调用另一个窗口了, 但是,你必须保证CAnotherDlg窗口已经被创建.
      

  8.   

    //my test code,in your current dialog call parent dialog
    HWND hwnd=::FindWindow("#32770","TestParent");
    FromHandle(::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("Test");
      

  9.   

    dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
    能这样写吗?好象不能哦,
      

  10.   

    先用FindWindow获得窗口句柄
    (::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("yourtest");
      

  11.   

    HWND hwnd=::FindWindow("#32770","TestParent");
    FromHandle(::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("Test");
    这样写还是不行啊
    还是出现同样的错误
      

  12.   

    i think you should domodal your dialog first ,then all my code.This have tested it in my project.
      

  13.   

    CString temp;
    CAnotherDlg dlg;
    dlg.DoModal();
    dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
    这样怎么还是不行?