×
Namespaces

Variants
Actions

获得CAknViewAppUi或CAknView的指针

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
hoolee 在 18 Jun 2008 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

CS000848


  • 开发伙伴平台:

S60 3rd Edition


  • 详细描述

下列示例帮你获得在S60 Avkon试图切换结构下CAknViewAppUi和CAknView类的引用。


源文件

如果你的程序有一个从CAknViewAppUi派生的UI类,则可以通过如下方式获得一个指向它的指针。

// Get a pointer to CAknView from CAknViewAppUi
// ESomeViewId is the view enumeration id value in your application .hrh file.
CSomeView* view = (CSomeView*)View(TUid::Uid(ESomeViewId));


如果你有至少一个从CAknView派生的类,你可以在这个类中通过如下方式获得对应用程序UI类的指针

// Get a pointer to CAknViewAppUi from CAknView
CYourAppUi* appUi = (CYourAppUi*)AppUi();


也可以从另一个view中获得某个view的指针:

// Get a pointer to CAknView from CAknView
CSomeView* view = (CSomeView*)AppUi()->View(TUid::Uid(ESomeViewId));


CAknViewAppUi和你程序运行周期一样长,因此在它这里存储引擎类(作为类成员)是很好的习惯。可以按照如下方式获得你引擎的指针:

// Get a pointer to your engine class from CAknView
CYourApplicationAppUi* appui = (CYourApplicationAppUi*)AppUi();
CYourAppEngine* engine = appui->Engine();


注意:你必须完成 CYourApplicationAppUi::Engine() 方法以便上述代码能正确执行。


通过CCoeControl类中的iEikonEnv获得指针的方法如下:

// Get the application UI from CEikonEnv
CYourApplicationAppUi* appui = (static_cast<CYourApplicationAppUi*>(iEikonEnv->AppUi()));
// Get the view you want
CSomeView* view = (CSomeView*)appui->View(TUid::Uid(ESomeViewId));
This page was last modified on 15 December 2011, at 09:46.
52 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×