【发布时间】:2013-01-12 13:41:11
【问题描述】:
我是 ATL 的新人。所以请原谅我问这个问题。
问题描述:
一个CEdit 控件被添加到ATL 对话框类中。它附在对话框初始化函数中。
//Define the edit control
ATLControls::CEdit m_txtInput;
//In the OnInitDialog function
m_txtInput.Attach(GetDlgItem(IDC_INPUT_LINE));
m_txtInput.SetWindowText(_T("New directory"));
//In the public memeber function of the dialog GetInput()
//I have tried three kinds of method to get the text. But all of them are throw an
//assert exception, IsWindow() failed.
//1.
GetDlgItemText(IDC_INPUT_LINE, input);
//2.
ZeroMemory(m_lptstrInput, MAX_PATH);
m_txtInput.GetLine(0, m_lptstrInput, MAX_PATH);
//3.
BSTR input;
m_txtInput.GetWindowText(input);
Here 是一个关于如何从CEdit 获取文本的主题,但它不起作用。
为什么CEdit控件可以用SetWindowText()函数设置文本,但不能用GetWindowText()函数获取文本?这真的让我很困惑。如果有人可以为我解释一下,非常感谢。
【问题讨论】:
-
我直接使用window API绕过了这个问题。使用 ::GetWindowText(m_txtInput.m_hwnd, buffer, size) 而不是直接从控件调用 GetWindowText 方法,它就可以工作了。但是我还是想知道为什么以前的方法不能通过assert。谢谢。
-
好像 ::GetWindowText 的结果是空的...为什么?...
-
问题成立,assert问题是由对话框关闭后调用GetInput()方法引起的。单击确定按钮后,相关窗口被释放。谢谢。