Symbian开发总结

来源:互联网 发布:linux行合并 编辑:程序博客网 时间:2024/06/01 18:28

83. 生成Dll,App时不能使用静态可写变量:
 static const char * KStrX  = "x";
     使用
 OPTION GCC  -save-temps
 可以生成汇编代码,查找Bss和Text段就可以看到静态可写变量。
    改为:
 static const char * const KStrX  = "x";
    或者:
 static const char KStrX[]  = "x";

84. 播放声音:
 a. 创建对象:
  iSoundPlayer = CMdaAudioPlayerUtility::NewFilePlayerL(soundFile,
        *this, EMdaPriorityMin, EMdaPriorityPreferenceNone);
 NewL()不指定声音剪辑, NewFilePlayerL(), NewDesPlayerL(),NewDesPlayerReadOnlyL() 预加载声音剪辑
 当加载完成,会调用MMdaAudioPlayerCallback::MapcInitComplete();
 
 b. 当对象创建完毕,可以使用一下方法打开音频剪辑.
 OpenFileL(const TDesC& aFileName);
 OpenDesL(const TDesC8& aDescriptor);
 OpenUrlL(const TDesC& aUrl, TInt aIapId = KUseDefaultIap, const TDesC8& aMimeType=KNullDesC8);
 如果音频剪辑已经打开或播放,在指定一个新音频数据前,使用Stop()和Close()卸载就数据。
 
 c. 控制:
 volume :GetVolume(), SetVolume(), MaxVolume() and SetVolumeRamp().
 Balance:GetBalance() and SetBalance().
 priority :SetPriority(),
 
 d. 插件
 ControllerImplementationInformationL() - 允许应用程序查询使用中的控制插件的实现信息
 CustomCommandSync() - 允许应用程序向 controller plugins发送自定义控制命令.
 RegisterForAudioLoadingNotification() - 注册接收音频剪辑加载或重新缓存通知
 GetAudioLoadingProgressL() - 获取音频剪辑加载或重新缓存进度。
 
 e。播放
 Play() :从当前位置播放音频数据,完成调用MMdaAudioPlayerCallback::MapcPlayComplete()
 SetRepeats() :同一段音频重复次数。
 Duration() :determine the duration of the audio clip in microseconds
 SetPlayWindow() and ClearPlayWindow() :设置或清除音频剪辑的起始和终结位置。
 GetPosition() and SetPosition() :音频剪辑位置。
 Pause() :暂停
 Stop() 尽快结束播放,调用回调方法MMdaAudioPlayerCallback::MapcPlayComplete(). 如果已经播放完成,
 此方法什么也不做.
 Close() 关闭所有相关的控制器。

85. UIQ中使用CreateWindowL()时需要调用CCoeControl::SetParent().否则出现Qikon-panic,27的错.
    参见RequestFocusL的定义
    When focus is set on a control, care must be taken so that the whole control chain gets its focus set.
 That means that all parents to the control should also set their focus to ETrue . This applies even if
 they are nonfocusing controls.

86. s60中使用浏览器打开文件或网址:(S60 2nd Ed FP 3: BrowserEngine.lib WebKit.lib )
 CBrCtlInterface::LoadUrl(_L("file://sample1.jpg"))
 CBrCtlInterface::LoadUrl(_L("file://sample2.jif"))
 CBrCtlInterface::LoadUrl(_L("file://sample3.mp3"))
 CBrCtlInterface::LoadUrl(_L("file://sample4.3gp"))
 
87. 使用系统工具打开指定的而文件:
   1. RApaLsSession ls;
   ls.Connect();
   TThreadId threadId;
   ls.StartDocument( iAttachFile, threadId );
   ls.Close();
   2. CApaCommandLine * cmd = CApaCommandLine::NewL();       
   cmd->SetLibraryNameL( m_pCurrentAppPath );       
   cmd->SetDocumentNameL( m_pCurrentFilePath );
   cmd->SetCommandL( EApaCommandOpen );

   EikDll::StartAppL( *cmd );
   delete cmd;

88. HandlePointerEventL,父容器调用子容器的HandlePointerEventL。

89. EStdDeviceKeyFourWayDown与EDeviceKeyFourWayDown
 EStdDeviceKeyFourWayDown(EStdKeyDevice5)对应于TKeyEvent.iScanCode。
 EDeviceKeyFourWayDown(EKeyDevice5)对应于TKeyEvent.iCode。
 KeyUp和KeyDown时iScanCode为0。
 
