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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A simple MFC problem? About display time in "00" format

Status
Not open for further replies.

bigbubu

Programmer
Sep 20, 2002
5
US
Here is the problem.

I linked m_iHour to edit box object, on its ON_CHANGE event()

{

UpdateData(TRUE);
CString sMessage;
if (m_iHour <1|| m_iHour>12)
{
sMessage = &quot;Hour should be an integer between 1 and 12.&quot;;
MessageBox(sMessage);
}
}

but when hour<10, I mean if input 3, it should display &quot;03&quot;, I know Format can
make it, but here I need m_iHour to be integer not a string type, and Format
can only be used to CString type.

Is there any other way can solve this?
Thanks in advance
 
I don't know what you want to do but iif you want to display information like '03' then you hev to work lith string. Of course you can get integer val from string with :

int m_int = atoi((LPCTSTR) str).
You can input and output string, but in fact to work with integer./sorry but no way to display int val with '0' on the left side/

I hope that this will help you.
 

If you're working with time why don't you use the CDateTimeCtrl? It returns a CTime object. Very easy to learn and use.

For example to get the date from the control with m_valueTimePicker being a CTime DDX variable.

CTimeSelector::GetTime(){

UpdateData(TRUE);

// get selected time
time_t time = m_valueTimePicker.GetTime();
ctTimePicked = CTime(time);

TRACE1(&quot;PICKED MINUTE = %i\n&quot;,ctTimePicked.GetMinute());
TRACE1(&quot;PICKED HOUR = %i\n&quot;,ctTimePicked.GetHour());
TRACE1(&quot;PICKED DAY = %i\n&quot;,m_valueDate.GetDay());
TRACE1(&quot;PICKED MONTH = %i\n&quot;,m_valueDate.GetMonth());
}

To set the time is just as easy.

BOOL CTimeSelector::OnInitDialog()
{
CDialog::OnInitDialog();

m_valueTimePicker = CTime::GetCurrentTime();
UpdateData(FALSE);

return TRUE;
}

Brother C
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top