Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get the last key pressed when using Edit Control

Status
Not open for further replies.

LnOrS

Programmer
Apr 3, 2001
66
0
0
PT
Hi,

I’m using an Edit Control on an MFC dialog. That control must accept numbers only, but they are not integers!! I’d like to filter all keys pressed different than “0123456789.e-“.
I’ve done that but there should be an easiest way to do that. How can I get the code (ASCII) of a key I stroke?
Here’s the code I used:

void CDialog01::OnUpdateEDITValue()
{
CString sAux, sAux1;
float fAux = -1;

GetDlgItemText(IDC_EDIT_Value, sAux);
sscanf(sAux, "%f", &fAux);
if (fAux < 0 && !sAux.IsEmpty())
SetDlgItemText(IDC_EDIT_Time, &quot;&quot;);
else
{
sAux1 = sAux.SpanIncluding(&quot;0123456789.e-&quot;);
if (sAux.GetLength() != sAux1.GetLength())
SetDlgItemText(IDC_EDIT_Value, sAux1);
}
}


Regards,
LnOrS
 
there you should do subclassing of your edit control. Is much better. John Fill
1c.bmp


ivfmd@mail.md
 
How can I do that? Have some sugestions?
 
learn about subcalssing in windows and go on. John Fill
1c.bmp


ivfmd@mail.md
 
Subclassing is most indicated here.
1.Read about SubClassDlgItem CWnd member function from MSDN
2.Check out the CTRLTEST sample from MSDN. I think is most suited for what you need.

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top