Help me please ! Problem with "DrawText" ! Thanks very much!
| Tue, 2005-09-13 04:08 | |
|
Hi all !
I use function "DrawText" to diplay text on screen but It doesn't appear.Please help me!Thanks very much! ----------------------------------View1Container.cpp----------------------------- void CTopmenuContainer::ViewTopmenu() { CWindowGc& gc = SystemGc(); gc.UseFont( iCoeEnv->NormalFont() ); gc.SetPenColor( 0xFFFFFF ); gc.SetBrushStyle( CWindowGc::ESolidBrush ); _LIT( iText,"Hello" ); gc.DrawText( iText,TPoint( 50,90 ) ); } -------------------------- doctinh113114 ! Please help me! Thanks very much ---------------------- |
|






Forum posts: 165
Forum posts: 107
I try to draw in Draw function but it still doesn't appear. Help me plesase !Thanks very much
Forum posts: 128
i think the mistake is that you are not setting the font. it is very important to set the font.
try this code, it worked for me
//in void CMyContainer::Draw(const TRect& aRect) const
CWindowGc& gc = SystemGc();
gc.Clear();
const CFont* normalFont = iEikonEnv->NormalFont();
const TInt KColorRed=35;
TRgb colorRed=AKN_LAF_COLOR(KColorRed);
TPoint textPoint(10,10);
_LIT(text,"ss");
gc.UseFont(normalFont);
gc.SetPenColor(colorRed);
gc.DrawText(text,textPoint);
gc.DiscardFont()
bye
Forum posts: 107
Text appears when I add your code in hellowold of SDK but in my example it doesn't . I don't know what error ?please help me! thanks very much!( in my example, I use multiview and CTimer )
Forum posts: 128
see i am also using it in multiviews, container1
r u getting some error message, if yes, post the error
and also post sample code of what u r doing
it will be easy to diagnose then
bye
Forum posts: 107
----------------------------------------------------------------- My code ---------------------------------------------------------------------------
#include "TrainAppUi.h"
#include "TopmenuContainer.h"
#include "TOPMENU.mbg"
#include "BitmapMethods.h"
#include "Train.hrh"
CTopmenuContainer* CTopmenuContainer::NewL(const TRect& aRect)
{
  CTopmenuContainer* self = CTopmenuContainer::NewLC(aRect);
  CleanupStack::Pop(self);
  return self;
}
CTopmenuContainer* CTopmenuContainer::NewLC(const TRect& aRect)
{
  CTopmenuContainer* self = new (ELeave) CTopmenuContainer;
  CleanupStack::PushL(self);
  self->ConstructL(aRect);
  return self;
}
void CTopmenuContainer::ConstructL(const TRect& aRect)
{
  CreateWindowL();
  SetRect(aRect);
  // Load background in the bitmap images from the multi bitmap file
  iTopmenu_BackgroundImage = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                        EMbmTopmenuBackground );
  //----- Load all trains in the multibitmap
  iTopmenu_LeftImage1 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuLeft_image1 );
  iTopmenu_LeftImage2 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuLeft_image2 );
  iTopmenu_LeftImage3 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuLeft_image3 );
  iTopmenu_LeftImage4 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuLeft_image4 );
  iTopmenu_RightImage1 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuRight_image1 );
  iTopmenu_RightImage2 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuRight_image2 );
  iTopmenu_RightImage3 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuRight_image3 );
  iTopmenu_RightImage4 = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuRight_image4 );
  iTopmenu_LeftRightmask = iEikonEnv->CreateBitmapL( KTopmenuFilename,
                   EMbmTopmenuLeftright_mask );
  // Create the off screen bitmap and device / gc
  iOffScreenBitmap    = NBitmapMethods::CreateBitmapL( Rect().Size(),KColourDepth );
  iOffScreenBitmapDevice = NBitmapMethods::CreateBitmapDeviceL( *iOffScreenBitmap );
  iOffScreenBitmapGc   = NBitmapMethods::CreateGraphicsContextL( *iOffScreenBitmapDevice );
  // Ham khoi tao thoi gian
  iPeriodicTimer = CPeriodic::NewL( CActive::EPriorityStandard );
  //----- Get value to Flag_Train
  iFlag_Train = 1;
  //----- Get value to Flag_Text
  iFlag_Text = 1;
  //SetUpSpritesL();
  ActivateL();
}
void CTopmenuContainer::ViewTopmenu()
{
  // Call function display image
  CWindowGc &gc = SystemGc();
  gc.Activate( *DrawableWindow() );
  // Blit the background image onto the off screen bitmap
  //   at the top left position
  //iOffScreenBitmapGc->BitBlt( TPoint( 0,0 ),iTopmenu_BackgroundImage );
  //----- Output Train on topmenu
  switch( iFlag_Train )
  {
   case 1 :
   {
     NBitmapMethods::BitBltMaskedEntireBitmap
        ( *iOffScreenBitmapGc,TPoint(0,0),
             *iTopmenu_LeftImage1,*iTopmenu_LeftRightmask );
     NBitmapMethods::BitBltMaskedEntireBitmap
        ( *iOffScreenBitmapGc,TPoint(152,0),
              *iTopmenu_RightImage1,*iTopmenu_LeftRightmask );
     iFlag_Train = 2;
   } break;
   case 2 :
   {
     NBitmapMethods::BitBltMaskedEntireBitmap
         ( *iOffScreenBitmapGc,TPoint(0,0),
             *iTopmenu_LeftImage2,*iTopmenu_LeftRightmask );
     NBitmapMethods::BitBltMaskedEntireBitmap
          ( *iOffScreenBitmapGc,TPoint(152,0),
              *iTopmenu_RightImage2,*iTopmenu_LeftRightmask );
    iFlag_Train = 3;
   } break;
   case 3 :
   {
     NBitmapMethods::BitBltMaskedEntireBitmap
         ( *iOffScreenBitmapGc,TPoint(0,0),
             *iTopmenu_LeftImage3,*iTopmenu_LeftRightmask );
     NBitmapMethods::BitBltMaskedEntireBitmap
         ( *iOffScreenBitmapGc,TPoint(152,0),
             *iTopmenu_RightImage3,*iTopmenu_LeftRightmask );
    iFlag_Train = 4;
   } break;
   case 4 :
   {
    NBitmapMethods::BitBltMaskedEntireBitmap
         ( *iOffScreenBitmapGc,TPoint(0,0),
            *iTopmenu_LeftImage4,*iTopmenu_LeftRightmask );
    NBitmapMethods::BitBltMaskedEntireBitmap
        ( *iOffScreenBitmapGc,TPoint(152,0),
            *iTopmenu_RightImage4,*iTopmenu_LeftRightmask );
    iFlag_Train = 1;
   } break;
  }
  //----- Output Text on topmenu --------------------------Doesn't appear
  switch( iFlag_Text )
  {
    case 1:
    {
      /* gc.UseFont(iCoeEnv->NormalFont());
      gc.SetPenColor(0xFFFFFF);
      gc.SetBrushStyle(CWindowGc::ESolidBrush);
      _LIT( iText,"Hello Huynh Quoc Thang" );
      gc.DrawText( iText,TPoint(50,90));*/
      // Get smallest possible arial font
      _LIT(KMyFontName,"Arial");
      CFont* myFont;
      TFontSpec myFontSpec(KMyFontName,1);
      CGraphicsDevice* screenDevice = iCoeEnv->ScreenDevice();
      screenDevice->GetNearestFontInTwips(myFont,myFontSpec);
      // Use new font
      gc.UseFont(myFont);
      // Draw some text
      _LIT(KMyText,"My text Huynh Quoc Thang");
      gc.DrawText(KMyText, TPoint(40, 40) );
      // Discard and release the font
      gc.DiscardFont();
      screenDevice->ReleaseFont(myFont);
    } break;
  }
  // Blit the offscreen image onto the screen at the top left position
  gc.BitBlt( Rect().iTl,iOffScreenBitmap );
  gc.Deactivate();
}
TInt CTopmenuContainer::Period(TAny* aPtr)
{
  ( static_cast<CTopmenuContainer*>( aPtr ) )->ViewTopmenu();
  //Returning a value of TRUE indicates the callback should be done again
  return TRUE;
}
void CTopmenuContainer::Display_Topmenu()
{
  // If the timer is not already running, start it
  if ( !iPeriodicTimer->IsActive() )
  {
    iPeriodicTimer->Start( 1,1000,
        TCallBack(CTopmenuContainer::Period, this ) );
  }
}
void CTopmenuContainer::Draw(const TRect& aRect) const
{
  //----- Display background into screen
  Display_Topmenu();
}
CTopmenuContainer::CTopmenuContainer()
{
}
CTopmenuContainer::~CTopmenuContainer()
{
  if ( iPeriodicTimer )
  {
    // Stop the periodic timer
    iPeriodicTimer->Cancel();
  }
  delete iPeriodicTimer;
  iPeriodicTimer = NULL;
  delete iOffScreenBitmapGc;
  iOffScreenBitmapGc = NULL;
  delete iOffScreenBitmapDevice;
  iOffScreenBitmapDevice = NULL;
  delete iOffScreenBitmap;
  iOffScreenBitmap = NULL;
  delete iTopmenu_BackgroundImage;
  iTopmenu_BackgroundImage = NULL;
  delete iTopmenu_LeftImage1;
  iTopmenu_LeftImage1 = NULL;
  delete iTopmenu_LeftImage2;
  iTopmenu_LeftImage2 = NULL;
  delete iTopmenu_LeftImage3;
  iTopmenu_LeftImage3 = NULL;
  delete iTopmenu_LeftImage4;
  iTopmenu_LeftImage4 = NULL;
  delete iTopmenu_LeftRightmask;
  iTopmenu_LeftRightmask = NULL;
  delete iTopmenu_RightImage1;
  iTopmenu_RightImage1 = NULL;
  delete iTopmenu_RightImage2;
  iTopmenu_RightImage2 = NULL;
  delete iTopmenu_RightImage3;
  iTopmenu_RightImage3 = NULL;
  delete iTopmenu_RightImage4;
  iTopmenu_RightImage4 = NULL;
}
TKeyResponse CTopmenuContainer::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
  switch( aKeyEvent.iScanCode)
  {
    case 164:
    {
       ((CTrainAppUi*)(ControlEnv()->AppUi()))->ActivateLocalViewL(TUid::Uid(iWelcomescreenID));
    } break;
  }
}
Forum posts: 165
void CTopmenuContainer::ViewTopmenu() codes inside
void CTopmenuContainer::Draw(const TRect& aRect) const....