智手移动中文网's Archiver

智手小石头 发表于 2006-5-9 11:19

文件应该存储在手机的正确位置

这个路径可以写死也可以运行时获得:
方法一:


code:--------------------------------------------------------------------------------
_LIT(KBitmapFilename, "c:\\system\\apps\\test\\xxx.mbm");
const TUint16 KMMCDriveLetter = 'e';
const TUint16 KROMDriveLetter = 'z';
// try 3 locations - application directory in C,E (memory card), and Z drive
TFileName imageLocation(KBitmapFilename);
TInt loadErr = iImageFlag->Load(imageLocation,useFullScreen);
// not found on C, try E & Z
if(loadErr != KErrNone)
        {
        imageLocation[0] = KMMCDriveLetter;   
        loadErr = iImageFlag->Load(imageLocation,useFullScreen);
        if(loadErr != KErrNone)
            {
            imageLocation[0] = KROMDriveLetter; // in emulator, apps usually reside on z
            loadErr = iImageFlag->Load(imageLocation,useFullScreen);
            }
        }
--------------------------------------------------------------------------------

方法二:


code:--------------------------------------------------------------------------------
void GetFullPathName(TDes& aFileName)
{
        // Get default drive and path
        TParse parse;
        TFileName appPath;
        TBuf<5>          appDrive;
        parse.Set(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName(), NULL, NULL);
        appPath.Copy(parse.DriveAndPath());
        appDrive.Copy(parse.Drive());

        // Parse the file name
        parse.Set(aFileName, NULL, NULL);
        if (parse.Drive().Length() == 0)
        {
                if (parse.Path().Length() == 0)
                { // Use default path and drive
                        aFileName.Insert(0, appPath);
                }
                else
                { // Use default drive
                        aFileName.Insert(0, appDrive);
                }
        }
}
--------------------------------------------------------------------------------


Regards
Maxying



--------------------------------------------------------------------------------


为了增强程序的可移植性,还是不要用绝对路径的好。我们可以在操作前获取当前设备的存储器路径。

例如:
根目录:
PathInfo::PhoneMemoryRootPath()
存储图片文件目录:
PathInfo::ImagesPath()
存储安装SIS文件目录:
PathInfo::InstallsPath()
存储声音文件目录:
PathInfo::SoundsPath()

如果想要定位MMC卡这种外加的存储器应该这样:

#include <PathInfo.h>
TFileName path = PathInfo::MemoryCardRootPath();

r60600



PathInfo这个类是在S60 2.0平台的,楼主的Symbian 6.1也就是S60 1.0平台用不了的!

Regards
Maxying

页: [1]

Powered by Discuz! Archiver 6.1.0  © 2001-2007 Comsenz Inc.