MFC 常用系统函数

1、获取当前路径:

    char path[MAX_PATH];
    GetCurrentDirectoryA(MAX_PATH,path);

2、获取系统时间
需要添加头文件:#include <Windows.h>

    SYSTEMTIME sysTime;
    GetLocalTime(&sysTime);
    printf("%4d%02d%02d%02d%02d",sysTime.wYear,sysTime.wMonth,sysTime.wDay,sysTime.wHour,sysTime.wMinute);

3、打开文件对话框

    char pFileName[MAX_PATH]; 
    int nPos = GetCurrentDirectoryA( MAX_PATH, pFileName); 

    CString defaultDir =L"\\";   //默认打开的文件路径 

    CString fileName(pFileName);         //默认打开的文件名 
    CFileDialog dlg(TRUE, //TRUE为OPEN对话框,FALSE为SAVE AS对话框
        defaultDir, 
        fileName,
        OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,
        (LPCTSTR)_T("XML Files (*.xml)|*.xml||"),
        NULL);
    CString m_ProjectPath;
    if(dlg.DoModal()==IDOK)
    {
        m_ProjectPath=dlg.GetPathName(); //文件名保存在了FilePathName里
    }

4、保存文件对话框

   BOOL isOpen = FALSE;        //是否打开(否则为保存) 
    char pFileName[MAX_PATH]; 
    int nPos = GetCurrentDirectoryA( MAX_PATH, pFileName); 

    CString defaultDir =L"\\";   //默认打开的文件路径 
    CString fileName(pFileName);         //默认打开的文件名 
    CString filter = L"文件 (*.xml)|*.xml||";   //文件过虑的类型 
    CFileDialog openFileDlg(isOpen, defaultDir, fileName, OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT, filter, NULL);  
    openFileDlg.GetOFN().lpstrInitialDir = L""; 

    if (openFileDlg.DoModal() == IDOK)
    {
        CString filePath = defaultDir +"\\"+fileName;
        filePath = openFileDlg.GetPathName();
    }

你可能感兴趣的:(mfc)