MFC Open File dialog box and get the file name based on the path

 

// 22 define global variables
CString g_NewFileName;

22 // open file dialog
bool CGetFacesDlg :: OpenFileFrame () // CGetFacesDlg class name, may correspond to modify their
{
    CString filePath;
    // class using MFC provides the CFileDialog
    the CFileDialog fileOpenDlg (TRUE, _T ( "* PNG." ), "", OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,
    "Image Files (* .jpg;. * BMP) | * .jpg;. * BMP | Image File (* BMP) | * .bmp;. | Image File (*. PNG) | * .png; | All Files (* *) | * || *.. ", NULL);
    char title [] = {" the Open Image "}; // provided only dialog box title
    fileOpenDlg.m_ofn. title = lpstrTitle;
    IF (fileOpenDlg.DoModal () == IDOK)
    {    
        filePath = fileOpenDlg.GetPathName ();
        
        IF (GetFileNameFromFilePath (filePath) == to false) // 22 is Gets the name of the folder to be created from the file path of
        {
        the MessageBox ( 'Gets the folder name failed "," error ", MB_OK);
        return ;
        }

        g_SourceImg = cvvLoadImage (filePath); // open the path in image according to the image
        IF (g_SourceImg = NULL!)
        {
        m_bflagBtn = to true;
        // The ID of the control in the dialog box displaying an image; DrawPicToHdc (g_SourceImg, IDC_STATIC)
        }

    
    }
}

// Get the name of the file path 22 from the folder to be created
BOOL CGetFacesDlg :: GetFileNameFromFilePath (CString FilePath)
{
        int nalllength FilePath.GetLength = ();
        int nIndex = FilePath.ReverseFind ( '\\');
        int = nalllength nsubLength -nindex-1;

        CString Picname = FilePath.Right (nsubLength); // 22 acquires the file path name (contains formatting)
        nIndex = Picname.Find (, 0 '.');
        G_NewFileName = Picname.Left (nIndex); // get the path 22 is the name of the file (without formatting)
                                IF (g_NewFileName == "") return to false;
        return to true;
}

Guess you like

Origin blog.csdn.net/ZDT_zdh/article/details/84257079