别的窗体的控件? 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(...)
//my test code,in your current dialog call parent dialog HWND hwnd=::FindWindow("#32770","TestParent"); FromHandle(::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("Test");
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(...)
CString temp;
CAnotherDlg dlg;
dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
这样可以吗?
CAnotherDlg dlg;
dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
这里窗口句柄还未创建,用我上面那种方法,或者用别的方法找到控件句柄后再操作
CAnotherDlg dlg;
dlg.DoModal();
dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
这样呢?
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窗口已经被创建.
HWND hwnd=::FindWindow("#32770","TestParent");
FromHandle(::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("Test");
能这样写吗?好象不能哦,
(::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("yourtest");
FromHandle(::GetDlgItem(hwnd,IDC_EDIT1))->SetWindowText("Test");
这样写还是不行啊
还是出现同样的错误
CAnotherDlg dlg;
dlg.DoModal();
dlg.GetDlgItem(IDC_EDIT)->SetWindowText(temp);
这样怎么还是不行?