创建博客 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

尐鬼じ☆ve伱

和你在一起的日子

 
 
 

日志

 
 

symbian Console下创建窗口  

2011-11-11 10:09:40|  分类: symbian 菜单 控 |  标签: |举报 |字号 订阅

#include <gdi.h> // CFont
#include <w32std.h> //RWindowGroup, CWsScreenDevice, CWindowGc
_LIT(KtxHelloThere,"Hi there !");
_LIT(KFontArial,"Arial");

class CWindowDrawer : public CActive
    {
public:
    static CWindowDrawer* NewL(void);
    static CWindowDrawer* NewLC(void);
    ~CWindowDrawer();
protected:
    void DoCancel();
    void RunL();
private:
    CWindowDrawer();
    void ConstructL(void);
    void Draw(void);
private:
    RWsSession             iWsSession;
    CWindowGc*             iWindowGc;
    CWsScreenDevice*     iScreenDevice;
    RWindowGroup         iWindowGroup;
    RWindow             iWindow;
    CFont*                iMyFont;//字体
    
    CFbsBitmap*        iBitmap ;
    CFbsBitmap*        iBitmapMask ;
    
    };
======================================================================================================

#include <apgwgnam.h> //CApaWindowGroupName
#include "WindowDrawer.h"
#include <coedef.h> //for ECoeWinPriorityAlwaysAtFront


#include "chat.mbg"
#include <eikenv.h>



_LIT(KMBMFilePath,"\\resource\\apps\\chat.mbm");

CWindowDrawer* CWindowDrawer::NewL()
    {
    CWindowDrawer* self = CWindowDrawer::NewLC();
    CleanupStack::Pop(self);
    return self;
    }
CWindowDrawer* CWindowDrawer::NewLC()
    {
    CWindowDrawer* self = new (ELeave) CWindowDrawer();
    CleanupStack::PushL(self);
    self->ConstructL();
    return self;
    }
// the active object priority should be relatively low
CWindowDrawer::CWindowDrawer(void):CActive(EPriorityLow)
    {

    }
CWindowDrawer::~CWindowDrawer()
    {
    Cancel();
    if(iMyFont)
        {
        iScreenDevice->ReleaseFont(iMyFont);
        iMyFont = NULL;
        }
    delete iWindowGc;
    iWindowGc = NULL;
    delete iScreenDevice;
    iScreenDevice = NULL;
    iWindow.Close();
    iWindowGroup.Close();
    iWsSession.Close();
    }


void CWindowDrawer::ConstructL(void)
    {
    CActiveScheduler::Add(this);
    User::LeaveIfError(iWsSession.Connect());

    iScreenDevice=new (ELeave) CWsScreenDevice(iWsSession);
    User::LeaveIfError(iScreenDevice->Construct());
    User::LeaveIfError(iScreenDevice->CreateContext(iWindowGc));

    TFontSpec MyeFontSpec (KFontArial, 12*15);//设定字体
    MyeFontSpec.iTypeface.SetIsProportional(ETrue);
    User::LeaveIfError(iScreenDevice->GetNearestFontInTwips(iMyFont,MyeFontSpec));

    iWindowGroup=RWindowGroup(iWsSession);
    User::LeaveIfError(iWindowGroup.Construct((TUint32)&iWindowGroup, EFalse));
    //    iWindowGroup.SetOrdinalPosition(0,ECoeWinPriorityNormal);
    iWindowGroup.SetOrdinalPosition(-1,ECoeWinPriorityAlwaysAtFront);
    iWindowGroup.EnableReceiptOfFocus(ETrue);
    CApaWindowGroupName* winGroupName=CApaWindowGroupName::NewLC(iWsSession);
    winGroupName->SetHidden(ETrue);   
    winGroupName->SetWindowGroupName(iWindowGroup);
    CleanupStack::PopAndDestroy();
    iWindow=RWindow(iWsSession);
    User::LeaveIfError(iWindow.Construct(iWindowGroup, (TUint32)&iWindow));
    TPixelsTwipsAndRotation SizeAndRotation;
    iScreenDevice->GetDefaultScreenSizeAndRotation(SizeAndRotation);
    iWindow.SetPointerCapture(EFalse);
    const TInt KPointerFilterBitsAllClear = 1;
    iWindow.PointerFilter(EPointerFilterDrag|EPointerFilterEnterExit, KPointerFilterBitsAllClear);
    iWindow.Activate();
    iWindow.SetExtent(TPoint(20,20),TSize(200,200));
    iWindow.PointerFilter(EPointerFilterDrag|EPointerFilterEnterExit, KPointerFilterBitsAllClear);

    //    iWindow.SetOrdinalPosition(0,ECoeWinPriorityNormal);
//    iWindow.SetOrdinalPosition(-1, ECoeWinPriorityAlwaysAtFront);
    //设置透明
    iWindow.SetRequiredDisplayMode(EColor16MA);   
        TRgb backgroundColour = KRgbYellow; // for example   
        if(KErrNone == iWindow.SetTransparencyAlphaChannel())       
            {
            // we now have a semi-transparent window,
            // so we have to not clear the window region in an       
            // opaque colour before drawing it each time;
            // 0 alpha is completely transparent,
            // 255 alpha is completely opaque
            backgroundColour.SetAlpha(0);
            }
        iWindow.SetBackgroundColor(backgroundColour);// end by chen
    iWindow.SetNonFading(ETrue);
    iWindow.SetVisible(ETrue);
    iBitmap = CEikonEnv::Static()->CreateBitmapL(KMBMFilePath,EMbmChat1);
    iBitmapMask = CEikonEnv::Static()->CreateBitmapL(KMBMFilePath,EMbmChat1mask);
    Draw();
    iWsSession.RedrawReady(&iStatus);
    SetActive();
    }
void CWindowDrawer::RunL()
    {
    if (iStatus != KErrCancel)
        {
        TWsRedrawEvent e;
        iWsSession.GetRedraw(e);
        // if Windows Server does not want a redraw the window handle is 0
        if (e.Handle() != 0)
            {
            // draw our only window   
            Draw();
            }
        iWsSession.RedrawReady(&iStatus);
        SetActive();
        }
    }
void CWindowDrawer::Draw(void)
    {
    iWindowGc->Activate(iWindow);
    TRect DrwRect(TPoint(0,0), iWindow.Size());
    iWindow.Invalidate(DrwRect);
    iWindow.BeginRedraw();
    iWindowGc->Clear(DrwRect);
    if(iMyFont)
        {
        iWindowGc->BitBltMasked(TPoint(40,80),iBitmap,TRect(TPoint(0,0),iBitmap->SizeInPixels()),iBitmapMask,EFalse);
  //      iWindowGc->UseFont(iMyFont);
//        TInt StartY ((DrwRect.Height() - iMyFont->HeightInPixels()) / 2);
//        iWindowGc->DrawText(KtxHelloThere,TRect(0,StartY,DrwRect.Width(),(StartY +     iMyFont->HeightInPixels())),iMyFont->AscentInPixels(), CGraphicsContext::ECenter, 0);
        }
    iWindow.EndRedraw();
    iWindowGc->Deactivate();
    iWsSession.Flush();
    }
void CWindowDrawer::DoCancel()
    {
    iWsSession.RedrawReadyCancel();
    }
  评论这张
 
阅读(134)| 评论(0)
|      
推荐 转载

历史上的今天

最近读者

热度

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2014