MFC中编辑框的更新问题~
我想让编辑框内容做到实时显示,但是我试过了很多种方法,都不行,加入UpdateData(false);和不加没区别,都是最后才显示,,哪位大虾可以给出出建议~
[解决办法]
发消息...
[解决办法]
UpdateData(false)->UpdateData(true)
[解决办法]
UpdateData(false)改成UpdateData(true)
[解决办法]
好久没玩MFC了。
[解决办法]
CEdit的基类是CWnd
CWnd::Invalidate
void Invalidate( BOOL bErase = TRUE );
Parameters
bErase
Specifies whether the background within the update region is to be erased.
Remarks
Invalidates the entire client area of CWnd. The client area is marked for painting when the next WM_PAINT message occurs. The region can also be validated before a WM_PAINT message occurs by the ValidateRect or ValidateRgn member function.
The bErase parameter specifies whether the background within the update area is to be erased when the update region is processed. If bErase is TRUE, the background is erased when the BeginPaint member function is called; if bErase is FALSE, the background remains unchanged. If bErase is TRUE for any part of the update region, the background in the entire region, not just in the given part, is erased.
Windows sends a WM_PAINT message whenever the CWnd update region is not empty and there are no other messages in the application queue for that window.
CWnd Overview
[解决办法]
Class Members
[解决办法]
Hierarchy Chart
See Also CWnd::BeginPaint, CWnd::ValidateRect, CWnd::ValidateRgn,::InvalidateRect
CWnd::UpdateWindow
void UpdateWindow( );
Remarks
Updates the client area by sending aWM_PAINT message if the update region is not empty. The UpdateWindow member function sends a WM_PAINT message directly, bypassing the application queue. If the update region is empty, WM_PAINT is not sent.
CWnd Overview
[解决办法]
Class Members
[解决办法]
Hierarchy Chart
See Also ::UpdateWindow, CWnd::RedrawWindow
[解决办法]
UpdateData(TRUE) 将控件窗口的值传给关联变量
UpdateData(FALSE) 将关联变量的值传给控件窗口
第二步是显示,但是需要先执行第一步刷新控件关联变量的值。
[解决办法]
简单的使用方法
拖两个edit控件进来
分别给这两个控件命名为
int m_a;
int m_b;
////////////////////////////////////////////
CMyTestMfcDlg::CMyTestMfcDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyTestMfcDlg::IDD, pParent)
, m_a(0)
, m_b(0)
{
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyTestMfcDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Text(pDX, IDC_EDIT1, m_a);
DDX_Text(pDX, IDC_EDIT2, m_b);
}
/////////////////////////////////////////////////
这些步骤,你在控件上面点右键选择添加变量就可以完成,变量类型选择(value),当然选择control也可以完成。
加一个按钮
当点击按钮
void CMyTestMfcDlg::OnBnClickedOk()
{
// TODO: 在此添加控件通知处理程序代码
//OnOK();
UpdateData(TRUE);
m_b = m_a;
UpdateData(FALSE);
}
就得到你的结果,希望能对你有帮助;