Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
Expertise Level:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)

This page was last modified 08:37, 26 November 2007.

Capturing foreground events

From Forum Nokia Wiki


CFgrObserver illustrates how to capture foreground events in a background application. This implementation should work with all platform versions, but with S60 3rd Edition you need to have the SwEvent capability.

The usage is quite simple. Just implement the defined callback interface in your class and construct an instance of the CFgrObserver. Whenever a GUI application is taking focus you will get a notification through the callback functions. The aAppUid argument will have the UID of the application getting the focus.

Note that when constructing this class the aWsSession session variable should be connected. Otherwise the construction process will fail.

If you are only interested in your own application's focus changes, you could overwrite the Application user interface class' HandleForegroundEventL() method.


ForeGroundObserver.cpp

CFgrObserver* CFgrObserver::NewL(RWsSession& aWsSession,MFgrCallBack& aCallBack)
	{
	CFgrObserver* self = CFgrObserver::NewLC(aWsSession,aCallBack);
	CleanupStack::Pop(self);
	return self;
	}
 
 
CFgrObserver* CFgrObserver::NewLC(RWsSession& aWsSession,MFgrCallBack& aCallBack)
	{
	CFgrObserver* self = new (ELeave) CFgrObserver(aWsSession,aCallBack);
	CleanupStack::PushL(self);
	self->ConstructL();
	return self;
	}
 
 
CFgrObserver::CFgrObserver(RWsSession& aWsSession,MFgrCallBack& aCallBack)
:CActive(EPriorityHigh),iCallBack(aCallBack), iWsSession(aWsSession), iWg(aWsSession)
{
}
 
CFgrObserver::~CFgrObserver()
{
	Cancel();
	iWg.Close();
}
 
void CFgrObserver::ConstructL()
{
	CActiveScheduler::Add(this);
	
	User::LeaveIfError(iWg.Construct((TUint32)&iWg, EFalse));
	iWg.SetOrdinalPosition(-1);
	iWg.EnableReceiptOfFocus(EFalse);
 
	CApaWindowGroupName* wn=CApaWindowGroupName::NewLC(iWsSession);
	wn->SetHidden(ETrue);
	wn->SetWindowGroupName(iWg);
	CleanupStack::PopAndDestroy();
 
	User::LeaveIfError(iWg.EnableFocusChangeEvents());
 
	Listen();
}
 
void CFgrObserver::RunL()
{
	if (iStatus == KErrNone) 
	{
		TWsEvent e;
		iWsSession.GetEvent(e);
	}
 
	TInt wgid = iWsSession.GetFocusWindowGroup();
	
	CApaWindowGroupName* gn;
	gn = CApaWindowGroupName::NewLC(iWsSession, wgid);
 
	iCallBack.ForegroundEventL(gn->AppUid());
	
	CleanupStack::PopAndDestroy(); // gn
	
	if (iStatus != KErrCancel) 
	{
		Listen();
	}
}
 
void CFgrObserver::DoCancel()
{
	iWsSession.EventReadyCancel();
}
 
void CFgrObserver::Listen()
{
	iWsSession.EventReady(&iStatus);
	SetActive();
}

ForeGroundObserver.h

class MFgrCallBack 
{
public:
	virtual void ForegroundEventL(TUid aAppUid) = 0;
};
 
class CFgrObserver : public CActive 
{
public:
	static CFgrObserver* NewL(RWsSession& aWsSession,MFgrCallBack& aCallBack);
	static CFgrObserver* NewLC(RWsSession& aWsSession,MFgrCallBack& aCallBack);
	virtual ~CFgrObserver();
private:
	CFgrObserver(RWsSession& aWsSession,MFgrCallBack* aCallBack);
	void ConstructL();
	void RunL();
	void DoCancel();
	void Listen();
private:
	MFgrCallBack& 	iCallBack;
	RWsSession&     iWsSession;
	RWindowGroup    iWg; 
};
Related Discussions
Thread Thread Starter Forum Replies Last Post
Changing the ordinal position of an exteranl application. Shaikuny Symbian User Interface 1 2004-12-30 07:32
Capturing stdout like stdioserver nono240 Open C 0 2008-02-27 09:53
About Capture foreground key event. yql General Symbian C++ 2 2007-11-02 09:37
How to Simulate Key Events in PyS60? changhyp Python 2 2007-04-30 06:45
background program capture key input jackxie Mobile Java General 1 2006-07-03 16:26
 
Powered by MediaWiki
     
     RDF Facets:
     
     
     qfnZtypeQUqfnTypeZCommunityContentQ
     qfnZtypeQUqfnTypeZWebpageQ
     qfnZtypeQUqfnTypeZWikiContentQ
     qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX