×
Namespaces

Variants
Actions

使用CAknGlobalMsgQuery显示一个全局消息查询框

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

测试基于
设备:: Nokia N93

兼容于
平台: S60 3rd Edition, FP1

文章
关键词: CAknGlobalMsgQuery, StringLoader, CAknGlobalMsgQuery::NewL(),
dougcn 在 09 Jul 2008 创建
最后由 hamishwillee 在 05 Jul 2012 编辑

Contents

概述

这个代码片段演示如何创建一个全局的消息查询框CAknGlobalMsgQuery。通过调用NewL()方法来构造一个全局查询框。需要构造一个活动对象以便处理对话框的关闭。此例使用通用类CGlobalQueryHandlerAO,这个类也用在其它全局查询代码片段中。类CGlobalQueryContainer用于调出全局查询框,它也是观察者,实现了接口MGlobalQueryObserver

此片段能用自签名。

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_header_text
{
buf = "<header text here>";
}
 
RESOURCE TBUF r_global_query_message_text
{
buf = "<message text here>";
}

头文件

  • 观察者接口
#ifndef GLOBALQUERYOBSERVER_H
#define GLOBALQUERYOBSERVER_H
 
class MGlobalQueryObserver
{
public:
// 保持这些方法短暂运行,因为在活动对象内调用。
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 <aknglobalmsgquery.h> //CAknGlobalMsgQuery
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;
CAknGlobalMsgQuery* iGlobalMsgQuery;
};
#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 message query
iQueryHandlerAO = CGlobalQueryHandlerAO::NewL(*this);
iQueryHandlerAO->StartHandler();
 
iGlobalMsgQuery = CAknGlobalMsgQuery::NewL();
HBufC* headerText = StringLoader::LoadLC(R_GLOBAL_QUERY_HEADER_TEXT);
HBufC* messageText = StringLoader::LoadLC(R_GLOBAL_QUERY_MESSAGE_TEXT);
 
//show the global message query
iGlobalMsgQuery->ShowMsgQueryL(iQueryHandlerAO->iStatus,
*messageText,
R_AVKON_SOFTKEYS_OK_CANCEL,
*headerText,
KNullDesC);
 
CleanupStack::PopAndDestroy(2); //messageText, headerText
}
 
CGlobalQueryContainer::~CGlobalQueryContainer()
{
//...
delete iQueryHandlerAO;
delete iGlobalMsgQuery;
}
 
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 5 July 2012, at 10:31.
57 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.

×