views:

699

answers:

1

Hai in vc++6.0 MFC, i connected a serial port, while reading and displaying a data(i want to display date and time ) in edit box (IDC_EDIT1),

My problem is I used a vertical scrollbar in the edit box. Whenever I display new data, the vertical scrollbar moves up; it must come down (scroll down),

The written code:

CString temp;
    static CString dat;
    static CString tim;

    if (dat != m_date || tim != m_time)
    {
        temp = "\r\n-------------------------------------------------------------------------------------------------\r\n\r\n";
        temp = temp + "Date: ";
        temp = temp + m_date;
        temp = temp + "\t\t\t";
        temp = temp + "Time: ";
        temp = temp + m_time;
        temp = temp + "\r\n-------------------------------------------------------------------------------------------------";
    }

    dat = m_date;
    tim = m_time;

    temp = temp + "\r\n\r\n";
    temp = temp + m_sensorname +"\t\t";
    temp = temp + m_value + "\t\t";
    temp = temp + m_units;

    if (m_datalog_id ==0x01)
        m_pdialog->m_editlog1= m_pdialog->m_editlog1 + temp;
    else if(m_datalog_id==0x02)
        m_pdialog->m_editlog2 = m_pdialog->m_editlog2 + temp;
    else
        return;

    m_pdialog->UpdateData(false);
+3  A: 

After you write your text to the edit control, call IDC_EDIT1.ScrollToCaret(). That will scroll it down to the bottom where the new line is.

Ron

Ron Savage