我在一个对话框中手工创建EDIT编辑框.代码入下.
void CCtrl32Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
x1+=200;x2+=300;y1+=400;y2+=500;
CRect rect(x1,x2,y1,y2);
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER, rect, this, ID_EXTRA_EDIT);
m_edit.SetFocus();
}
以上代码编译OK.运行出错.其中x1.x2.y1.y2是class CCtrl32Dlg : public CDialog中的公共变量.
如果将以上代码改为以下.运行OK.可以通过点按钮创建一个编辑框.
void CCtrl32Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
x1=200;x2=300;y1=400;y2=500;
CRect rect(x1,x2,y1,y2);
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER, rect, this, ID_EXTRA_EDIT);
m_edit.SetFocus();
}
但是点击第一次button时候会在对话框中创建一个编辑框.点第二下就出错.
void CCtrl32Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
x1+=200;x2+=300;y1+=400;y2+=500;
CRect rect(x1,x2,y1,y2);
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER, rect, this, ID_EXTRA_EDIT);
m_edit.SetFocus();
}
以上代码编译OK.运行出错.其中x1.x2.y1.y2是class CCtrl32Dlg : public CDialog中的公共变量.
如果将以上代码改为以下.运行OK.可以通过点按钮创建一个编辑框.
void CCtrl32Dlg::OnButton1()
{
// TODO: Add your control notification handler code here
x1=200;x2=300;y1=400;y2=500;
CRect rect(x1,x2,y1,y2);
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER, rect, this, ID_EXTRA_EDIT);
m_edit.SetFocus();
}
但是点击第一次button时候会在对话框中创建一个编辑框.点第二下就出错.
if(!m_edit.GetSafeHwnd())
{
x1=200;x2=300;y1=400;y2=500;
CRect rect(x1,x2,y1,y2);
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER, rect, this, ID_EXTRA_EDIT);
m_edit.SetFocus();
}
创建前先释放以前的:
if(m_edit.GetSafeHwnd())m_edit.DestroyWindow();x1=200;x2=300;y1=400;y2=500;
CRect rect(x1,x2,y1,y2);
m_edit.Create(WS_CHILD | WS_VISIBLE | WS_TABSTOP |
ES_AUTOHSCROLL | WS_BORDER, rect, this, ID_EXTRA_EDIT);
m_edit.SetFocus();