CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1

    How can I display current Time in a Static text.

    I have already a dialog with Static text, IDC_STATICTIME, I have created a variable using CString m_sTime and with this

    COleDateTime m_strTime= COleDateTime::GetCurrentTime();
    m_sTime = m_strTime.Format("%b %d %Y);

    Question: How can i display it in a certain portion in the dialog? So, the IDC_STATICTIME, i've used should display:

    Current Date: the date(say May 23 2005)

    I have put the code in DoDataExchange(CDataExchange* pDX)
    with DDX_Text(pDX, IDC_STATICTIME, m_sTime); and it display as it should be but any other option without using DDX_text to display it?

  2. #2
    Join Date
    Nov 2003
    Posts
    2,185

    Re: How can I display current Time in a Static text.

    with the class wizard you can add a control variable to the control.

    Then, m_sTime = m_strTime.Format("%b %d %Y); won't do anything.

    you should use the function as m_strTime.Format("%b, %d, %Y", value1, value2, value3);

    Then, if you added a control variable, you can use this:
    m_lblMyStatic.SetWindowText(m_sTime);

  3. #3

    Re: How can I display current Time in a Static text.

    thank you for the reply, but m_strTime.Format("%b, %d, %Y", value1, value2, value3); seems unclear to me, what is value1, value2, value3? I just want to display the current date, put it in a create STATIC TEXT. Sorry but I am new in Visual. Can i also put the code outside DDX

  4. #4
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    324

    Re: How can I display current Time in a Static text.

    The easiest way is:
    SetDlgItemText(IDC_STATICTIME, m_sTime);
    Regards,
    Marco Era
    www.marcoera.com

    Latest post on my blog: Back to the Amiga's times

  5. #5
    Join Date
    Nov 2003
    Posts
    2,185

    Re: How can I display current Time in a Static text.

    Do you even understand the function Format?

    Check out the function description in MSDN.

    For every %d, %s or whatsoever, you should add values.

    So, if you want to add integers and strings to a string, use this code:

    Code:
    CString sExample = "hello";
    int iExample = 5;
    CString sFinalString;
    
    // Because the first % is a s, we should first add the sExample as parameter
    sFinalString.Format("%s, how are you doing? This is a number: %d", sExample, iExample);
    The value if sFinalString will be:
    hello, how are you doing? This is a number: 5

    Do you understand?

  6. #6

    Re: How can I display current Time in a Static text.

    yes, i know that, we dont need the value1, value2, value3 since the Format function does that automatically i think in COleDateTime, because we are getting the Current Date of the system. Anyway, thank you all for the reply, I will try to figure it out myself.

  7. #7
    Join Date
    Oct 2002
    Location
    Italy
    Posts
    324

    Re: How can I display current Time in a Static text.

    Quote Originally Posted by Tischnoetentoet
    Do you even understand the function Format?
    I think scrapage_online is using COleDateTime's Format member, not CString's (despite the actual name of the object, m_strTime, would make you think it's a string).
    Regards,
    Marco Era
    www.marcoera.com

    Latest post on my blog: Back to the Amiga's times

  8. #8

    Re: How can I display current Time in a Static text.

    Quote Originally Posted by puzzolino
    I think scrapage_online is using COleDateTime's Format member, not CString's (despite the actual name of the object, m_strTime, would make you think it's a string).
    sorry about the confusion, yes i am using the COleDateTime format, i just used the m_strTime object just for debug.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured