使用VC开发的一个简单工作日志软件

1,软件界面



2,示例代码

void CworklogDlg::OnBnClickedBtnExit()
{
    // TODO: Add your control notification handler code here
    CDialog::OnCancel();
}

void CworklogDlg::OnBnClickedBtnSave()
{
    // TODO: Add your control notification handler code here
    UpdateData(TRUE);

    // 保存指定日期的工作日志
    SaveWorkLog(m_time);
}

void CworklogDlg::OnDtnDatetimechangeDatetimepicker2(NMHDR *pNMHDR, LRESULT *pResult)
{
    LPNMDATETIMECHANGE pDTChange = reinterpret_cast<LPNMDATETIMECHANGE>(pNMHDR);
    // TODO: Add your control notification handler code here
    *pResult = 0;

    UpdateData(TRUE);

    // 打开指定日期的工作日志
    OpenWorkLog(m_time);

    UpdateData(FALSE);
}

// 打开指定日期的工作日志
void CworklogDlg::OpenWorkLog(CTime time)
{
    CString strDate = time.Format("%Y-%m-%d");
    CString strFileName;
    strFileName.Format("%s.txt", strDate);

    FILE* file;
    char szLog[10240] = {0};
    file = fopen( strFileName.GetBuffer(), "rb" );

    if( NULL != file)
    {
        fread(szLog, 1, 10240, file );
        fclose(file);
        m_strLog = szLog;
    }
    else
    {
        m_strLog.Empty();
    }
}

// 保存指定日期的工作日志
void CworklogDlg::SaveWorkLog(CTime time)
{
    CString strData = time.Format("%Y-%m-%d");
    CString strFileName;
    strFileName.Format("%s.txt", strData.GetBuffer());

    FILE* file;
    file = fopen( strFileName.GetBuffer(), "w+b" );
    fwrite(m_strLog.GetBuffer(), m_strLog.GetLength(), 1, file);
    fclose(file);
}

3,示例工程下载

http://download.csdn.net/detail/mnorst/3474596

你可能感兴趣的:(工作,File,null)