UpdateData(TRUE)/(FALSE)和DoModal - 内部步骤 [英] UpdateData(TRUE)/(FALSE) and DoModal - internal steps

查看:175
本文介绍了UpdateData(TRUE)/(FALSE)和DoModal - 内部步骤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







在Dialog Base Application中,如果我调用DoModal和UpdateData(TRUE)或(FALSE),那么这些功能是在内部调用的吗?



例如:



CEdit m_strString;



在OnInitDialog中,如果我调用UpdateData(FALSE)以及数据初始化为m_strString,那么该值将更新为编辑控件。如果我不使用UpdateData(FALSE)意味着,该值不会更新。这是怎么回事?



void classname :: OnInitDialog()

{



m_strString =test_value;

UpdateData(FALSE);



返回TRUE;

}





默认情况下OnInitDialog中的返回类型为TRUE如果我改为FALSE,那么会发生什么?



所有函数的调用是什么?



问候,

ranjith

解决方案

你的例子是错的:你的 m_strString 变量的类型为 CEdit 但它用作 CString



您应该阅读 Dialog Data Exchange [ ^ ](DDX)。



如果您不想使用DDX,请添加控件类型的成员变量并调用适当的函数来设置并从<$ c $中获取值c> OnInitDialog ( SetWindowText CEdit )和 OnOK GetWindowText CEdit )。



请参阅MSDN以获取 OnInitDialog [ ^ ]关于返回值:

Quote:

指定应用程序是否已将输入焦点设置为对话框中的某个控件。如果OnInitDialog返回非零值,Windows会将输入焦点设置为默认位置,即对话框中的第一个控件。仅当应用程序已将输入焦点显式设置为对话框中的某个控件时,应用程序才能返回0。



[更新]

OnInitDialog 的默认实现将调用 UpdateData (FALSE)。因此,在调用基类函数 CDialog :: OnInitDialog 之前初始化控件成员变量时,您不必自己调用它(在您的示例中缺少)。


Hi ,


In Dialog Base Application, if i call DoModal and UpdateData(TRUE) or (FALSE),what are the functions are getting called internally?.

for example:

CEdit m_strString;

In OnInitDialog, if i call UpdateData(FALSE) and what ever the data is initializing into m_strString that value is updated into edit control. If i won't use UpdateData(FALSE) means, the value is not updating.here what is happening?

void classname::OnInitDialog()
{

m_strString = "test_value";
UpdateData(FALSE);

return TRUE;
}


by default return type is TRUE in OnInitDialog, if i changed to FALSE, then what happen?.

what are all the functions are getting called?.

regards,
ranjith

解决方案

Your example is wrong: Your m_strString variable is of type CEdit but it is used as CString.

You should read about Dialog Data Exchange[^] (DDX).

If you don't want to use DDX, add member variables of your control types and call the appropiate functions to set and get the values from within OnInitDialog (SetWindowText for CEdit) and OnOK (GetWindowText for CEdit).

See the MSDN for OnInitDialog[^] about the return value:

Quote:

Specifies whether the application has set the input focus to one of the controls in the dialog box. If OnInitDialog returns nonzero, Windows sets the input focus to the default location, the first control in the dialog box. The application can return 0 only if it has explicitly set the input focus to one of the controls in the dialog box.


[UPDATE]
The default implementation of OnInitDialog will call UpdateData(FALSE). So you don't have to call it yourself when initializing your control member variables before calling the base class function CDialog::OnInitDialog (which is missing in your example).


这篇关于UpdateData(TRUE)/(FALSE)和DoModal - 内部步骤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