a question about Edit Box
-
-
I added an Edit Box to my Dialog. i'd like it only accept numeric input. when a non-numeric key is pressed a warning dialog will apear. i mean, just after press the key, not after my button 'Subject' is pressed, the dialog appears. Hello World
If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor. Shuang. Wu wrote: when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed. - Aaron
-
If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor. Shuang. Wu wrote: when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed. - Aaron
-
If you only want it to accept 0-9 you can set it's style as "Numeric" in the resource editor. Shuang. Wu wrote: when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed. - Aaron
monrobot13 wrote: **Shuang. Wu wrote: **when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed.**** BTW, i failed to do as my previous idea. I would like to know if there is some way to do it? Hello World
-
monrobot13 wrote: **Shuang. Wu wrote: **when a non-numeric key is pressed a warning dialog will apear This isn't a good design idea. It would get pretty annoying having to close a dialog everytime you press an incorrect key. Setting the edit's style as numeric will produce a beep when an invalid key is pressed.**** BTW, i failed to do as my previous idea. I would like to know if there is some way to do it? Hello World
You can do this using CWnd::SubclassDlgItem Derive your own class say CMyEdit from CEdit and add a WM_CHAR handler: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar >= '0' && nChar <= '9') { CEdit::OnChar(nChar, nRepCnt, nFlags); return; } else { AfxMessageBox("Invalid Key"); } } In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); where m_myEdit is a Dialog member of type CMyEdit and IDC_EDIT1 is the edit control id. Hope this helps!
-
You can do this using CWnd::SubclassDlgItem Derive your own class say CMyEdit from CEdit and add a WM_CHAR handler: void CMyEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { if (nChar >= '0' && nChar <= '9') { CEdit::OnChar(nChar, nRepCnt, nFlags); return; } else { AfxMessageBox("Invalid Key"); } } In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); where m_myEdit is a Dialog member of type CMyEdit and IDC_EDIT1 is the edit control id. Hope this helps!
Mahendra_786 wrote: In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); This is highly unnecessary, and is handled automatically when a member variable is mapped to a control (using ClassWizard).
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
-
Mahendra_786 wrote: In your Dialog class add this to OnInitDialog: m_myEdit.SubclassDlgItem(IDC_EDIT1, this); This is highly unnecessary, and is handled automatically when a member variable is mapped to a control (using ClassWizard).
"The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)
That is :rolleyes:HIGHLY:rolleyes: correct and my way in fact may be insufficient not just unnecessary. In fact DDX_* somewhere calls SubclassWindow to do this. Moreover the way I suggested I am not sure how UpdateData will work beside other side-effects. Due Regards Mahendra