90. 手动添加菜单:
 CQikCommand* q = CQikCommand::NewLC(EAppCmdSortAltType1);
    q->SetType(EQikCommandTypeScreen);
    q->SetPriority(EAppCmdSortType1Priority);
    q->SetGroupId(EAppCmdSortGroup);
    q->SetIcon(KMbmFile, EMbmCommands1Icon0, EMbmCommands1Icon0mask);
    iEikonEnv->ReadResourceL(bb,R_STR_SORT_TYPE1);
    q->SetTextL(bb);
    q->SetHandler(this);
    cm.InsertCommandL(*this,q);
    CleanupStack::Pop(q);

91. Active延迟执行程序,可替换计时器。
 void CActivityManager::RunL()
 {
  if (iStatus == KErrNone)  
   iObserver->ActiveEvent(iState);
 }

 void CActivityManager::SetEvent(TInt aEvent)
 {
  if (!IsActive())  
  {  
   TRequestStatus* status=(&iStatus);
   SetActive(); // 等待 
   User::RequestComplete(status, KErrNone); // 完成
   iState = aEvent;
  }
 }
 
92 窗体透明:
 1. http://developer.uiq.com/forum/thread.jspa?threadID=551&tstart=0
 void CMyControl::ConstructL(const TRect& aRect)
 {
 // create a semi-transparent window
 CreateWindowL();
 SetRect(aRect);
 Window().SetRequiredDisplayMode(EColor16MA);
 TRgb backgroundColour = KRgbRed; // for example
 if(KErrNone == Window().SetTransparencyAlphaChannel())
  {
  backgroundColour.SetAlpha(0);
  }
 Window().SetBackgroundColor(backgroundColour);
 // other construction code here
 ...
 // and finish construction
 ActivateL();
 }

 2. http://developer.uiq.com/forum/thread.jspa?threadID=521&tstart=0
 void CMyControl::ConstructL(const TRect& aRect)
 {
 // create a bitmap to use as a mask for the window
 iWindowMask = new(ELeave) CFbsBitmap;
 User::LeaveIfError(iWindowMask->Create(aRect.Size(),EGray256));
 // create a semi-transparent window
 CreateWindowL();
 SetRect(aRect);
 if(KErrNone == Window().SetTransparencyBitmap(*iWindowMask))
  {
  // we now have a semi-transparent window,
  // so make the mask look interesting
  CFbsDevice* maskDev = CFbsBitmapDevice::NewL(bitmap);
  CleanupStack::PushL(maskDev);
  CFbsBitGc* maskGc = CFbsBitGc::NewL();
  CleanupStack::PushL(maskGc);
  maskGc->Activate(maskDev);
  maskGc->... // whatever
  CleanupStack::PopAndDestroy(maskGc);
  CleanupStack::PopAndDestroy(maskDev);
  }
 else
  {
  // creating a semi-transparent window failed; tidy up now
  // we still have a window though, it's just opaque.
  delete iWindowMask;
  iWindowMask = NULL;
  // set the background colour, or whatnot...?
  }
 // other construction code here
 ...
 // and finish construction
 ActivateL();
 }
 
 3. http://developer.uiq.com/forum/thread.jspa?threadID=520&tstart=0
 TRgb backgroundColour = KRgbRed;
 backgroundColour.SetAlpha(0x80); // now 50% transparent
        gc.SetBrushColor(backgroundColour);
 gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
 gc.Clear(Rect());
 ...

94. 改变Gcce优化级别:
 In the SDK, find the file epoc32/tools/compilation_config/GCCE.mk and edit it with a text editor.
 REL_OPTIMISATION=
 改变为;
 REL_OPTIMISATION= -O2 -fno-unit-at-a-time
 出现"undefined reference to `typeinfo for MTmTextLayoutForwarder'“添加"LIBRARY form.lib tagma.lib".

95. 后台App获取pen事件:
 CQikAppUi::IgnorePointerEventsWhenInBackground(EFalse);

96. 替换Cba:
 if (aShow)
 {
  iCtrlCba = CEikButtonGroupContainer::NewL(
   CEikButtonGroupContainer::ECba,
   CEikButtonGroupContainer::EHorizontal,
   this, R_AVKON_SOFTKEYS_SELECT_CANCEL, *this);
 }
 else
 {
  delete iCtrlCba;
  iCtrlCba = NULL;
 }

97. 画字符串:
 TInt baseLine = rect.Height()/2 + font->AscentInPixel()/2;
 gc.UseFont(font);
 gc.DrawText(*helloworld, rect, baseLine);
 gc.DiscardFont();
 
98. 获得控件的屏幕坐标
 TRect rcCtrl(Rect());
 rcCtrl.Move(Window().AbsPosition()); // 得到屏幕坐标

 或者直接使用PositionRelativeToScreen();在uiq2也管用

99. 修改模拟器字体
 Copy elocl.29 (for Traditional Chinese Taiwan) or elocl.31 (for Simplified Chinese)
 from epoc32/release/winscw/udeb to epoc32/release/winscw/udeb/z/sys/bin
 修改使用的语言:
 (Control panel -> Device -> Select Language).

 以上在UIQ3中使用,对于s60v3:
 将windows中的字体拷贝到system的fonts目录,删除原来的

