返回> 网站首页 

symbian页面切换 小结

yoours2009-03-20 23:15:16 阅读 1239

简介一边听听音乐,一边写写文章。

 
一、工程文件结构及执行顺序
     Symbian3.cpp               程序开始的地方
     Symbian3application.cpp    程序类
     Symbian3document.cpp       文档类
     Symbian3appui.cpp          UI类
     Symbian3appview.cpp        容器类(并不是视图类,它继承CCoeControl)
 
二、页面(容器类)切换
最简单的办法是通过CCoeControl::MakeVisible()函数改变Container的可见性:   
    
  1.   在AppUi::ConstructL()里创建两个Container类的实例,并调用AddToStackL()将它们加入到Constrol   Stack中,然后隐藏暂时不显示的Container   
    
  void   CMyAppUi::ConstructL()   
          {   
          BaseConstructL();   
    
          iContainer1   =   CMyContainer1::NewL(ClientRect());   
          iContainer2   =   CMyContainer2::NewL(ClientRect());   
          AddToStackL(iContainer2);   
          AddToStackL(iContainer1);   
    
          iContainer2->MakeVisible(EFalse);   
          }   
    
  2.在接收到命令后切换两个Container的可见性   
    
  void   CMyAppUi::HandleCommandL(TInt   aCommand)   
          {   
          switch(aCommand)   
                  {   
                  case   ESwitchToContainer2:   
                          {   
                          iContainer2->MakeVisible(ETrue);   
                          iContainer1->MakeVisible(EFalse);   
                          break;   
                          }   
                  case   EEikCmdExit:   
                  case   EAknSoftkeyExit:   
                          {   
                          Exit();   
                          break;   
                          }   
                  default:   
                          {   
  //                         Panic(EHelloWorldBasicUi);   
                          break;   
                          }   
                  }   
          }   
    
  3.   在AppUi的析构函数中调用RemoveFromStackL()将两个Container从Control   Stack中移除并delete掉。   
  CMyAppUi::~CHelloWorldAppUi()   
          {   
          if   (iContainer1)   
                  {   
                  RemoveFromStack(iContainer1);   
                  delete   iContainer1;   
                  }   
          if   (iContainer2)   
                  {   
                  RemoveFromStack(iContainer2);   
                  delete   iContainer2;   
                  }                   
          }   
    
    另一个办法是一开始只创建Container1,等用到Container2时再创建Container2,并销毁Container1。
微信小程序扫码登陆

文章评论

1239人参与,0条评论