×
Namespaces

Variants
Actions

使用CAknGlobalConfirmationQuery显示一个全局确认询问框

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

文章
翻译:
hoolee
最后由 hamishwillee 在 09 Aug 2012 编辑

Contents

简介

下列代码示例演示了如何生成一个全局的确认询问框CAknGlobalConfirmationQuery:一个全局确认询问框使用NewL()方法构造,并使用ShowConfirmationQueryL()方法调用。这时将会构造一个活动对象,用来取消对话框。这个示例中使用了CGlobalQueryHandlerAO类。而CGlobalQueryContainer类用来启动询问框,也用来监控(需要完成MGlobalQueryObserver接口)

下列代码自签名即可 This snippet can be self-signed.

MMP文件

需要下列链接库:

LIBRARY cone.lib            //CEikonEnv, CCoeEnv 
LIBRARY avkon.lib //Avkon resources
LIBRARY CommonEngine.lib //StringLoader
LIBRARY euser.lib //CActive, CleanupStack


资源文件

.rss

#include <eikon.rh>
#include <avkon.rsg>
#include <avkon.rh>
 
//...
RESOURCE TBUF r_global_query_confirmation_text
{
buf = "<confirmation text here>";
}

头文件

  • 监控接口
#ifndef GLOBALQUERYOBSERVER_H
#define GLOBALQUERYOBSERVER_H
 
class MGlobalQueryObserver
{
public:
//keep these methods short running because they are called
//from within an active object
virtual void ProcessOkOptionL() = 0;
virtual void ProcessCancelOptionL() = 0;
virtual void ProcessDoneOptionL() = 0;
virtual void ProcessSelectedItemL(const TInt aItem) = 0;
};
 
#endif // GLOBALQUERYOBSERVER_H
  • 处理活动对象
#ifndef GLOBALQUERYHANDLERAO_H
#define GLOBALQUERYHANDLERAO_H
 
#include <e32base.h> //CActive
#include "GlobalQueryObserver.h"
 
class CGlobalQueryHandlerAO : public CActive
{
public:
~CGlobalQueryHandlerAO();
static CGlobalQueryHandlerAO* NewL(MGlobalQueryObserver& aObserver);
static CGlobalQueryHandlerAO* NewLC(MGlobalQueryObserver& aObserver);
public:
void StartHandler();
private:
CGlobalQueryHandlerAO(MGlobalQueryObserver& aObserver)
: CActive (EPriorityStandard), iObserver(aObserver){};
void ConstructL();
private: // from CActive
void RunL();
void DoCancel();
private: // data
MGlobalQueryObserver& iObserver;
};
#endif //GLOBALQUERYHANDLERAO_H
  • 控件/监控
#ifndef GLOBALQUERYCONTAINER_H
#define GLOBALQUERYCONTAINER_H
 
#include <coecntrl.h> // CCoeControl
#include "GlobalQueryObserver.h"
#include <aknglobalconfirmationquery.h> //CAknGlobalConfirmationQuery
class CGlobalQueryHandlerAO;
 
class CGlobalQueryContainer : public CCoeControl, MGlobalQueryObserver
{
public:
//...
void MakeExampleQueryL();
public: // from MGlobalQueryObserver
void ProcessOkOptionL();
void ProcessCancelOptionL();
void ProcessDoneOptionL(); //not used
void ProcessSelectedItemL(const TInt aItem); //not used
//...
private:
CGlobalQueryHandlerAO* iQueryHandlerAO;
CAknGlobalConfirmationQuery* iGlobalConfirmationQuery ;
};
#endif // GLOBALQUERYCONTAINER_H


源文件

  • 处理活动对象
#include "GlobalQueryHandlerAO.h"
#include <avkon.hrh> //EAknSoftkeyOk, EAknSoftkeyCancel, EAknSoftkeyDone
 
CGlobalQueryHandlerAO::~CGlobalQueryHandlerAO() { Cancel(); }
 
void CGlobalQueryHandlerAO::ConstructL()
{
CActiveScheduler::Add(this);
}
 
CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::NewLC(MGlobalQueryObserver& aObserver)
{
CGlobalQueryHandlerAO* self = new (ELeave) CGlobalQueryHandlerAO(aObserver);
CleanupStack::PushL(self);
self->ConstructL();
return self;
}
 
CGlobalQueryHandlerAO* CGlobalQueryHandlerAO::NewL(MGlobalQueryObserver& aObserver)
{
CGlobalQueryHandlerAO* self = CGlobalQueryHandlerAO::NewLC(aObserver);
CleanupStack::Pop(self);
return self;
}
 
void CGlobalQueryHandlerAO::DoCancel(){}
 
void CGlobalQueryHandlerAO::StartHandler() { SetActive(); }
 
void CGlobalQueryHandlerAO::RunL()
{
if (iStatus == EAknSoftkeyOk)
iObserver.ProcessOkOptionL();
else if(iStatus == EAknSoftkeyCancel)
iObserver.ProcessCancelOptionL();
else if(iStatus == EAknSoftkeyDone)
iObserver.ProcessDoneOptionL();
else
iObserver.ProcessSelectedItemL(iStatus.Int());
 
Cancel();
}
  • 容器/监控
#include "GlobalQueryContainer.h" //CGlobalQueryContainer
#include "GlobalQueryHandlerAO.h" //CGlobalQueryHandlerAO
#include <GlobalQuery_0xED0C36BE.rsg> //Resources
#include <StringLoader.h> // StringLoader
 
void CGlobalQueryContainer::ConstructL(const TRect& aRect)
{
CreateWindowL();
SetRect(aRect);
ActivateL();
 
MakeExampleQueryL();
}
 
void CGlobalQueryContainer::MakeExampleQueryL()
{
//start the query handler and show global confirmation query
iQueryHandlerAO = CGlobalQueryHandlerAO::NewL(*this);
iQueryHandlerAO->StartHandler();
 
iGlobalConfirmationQuery = CAknGlobalConfirmationQuery::NewL();
HBufC* confirmationText = StringLoader::LoadLC(R_GLOBAL_QUERY_CONFIRMATION_TEXT);
 
iGlobalConfirmationQuery->ShowConfirmationQueryL
(iQueryHandlerAO->iStatus,
*confirmationText,
R_AVKON_SOFTKEYS_OK_CANCEL,
R_QGN_NOTE_INFO_ANIM);
 
CleanupStack::PopAndDestroy(); //confirmationText
}
 
CGlobalQueryContainer::~CGlobalQueryContainer()
{
//...
delete iQueryHandlerAO;
delete iGlobalConfirmationQuery;
}
 
void CGlobalQueryContainer::ProcessOkOptionL()
{
//OK pressed, do something
iEikonEnv->InfoWinL(_L("OK"),_L("Pressed"));
}
void CGlobalQueryContainer::ProcessCancelOptionL()
{
//Cancel pressed, do something...
iEikonEnv->InfoWinL(_L("Cancel"),_L("Pressed"));
}
void CGlobalQueryContainer::ProcessDoneOptionL()
{
//not used
}
void CGlobalQueryContainer::ProcessSelectedItemL(const TInt /*aItem*/)
{
//not used
}

后记

示例代码演示如何生成一个全局的确认询问框,处理它的取消。并且活动对象处理了如何通知监控然后关闭。

相关链接

This page was last modified on 9 August 2012, at 09:38.
76 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.

×