100 . 绘制动画图片  S60 3rd Edition
 应用程序可以通过ICL(Image Converter Library)使用CImageDecoder类在自定义的UI控件中绘制动画图片,比如GIF动画图片。
 ICL允许使用CImageDecoder::Convert()将动画图片(多帧)转换为CFbsBitmap位图机型显示,
 我们可以通过使用CImageDecoder::FrameCount()获得图片文件的帧数,通过CImageDecoder::FrameInfo(TInt aFrameNumber = 0)
 返回每帧的信息.对每帧来说都要调用CImageDecoder::Convert(),这个转换是异步的。每次完成后,完成后将返回一个CFbsBitmap实例。
 帧之间的时间间隔可以通过TFrameInfo类获得,通过这些信息,我们可以依次播放CFbsBitmap以产生动画效果。

 注意:在S60 2nd中可以使用CPAlbImageViewerBasic来播放动画,但在第三版中已经去除了。
 
101. 进程枚举
 bool CheckIfCameraAppIsRunning(){
 
  bool mCameraFound = false;
 
  TBuf<32> KProcess (KUidCameraApp);
  KProcess.UpperCase();
  TFindProcess processFinder(_L("*"));
  TFullName currentProcess;
  while (processFinder.Next(currentProcess) == KErrNone) {
   currentProcess.UpperCase();
   if ((currentProcess.Find(KProcess) != KErrNotFound))
                 {
    mCameraFound = true;
    break;
   }
  }
  return mCameraFound;
 }

 进程检测:
 const TUid KUidCamera = {0x102013F3};
 TApaTaskList tlist(iCoeEnv->WsSession());
 TApaTask task = tlist.FindApp(KUidCamera);
 if(task.Exists())
  {
  _LIT(KRunning, "The Camera is running");
  iEikonEnv->InfoMsg(KRunning);
  }

102. UIQ3中使用Building block,输入框的fep能够显示标题:
 QIK_SLOT_CONTENT
     {
     slot_id = EQikItemSlot1;
     //unique_handle = ESimpleDialogLabel;
     caption = STRING_r_card_savedlg_save_caption; // 此处起作用
     },
 QIK_SLOT_CONTENT
     {
     slot_id = EQikItemSlot2;
     caption = STRING_r_card_savedialog_prompt;  // 不起作用
     unique_handle = ESimpleDialogEdwin;
     }

103.  枚举系统可用字体:
 void CFvModel::ConstructL()
 {
  TTypefaceSupport *typeface;
  iFontCount = iCoeEnv->ScreenDevice()->NumTypefaces();
  for( TInt i=0;i<iFontCount;i++)
  {
  typeface = new TTypefaceSupport;
  User::LeaveIfNull(typeface);
  iCoeEnv->ScreenDevice()->TypefaceSupport(*typeface,i);
  User::LeaveIfError(iFont.Append(typeface));
  }
 }

104. 关于Symbian平台路径问题:(s60)
    a.取得程序下的文件的绝对路径

 #include <AknUtils.h>
 TFileName pathname(_L("data.dat")) ;
 CompleteWithAppPath (pathname) ;
    b. 根目录: PathInfo::PhoneMemoryRootPath()
 存储图片文件目录: PathInfo::ImagesPath()
 存储安装SIS文件目录: PathInfo::InstallsPath()
 存储声音文件目录: PathInfo::SoundsPath()
 MMC卡这种外加的存储器:PathInfo::MemoryCardRootPath();

105. Symbian OS v9上信息摘要算法的实现(MD5/SHA1)
    void GetMsgDigestByMd5L( TDes8 &aDest, const TDesC8 &aSrc )
 {
       _LIT8( KDigestFormat, "%02x" );
       aDest.Zero();

       CMD5 *md5 = CMD5::NewL();
       CleanupStack ::PushL( md5 );
 
       TPtrC8 ptrHash = md5->Hash( aSrc );
 
       for( TInt i=0; i < ptrHash.Length(); i++ )
       {
              aDest.AppendFormat( KDigestFormat, ptrHash[i] );
       }
 
       CleanupStack::PopAndDestroy( md5 );
 }

106.  图片格式转换:
        使用第二个参数可以转换出掩码图片实现背景透明等功能。
 virtual void CMdaImageDataReadUtility::ConvertL(CFbsBitmap& aBitmap,
  CFbsBitmap& aMaskBitmap,TInt aFrameNumber = 0);
 virtual void CImageDecoder::Convert(TRequestStatus *aRequestStatus,
  CFbsBitmap &aDestination, CFbsBitmap &aDestinationMask, TInt aFrameNumber=0);

原创粉丝点击