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();
}
评论这张
转发至微博
转发至微博
0人 |
分享到:
阅读(64)|
评论()|
转载 (0)
|举报
评论