×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Dec 2009
    Posts
    49

    Displaying_controls_in_Symbian_exe_programs

    I want to use ScrollBar in this sample,so i do this things as follow
    1.Create ScrollBar in
    void CMyControl::ConstructL(const TRect& aRect)

    iListBox->CreateScrollBarFrameL();
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

    2.override this function in Class CMyControl

    TInt CountComponentControls() const;
    CCoeControl* ComponentControl(TInt aIndex) const;
    TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) ;

    3.add CMyControl object to UI ,which is create by myself

    // Create a basic UI and set control to receive events
    CMyAppUi* appUi = new(ELeave) CMyAppUi;
    appUi->AddToStackL( ctrl) ;
    coeEnv->SetAppUi(appUi); // takes ownership

    it shows right ,but when i press down Arrow , it has no response.
    in debug ,i found that it have call
    return iListBox->OfferKeyEventL(aKeyEvent, aType);

    besides ,with the same code ,i have done it well in a App project !

    Thank you!
    }

  2. #2
    Super Contributor
    Join Date
    Mar 2004
    Location
    Singapore
    Posts
    9,968

    Re: Displaying_controls_in_Symbian_exe_programs

    1. make sure you have focused your control and
    2. show your complete OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )

  3. #3
    Registered User
    Join Date
    Dec 2009
    Posts
    49

    Re: Displaying_controls_in_Symbian_exe_programs

    Quote Originally Posted by skumar_rao View Post
    1. make sure you have focused your control and
    2. show your complete OfferKeyEventL( const TKeyEvent& aKeyEvent, TEventCode aType )
    Now i change some code

    1.

    #ifndef CMYCONTROL_H_
    #define CMYCONTROL_H_
    #include <eiktxlbx.h> // CEikTextListBox
    #include <coecntrl.h> // CCoeControl
    #include <eiktxlbx.h>
    #include <aknlists.h>
    class CMyControl : public CCoeControl,MCoeControlObserver,MEikListBoxObserver{
    public:
    void ConstructL(const TRect& aRect);
    ~CMyControl();
    private:

    void SizeChanged();
    TInt CountComponentControls() const;
    CCoeControl* ComponentControl(TInt aIndex) const;
    void Draw(const TRect& aRect) const;
    TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) ;
    void HandleControlEventL( CCoeControl* aControl,TCoeEvent aEventType );

    void HandleListBoxEventL( CEikListBox* /*aListBox */,
    TListBoxEvent aEventType );
    private:
    //CEikLabel* iLabel ;


    //CEikTextListBox* iListBox;
    CAknSingleStyleListBox* iListBox ;
    };
    #endif /* CMYCONTROL_H_ */


    -------------------------------------------
    2.

    #include "CMyControl.h"
    #include <eiktxlbm.h>


    void CMyControl::ConstructL(const TRect& aRect)
    {
    CreateWindowL(); // You may use CAknSingleStyleListBox, etc for Series 60..

    iListBox = new(ELeave) CAknSingleStyleListBox ;
    iListBox->SetContainerWindowL(*this);
    // iListBox->SetMopParent(this);
    iListBox->ConstructL(this, EAknListBoxSelectionList|EAknListBoxLoopScrolling) ;
    iListBox->SetFocus(ETrue);
    iListBox->CreateScrollBarFrameL(ETrue);

    iListBox->SetRect( aRect) ;
    iListBox->SetExtent(TPoint( 0 , 0 ) ,iListBox->MinimumSize() ) ;

    //\t%S\t\t
    CDesCArray* List = static_cast<CDesCArray*>(iListBox->Model()->ItemTextArray()) ;
    List->Reset() ;
    HBufC* bf = HBufC::New(50) ;
    TPtr ptr = bf->Des() ;

    for( TInt i =0 ; i< 3 ; i++ )
    {
    ptr.Zero() ;
    ptr.Copy( _L("dfdf")) ;
    ptr.Insert(0 , _L("\t ")) ;
    List->AppendL( ptr) ;
    }

    //iColumnListBox->ItemDrawer()->ColumnData()->SetAlignmentL(CGraphicsContext::ECenter ) ;

    iListBox->HandleItemAdditionL();

    iListBox->DrawNow();
    SetRect(aRect);
    ActivateL();
    }
    CMyControl::~CMyControl()
    { delete iListBox;}
    void CMyControl::SizeChanged()
    { iListBox->SetRect(Rect());}

    TInt CMyControl::CountComponentControls() const
    { return 1;}
    CCoeControl* CMyControl::ComponentControl(TInt aIndex) const{
    switch (aIndex)
    {
    case 0:
    return iListBox;
    default:

    return 0;
    }
    }

    void CMyControl:raw(const TRect& aRect) const{
    CWindowGc& gc = SystemGc();
    gc.Clear(aRect);
    }

    TKeyResponse CMyControl::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType)
    {

    return iListBox->OfferKeyEventL(aKeyEvent, aType);
    }

    //
    void CMyControl::HandleControlEventL(
    CCoeControl* /*Control*/,TCoeEvent /*aEventType*/)
    {
    }


    void CMyControl::HandleListBoxEventL( CEikListBox* /*aListBox */,
    TListBoxEvent aEventType )
    {
    switch( aEventType )
    {
    case EEventEnterKeyPressed: // Flow through
    case EEventItemClicked:
    //EditContactDlgL();
    iListBox->DrawNow();
    break;
    default:
    break;
    }
    }


    -------------------------------------------------------------

    class CMyAppUi : public CEikAppUi//CCoeAppUi
    {
    public:

    void ConstructL();
    CMyAppUi();
    virtual ~CMyAppUi();
    // unhide base function
    using CEikAppUi::HandleWsEventL;
    };

    void CMyAppUi::ConstructL()
    {
    //BaseConstructL(ENoAppResourceFile) ;
    BaseConstructL( ENoAppResourceFile | ENoScreenFurniture );
    CEikonEnv::Static()->SetSystem( ETrue );
    }

    CMyAppUi::CMyAppUi(){}

    CMyAppUi::~CMyAppUi(){}

    -------------------------------------------------------------
    LOCAL_C void ExeMainL()
    {

    //coe->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);

    CCoeEnv* coe = CCoeEnv::Static();

    CCoeEnv::Static()->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
    CMyControl* ctrl = new(ELeave) CMyControl;
    CleanupStack::PushL(ctrl);
    ctrl->ConstructL(TRect(0, 0, screenWidth, screenHeight));
    ctrl->DrawNow();
    CCoeEnv::Static()->WsSession().Flush();

    //Create a basic UI and set constrol to receive events

    CMyAppUi* appUi = new(ELeave) CMyAppUi;
    //appUi->SetCustomControl(&ctrl) ;
    //appUi->SetRootControl(ctrl);
    appUi->ConstructL();
    appUi->AddToStackL( ctrl) ;
    coe->SetAppUi(appUi) ;


    for (; { // Wait synchronously for event
    TRequestStatus status;
    coe->WsSession().EventReady(&status);
    User::WaitForRequest(status);
    if (status.Int() == KErrNone)
    {
    TWsEvent event;
    coe->WsSession().GetEvent(event);
    // Check exit key
    if (event.Key()->iCode == EKeyDevice3)
    break;
    // Pass event to control
    appUi->HandleWsEventL(event, ctrl);
    }
    }


    CleanupStack::PopAndDestroy(ctrl);

    }


    GLDEF_C TInt E32Main()
    {

    // Create cleanup stack
    __UHEAP_MARK;
    CTrapCleanup* cleanup = CTrapCleanup::New();


    CEikonEnv* coe = new CEikonEnv;
    TRAPD(err, coe->ConstructL());
    __ASSERT_ALWAYS(!err, User::Panic(_L("EXECTRL"), err));

    coe->RootWin().SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);

    TRAPD(error, ExeMainL());
    __ASSERT_ALWAYS(!error, User::Panic(_L("EXECTRL"), error));
    User::After(10*1000*1000);
    //CEikonEnv::Static()->RootWin().SetOrdinalPosition(-1, ECoeWinPriorityNeverAtFront);

    //delete coe;

    delete cleanup;
    __UHEAP_MARKEND;

    return 0 ;



    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •