Symbian (console DrawText)后台程序如何在桌面上绘制文本效果
2010-03-18 20:42
453 查看
Symbian 后台程序如何在桌面上绘制文本效果
大家用过来电通的朋友都会知道.
当来电或者去电的时候.桌面上会有地区号码的文字显示.
那这种效果应该如何实现呢.
其实非常的简单,让我们今天来看看这种效果是如何实现的.
小弟最近也仿写了一个字样的效果,自我感觉还是不错的.
特在此总结一下为自己留个脚印没准其他网友也用得着.
哈哈少费话了进入正题了.
//初始化窗口
void CWindowDrawer::ConstructL(const TDesC& aArea)
{
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(0,ECoeWinPriorityAlwaysAtFront);
iWindowGroup.EnableReceiptOfFocus(EFalse);
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.Activate();
//iWindow.SetExtent(TPoint(0,0),SizeAndRotation.iPixelSize);
iWindow.SetExtent(TPoint(0,0),TSize(240,40));
iWindow.SetBackgroundColor(KRgbBlue);
// iWindow.SetOrdinalPosition(0,ECoeWinPriorityNormal);
iWindow.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
iWindow.SetNonFading(ETrue);
iWindow.SetVisible(ETrue);
SetWhere(aArea);
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()
{
iWindowGc->Activate(iWindow);
TRect DrwRect(TPoint(0,0), iWindow.Size());
iWindow.Invalidate(DrwRect);
iWindow.BeginRedraw();
iWindowGc->Clear(DrwRect);
if(iMyFont)
{
iWindowGc->UseFont(iMyFont);
TInt StartY ((DrwRect.Height() - iMyFont->HeightInPixels()) / 2);
iWindowGc->SetPenColor(TRgb(255,0,0));
if(iWhereArea != NULL)
{
iWindowGc->DrawText(iWhereArea->Des(),TRect(0,StartY,DrwRect.Width
(),(StartY + iMyFont->HeightInPixels())),iMyFont->AscentInPixels(),
CGraphicsContext::ECenter, 0);
}
else
{
iWindowGc->DrawText(_L("/x672A/x77E5/x7535/x8BDD"),TRect
(0,StartY,DrwRect.Width(),(StartY + iMyFont->HeightInPixels())),iMyFont->AscentInPixels(),
CGraphicsContext::ECenter, 0);
}
}
iWindow.EndRedraw();
iWindowGc->Deactivate();
iWsSession.Flush();
}
以上代码在N73/N95/6120c上测试通过
大家用过来电通的朋友都会知道.
当来电或者去电的时候.桌面上会有地区号码的文字显示.
那这种效果应该如何实现呢.
其实非常的简单,让我们今天来看看这种效果是如何实现的.
小弟最近也仿写了一个字样的效果,自我感觉还是不错的.
特在此总结一下为自己留个脚印没准其他网友也用得着.
哈哈少费话了进入正题了.
//初始化窗口
void CWindowDrawer::ConstructL(const TDesC& aArea)
{
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(0,ECoeWinPriorityAlwaysAtFront);
iWindowGroup.EnableReceiptOfFocus(EFalse);
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.Activate();
//iWindow.SetExtent(TPoint(0,0),SizeAndRotation.iPixelSize);
iWindow.SetExtent(TPoint(0,0),TSize(240,40));
iWindow.SetBackgroundColor(KRgbBlue);
// iWindow.SetOrdinalPosition(0,ECoeWinPriorityNormal);
iWindow.SetOrdinalPosition(0, ECoeWinPriorityAlwaysAtFront);
iWindow.SetNonFading(ETrue);
iWindow.SetVisible(ETrue);
SetWhere(aArea);
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()
{
iWindowGc->Activate(iWindow);
TRect DrwRect(TPoint(0,0), iWindow.Size());
iWindow.Invalidate(DrwRect);
iWindow.BeginRedraw();
iWindowGc->Clear(DrwRect);
if(iMyFont)
{
iWindowGc->UseFont(iMyFont);
TInt StartY ((DrwRect.Height() - iMyFont->HeightInPixels()) / 2);
iWindowGc->SetPenColor(TRgb(255,0,0));
if(iWhereArea != NULL)
{
iWindowGc->DrawText(iWhereArea->Des(),TRect(0,StartY,DrwRect.Width
(),(StartY + iMyFont->HeightInPixels())),iMyFont->AscentInPixels(),
CGraphicsContext::ECenter, 0);
}
else
{
iWindowGc->DrawText(_L("/x672A/x77E5/x7535/x8BDD"),TRect
(0,StartY,DrwRect.Width(),(StartY + iMyFont->HeightInPixels())),iMyFont->AscentInPixels(),
CGraphicsContext::ECenter, 0);
}
}
iWindow.EndRedraw();
iWindowGc->Deactivate();
iWsSession.Flush();
}
以上代码在N73/N95/6120c上测试通过
相关文章推荐
- Android 如何去除桌面上下边框暗度逐渐变暗的效果
- 如何在FastReport.Net中使用曲线绘制PDF文本
- 如何将你的linux打造成mac的桌面效果(支持Ubuntu,Debian,CentOS,Fedora,SUSE [Linux])
- Canvas的drawText绘制文本自动换行(支持设置显示最大行数)
- 【请教问题】kanzi如何实现类似安卓手机桌面滑动切换界面效果?
- Symbian自定义控件—如何实现跑马灯效果? - [symbian](转)
- Symbian中如何读入一行文本的类TFileText--SDk
- 如何绘制闪电效果
- 在毛玻璃效果上绘制文本
- Symbian中如何绘制背景图片问题
- C#的winform程序下如何实现文本编辑框(TextBox)的Hint提示文字效果
- WinAPI: DrawText - 将文本绘制到指定的矩形中
- 如何从Symbian数据库中读取长文本
- Win8系统如何设置桌面背景放映幻灯片效果
- Ubuntu从入门到精通 ubuntu如何设置和打开3D效果桌面
- Java学习笔记------如何为文本输入框设置下凹效果?
- Android 如何在Launcher的桌面滑动时添加动画效果? M
- 【UWP通用应用开发】编辑文本、绘制图形、3D透视效果及绘制时钟实战
- phpStorm如何在Console控制台执行php文本,而不是浏览器中
- WinAPI: DrawText - 将文本绘制到指定的矩形中