help me please ! Problem with "OfferkeyEventL". Thanks very much !
| Wed, 2005-10-12 08:22 | |
|
Hi all !
In my example,I want to change DX , DY values when user press any key . I use "OfferkeyEventL" funcution for catching event but It didn't happen . Please help me ! What error I have ! Thanks very much ! ------------------------------------------------- My code ----------------------------------------------------- #include "MultiviewAppUi.h" #include "View01View.h" void CMultiviewAppUi::ConstructL() { CEikAppUi::ConstructL(); iView01 = CView01::NewL(ApplicationRect()); RegisterViewL(*iView01); AddToStackL(*iView01,iView01); SetDefaultViewL(*iView01); } #include "View01View.h" #include "Multiview.hrh" #include "Multiview.rsg" CView01* CView01::NewL(const TRect& aRect) { CView01* self = CView01::NewLC(aRect); CleanupStack::Pop(self); return self; } CView01* CView01::NewLC(const TRect& aRect) { CView01* self = new( ELeave ) CView01(); CleanupStack::PushL(self); self->ConstructL(aRect); return self; } CView01::CView01() { } CView01::~CView01() { } void CView01::ConstructL(const TRect& aRect) { iRect=aRect; DX=100; DY=100; CreateWindowL(); SetRect(aRect); ActivateL(); } TVwsViewId CView01::ViewId() const { return TVwsViewId( KUidQBasicApp,ViewUid() ); } TUid CView01::ViewUid() const { return iView01ID; } void CView01::Draw(const TRect& aRect) const { CWindowGc& gc = SystemGc(); TRect rect = Rect(); gc.Clear(); gc.SetPenColor( 0x3FEE50 ); gc.SetBrushColor( 0x3FEE50 ); gc.DrawRect( TRect( 10,10,DX,DY ) ); } void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId, TUid aCustomMessageId, const TDesC8& aCustomMessage) { } void CView01::ViewDeactivated() { MakeVisible(EFalse); } TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) { if(aType != EEventKey) { return EKeyWasNotConsumed; } switch(aKeyEvent.iScanCode) { //----- case user presskey next case 15: case 165: { DX=200; DY=200; } break; } } ------------------------------------------------- doctinh113114 ----------------------------------------------------------- |
|






