切换两个Container的方法

最简单的办法是通过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。

你可能感兴趣的:(delete)