选择文件对话框

来源:互联网 发布:mmd动作数据lovelive 编辑:程序博客网 时间:2024/06/12 21:28

经常在我们的项目中可能会用到选择文件对话框.
当然更会用到选择指定格式的文件

#include <maknfilefilter.h>

//定义一个属于自己的类,也就是文件过滤器
//代码演示了选择图像文件的对话框

class CMelodyFilter : public MAknFileFilter
{
    TBool Accept(const TDesC &aDriveAndPath, const TEntry &aEntry) const
    {
    if(aEntry.IsDir() || aEntry.iName.Right(4) == _L(".jpg") || aEntry.iName.Right(4) == _L(".png")
            || aEntry.iName.Right(4) == _L(".gif"))
        return ETrue;
    else
        return EFalse;
    }
};


//选择文件对话框
TBool CSaveImageAppUi::SelectFileL(TFileName& aFileName)
    {
    TFileName fileName;
    
    CAknMemorySelectionDialog* memSelectionDialog =
        CAknMemorySelectionDialog::NewL(ECFDDialogTypeSelect, EFalse);
    CAknMemorySelectionDialog::TMemory mem(CAknMemorySelectionDialog::EPhoneMemory);

    TInt ret = memSelectionDialog->ExecuteL(mem);
    CleanupStack::PopAndDestroy(memSelectionDialog);
    if (!ret)
             
        return EFalse;
        }

    CAknFileSelectionDialog* fileSelectionDialog = NULL;
    if (mem == CAknMemorySelectionDialog::EMemoryCard)
        {
        fileSelectionDialog = CAknFileSelectionDialog::NewL(
                ECFDDialogTypeSelect, R_FILE_SELECTION_DIALOG_E);
        }
    else
        {
        fileSelectionDialog= CAknFileSelectionDialog::NewL(
                ECFDDialogTypeSelect, R_FILE_SELECTION_DIALOG_C);
        }

    CMelodyFilter* filter = new(ELeave) CMelodyFilter;

    fileSelectionDialog->SetDefaultFolderL(_L("Image\\"));
    fileSelectionDialog->AddFilterL(filter);
    TBool err = fileSelectionDialog->ExecuteL(fileName);
    aFileName.Copy(fileName);
    delete fileSelectionDialog;
   
    return err;
    }

//资源文件
#include <commondialogs.hrh>  //FILESELECTIONDIALOG
#include <commondialogs.rh>

RESOURCE FILESELECTIONDIALOG r_file_selection_dialog_c
{
 title = <0x9009><0x62e9><0x6587><0x4EF6>;
 root_path = "C:\\";
 }

RESOURCE FILESELECTIONDIALOG r_file_selection_dialog_e
{
 title = <0x9009><0x62e9><0x6587><0x4EF6>;
 root_path = "E:\\";
}

 

Archived:How to fetch media files using Symbian C++

http://www.developer.nokia.com/Community/Wiki/How_to_fetch_media_files