C++ MFC 整数文本字段始终设置为 0?
我正在 VC++ MFC 中创建首选项表单,并且有几个仅接受整数的文本字段。我是 MFC 新手,所以这就是我在一些教程中发现的初始化它们的方法:
CProgramDlg::CProgramDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgramDlg::IDD, pParent)
, m_nSampleValue1()
, m_nSampleValue2() ... m_nSampleValueN {}
这很宏大,但是当我运行它时,所有文本框都填满了零。我知道对于字符串,你可以只发送它“”,它会清除文本框,但我尝试为我的整数设置 NULL,但没有任何运气。
有没有办法让文本框为空而不显示零?感谢您的帮助!
I'm creating a preferences form in VC++ MFC, and I have several textfields that only accept integers. I'm new to MFC, so this is how I found to initialize them in some tutorial:
CProgramDlg::CProgramDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgramDlg::IDD, pParent)
, m_nSampleValue1()
, m_nSampleValue2() ... m_nSampleValueN {}
This is grand and all, but when I run it, all of the textboxes are filled with zeros. I know with strings that you can just send it "" and it will clear the textbox, but I tried NULL for my ints and did not have any luck.
Is there a trick to getting the textboxes to just be empty without showing zeros? Thank you for your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
m_nSampleValue1()
和m_nSampleValue2()
已进行值初始化。如果它是原始类型,那么这意味着它们将被零初始化。如果它是整数类型,那么我认为如果不更改代码的其他部分(哪部分?您没有将其发布在这里),这是不可能的。如果你不想这样做,或者很难做到,那么你可以将成员的类型更改为字符串,那么它们将自动为空字符串。
但是,如果您想查看非零值,请执行以下操作:
m_nSampleValue1()
andm_nSampleValue2()
are value-initialized. If its primitive types, then that means they will be zero-initialized.If its integral type, then I think that isn't possible without changing other part of the code (which part? you've not posted it here). If you don't want to do that, or if that is hard to do, then you can change the type of the members to string, then they will be empty strings automatically.
However, if you want to see non-zero values, then do this: