Archive for the ‘PC Software’ Category

VC::FileOpen & FileClose & getCurrentTime

星期三, 03月 8th, 2006

void CT0202Dlg::OnFileOpen()
{
    CFileDialog    openFileDialog(1);
    openFileDialog.DoModal();
    m_file_path = openFileDialog.GetPathName();
   
    HANDLE    hFileHandle;
    hFileHandle = CreateFile(m_file_path, GENERIC_READ, FILE_SHARE_READ, NULL,
        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if( hFileHandle == INVALID_HANDLE_VALUE ){
        AfxMessageBox("Open Failed ");
        return;
    }
   
    char        readContent[1025];
    DWORD        readLength;
    m_edit.Empty();
   
    do {
        ReadFile( hFileHandle, readContent, 1024, &readLength, NULL );
        readContent[readLength] = 0;
        m_edit = m_edit + (CString)readContent;
    } while ( readLength == 1024 );

    UpdateData(FALSE);
    CloseHandle( hFileHandle );
   
}


void CT0202Dlg::OnFileSave()
{
    CFileDialog    openFileDialog(0);
    openFileDialog.DoModal();
    m_file_path = openFileDialog.GetPathName();
   
    HANDLE    hFileHandle;
    hFileHandle = CreateFile(m_file_path, GENERIC_WRITE, FILE_SHARE_WRITE, NULL,
        CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if( hFileHandle == INVALID_HANDLE_VALUE ){
        AfxMessageBox("Create File Failed ");
        return;
    }
    UpdateData( FALSE );

   
    char        writeContent[1025];
    DWORD        writeLength;
    DWORD        nNumberOfByteToWrite = m_edit.GetLength();

    for( int i = 0; i < nNumberOfByteToWrite; ) {
        for( int j = 0; j < 1024 && i < nNumberOfByteToWrite; i++, j++ )
            writeContent[j] = m_edit.GetAt(i);
        writeContent[j] = 0;   
        WriteFile( hFileHandle, writeContent, j, &writeLength, NULL );
    }
    CloseHandle( hFileHandle );

}


GetCurrentTime
    COleDateTime     dateTime;
    dateTime = COleDateTime::GetCurrentTime();
    int y = dateTime.GetYear();
    int m = dateTime.GetMonth();
    int d = dateTime.GetDay();

Web Sites

星期五, 02月 10th, 2006

http://community.csdn.net/

技术开发最全面的论坛,里面可以遇到很多牛人,版面也很全,什么J2EE,.NET啊,该有的全上,在这里基本上可以提出任何问题,人气也是最旺的,不过一般提出的意见都有正方两面的,所以最终解决问题,还是靠自己。


登录 | 访问数21629 | 水木BLOG | 水木社区 | 关于我们 | Blog论坛 | 法律声明 | 隐私权保护 | 京ICP证050249号
水木社区Blog系统是基于KBS系统WordPress MU架构的