c++ - MFC - Remove leading zeros for CEdit number control -
i find cedit control has option 'number' in property, can prevent user enter non-digit character textbox - cedit number control now. if there option 'number', think maybe there way remove leading zeros cedit simple option 'number'.
i have tried dialog data exchange hope remove leading zeros me automatically, won't.
then think way add en_killfocus message each of cedit number controls, find exhausted.
so think better way add en_killfocus, cedit number controls lose focus event point 1 function, in function i'll remove leading 0 'current' control, in c# can 'current' control, in c++ don't know if it's supported.
or inherit cedit make ceditnum - implement lose focus remove leading zeros feature, solution, can't design on visual studio design window (i think). hope there solution similar this solution (which solution draw&drop problem)
anyway, before apply final solution (en_killfocus), want make sure if there better way - least implement, reuse existing implement of mfc.
a little explain remove leading zeros: enter: 00001 cedit control, lose focus, cedit control show you: 1. idea ms excel when enter number cell.
"but cedit number controls lose focus event point 1 function"
that true, control id of control that's lost focus parameter.
add message table, replace idc_first, idc_last first , last ids of edit controls, or use 0, 0xffffffff all.
on_control_range(en_killfocus, idc_first, idc_last, onkillfocus).
here signature of onkillfocus, , how cwnd apply changes.
void cmydialogclass::onkillfocus(uint nid) { // can further check if id 1 of interest here... // if edit control control ids not contiguous, example. // can cedit* here, if used ddx map // control cedit. cwnd* pctrl = getdlgitem(nid); if (pctrl) { cstring str; pctrl->getwindowtext(str); // remove zeroes, or format like.... str.format(_t("%d"), _tcstoi(str)); pctrl->setwindowtext(str); } } // if mapped control cedit, here's how can safely // pointer cedit cedit* pedit = (cedit*)getdlgitem(nid); assert_kindof(cedit, pedit); // debug check if (pedit && pedit->iskindof(runtime_class(cedit))) // standard check { // .... }
Comments
Post a Comment