开发者

C++ MFC Integer Textfields Always Set to 0?

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* pPar开发者_运维知识库ent /*=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!


m_nSampleValue1() and m_nSampleValue2() are value-initialized. If its primitive types, then that means they will be zero-initialized.

Is there a trick to getting the textboxes to just be empty without showing a 0?

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:

CProgramDlg::CProgramDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProgramDlg::IDD, pParent)
, m_nSampleValue1(100)
, m_nSampleValue2(200) ... m_nSampleValueN(1000) {}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