Forum posts: 982
pirosl
Forum posts: 127
I guess the 15 and 165 are the right TStdScanCode. In the following code all the controll does not return. Check it.
TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
switch(aKeyEvent.iScanCode)
{
//----- case user presskey next
case 15:
case 165:
{
DX=200;
DY=200;
} break;
}
return EKeyWasConsumed;
}
Forum posts: 107
I'm using SDK UIQ 2.1.
----------------------------------------
RegisterViewL(*iView01);
AddToStackL(*iView01,iView01);
----------------------------------------------
Is this code to add iView01 object to stack right or wrong ? I didn't know ! Please help me ! How can I add iView01 to stack please ! Thanks very much !
Forum posts: 127
I am not familiar with UIQ development. But I guess the method call for view should be:
RegisterViewL(iView01);
AddToStackL(iView01);
Regards,
shagor
Forum posts: 107
Thanks very much ! But It didn't work . please help me !
Forum posts: 982
pirosl
Forum posts: 107
My code :
----------------------------------------------------------
CEikAppUi::ConstructL();
iView01 = CView01::NewL(ApplicationRect());
RegisterViewL(*iView01);
AddToStackL(*iView01,iView01); // = AddToStackL(*iView, iController)
SetDefaultViewL(*iView01);
-------------------------------------------------
But I can't catch keypress event by OfferkeyEvent . Please help me to correct it ! Please share me some me code or example .Thanks very much!
Forum posts: 982
Also your code
CEikAppUi::ConstructL();
iView01 = CView01::NewL(ApplicationRect());
AddToStackL(*iView01,iView01);
RegisterViewL(*iView01);
SetDefaultViewL(*iView01);
is taken from appui rigth?. It's perfectly valid
pirosl
Forum posts: 107
Yes, I get it from ...AppUi class ! This is my full code . Help me to correct it please ! Thanks very much ! Please help me Thanks!
------------------------------------------------- My code -----------------------------------------------------
#include "MultiviewAppUi.h"
#include "View01View.h"
void CMultiviewAppUi::ConstructL()
{
CEikAppUi::ConstructL();
iView01 = CView01::NewL(ApplicationRect());
RegisterViewL(*iView01);
AddToStackL(*iView01,iView01);
SetDefaultViewL(*iView01);
}
#include "View01View.h"
#include "Multiview.hrh"
#include "Multiview.rsg"
CView01* CView01::NewL(const TRect& aRect)
{
CView01* self = CView01::NewLC(aRect);
CleanupStack::Pop(self);
return self;
}
CView01* CView01::NewLC(const TRect& aRect)
{
CView01* self = new( ELeave ) CView01();
CleanupStack::PushL(self);
self->ConstructL(aRect);
return self;
}
CView01::CView01()
{
}
CView01::~CView01()
{
}
void CView01::ConstructL(const TRect& aRect)
{
iRect=aRect;
DX=100;
DY=100;
CreateWindowL();
SetRect(aRect);
ActivateL();
}
TVwsViewId CView01::ViewId() const
{
return TVwsViewId( KUidQBasicApp,ViewUid() );
}
TUid CView01::ViewUid() const
{
return iView01ID;
}
void CView01::Draw(const TRect& aRect) const
{
CWindowGc& gc = SystemGc();
TRect rect = Rect();
gc.Clear();
gc.SetPenColor( 0x3FEE50 );
gc.SetBrushColor( 0x3FEE50 );
gc.DrawRect( TRect( 10,10,DX,DY ) );
}
void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage)
{
}
void CView01::ViewDeactivated()
{
MakeVisible(EFalse);
}
TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
switch(aKeyEvent.iScanCode)
{
//----- case user presskey next
case 15:
case 165:
{
DX=200;
DY=200;
} break;
}
}
Forum posts: 982
void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage)
{
}
make
void CView01::ViewActivatedL(const TVwsViewId& aPrevViewId,
TUid aCustomMessageId, const TDesC8& aCustomMessage)
{
ActivateL();
MakeVisible( ETrue);
}
pirosl
Forum posts: 107
I thanks very much ! I correct my code the same above but It didn't work ! Please help me again ! Thanks !
Forum posts: 982
pirosl
Forum posts: 107
I change rectangle on OfferKeyEvent but It didn't work .Please help me again ! Thanks very much
-----------------------------------------------
switch(aKeyEvent.iScanCode)
{
//----- case user presskey next
case 15:
case 165:
{
//DX=200;
//DY=200;
CWindowGc& gc = SystemGc();
TRect rect = Rect();
gc.Clear();
gc.SetPenColor( 0x3FEE50 );
gc.SetBrushColor( 0x3FEE50 );
gc.DrawRect( TRect( 10,10,200,200 ) );
} break;
-----------------------------------------------------------------------------------------
Forum posts: 982
May be the function is called but your aKeyEvent.iScanCode are not the rigth ones.
Try to put smth outside the switch if you can't make a debug
pirosl
Forum posts: 107
I think "offerkeyeventL" is not called the same to you . Because I put this code for changing width and height of rectangle out of "switch" function but "offerkeyevent" doesn't do .
-------------------------------------------------
TKeyResponse CView01::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
{
if(aType != EEventKey)
{
return EKeyWasNotConsumed;
}
CWindowGc& gc = SystemGc();
TRect rect = Rect();
gc.Clear();
gc.SetPenColor( 0x3FEE50 );
gc.SetBrushColor( 0x3FEE50 );
gc.DrawRect( TRect( 10,10,100,100 ) );
return EKeyWasConsumed;
}
----------------------------------------------------------------------
Please help me again ! Thanks very much !