DUILIB圆形头象
#ifndef __UIHEADICON_H__
#define __UIHEADICON_H__
/*
名称:圆形头像控件(派生CButtonUI类)
*/
class CHeadUI: public CButtonUI
{
public:
CHeadUI();
LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName);
void SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue);
void PaintBkImage(HDC hDC);
void SetBkImage(LPCTSTR pStrImage);
void SetDefaultBkImage(LPCTSTR pStrImage){ m_sDefaultBkImage = pStrImage; }
CDuiString GetDefaultBkImage(){ return m_sDefaultBkImage; }
void SetAutoPenColor(bool bAuto){ m_bAutoPenColor = bAuto; }
bool IsAutoPenColor() { return m_bAutoPenColor; }
void SetPenColor(DWORD dwColor){ m_dwPenColor = dwColor; }
DWORD GetPenColor(HDC hDC);
void SetPenWidth(int nPenWidth){ m_nPenWidth = nPenWidth; }
int GetPenWidth(){ return m_nPenWidth; }
bool IsHeadImageExist(LPCTSTR pStrImage);
private:
CDuiString m_sDefaultBkImage;
bool m_bAutoPenColor;
DWORD m_dwPenColor;
int m_nPenWidth;
};
#endif // __UIHEADICON_H__
#include "StdAfx.h"
#include "UIHeadIcon.h"
CHeadUI::CHeadUI()
{
m_sDefaultBkImage = _T("Head\\100_1.png");
m_bAutoPenColor = false;
m_dwPenColor = Color(255, 255, 255, 255).GetValue();
m_nPenWidth = 2;
}
LPCTSTR CHeadUI::GetClass() const
{
return _T("HeadIconUI");
}
LPVOID CHeadUI::GetInterface(LPCTSTR pstrName)
{
if( _tcscmp(pstrName, _T("HeadIcon")) == 0 ) return static_cast<CHeadUI*>(this);
return CControlUI::GetInterface(pstrName);
}
void CHeadUI::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
{
if (_tcscmp(pstrName, _T("defaultbkimage")) == 0) SetDefaultBkImage(pstrValue);
else if (_tcscmp(pstrName, _T("bkimage")) == 0) SetBkImage(pstrValue);
else if (_tcscmp(pstrName, _T("pencolor")) == 0) {
while (*pstrValue > _T('\0') && *pstrValue <= _T(' ')) pstrValue = ::CharNext(pstrValue);
if (*pstrValue == _T('#')) pstrValue = ::CharNext(pstrValue);
LPTSTR pstr = NULL;
DWORD clrColor = _tcstoul(pstrValue, &pstr, 16);
SetPenColor(clrColor);
}
else if (_tcscmp(pstrName, _T("autopencolor")) == 0) SetAutoPenColor(_tcscmp(pstrValue, _T("true")) == 0);
else if (_tcscmp(pstrName, _T("penwidth")) == 0) SetPenWidth(_ttoi(pstrValue));
else return CButtonUI::SetAttribute(pstrName, pstrValue);
}
void CHeadUI::SetBkImage(LPCTSTR pStrImage)
{
if (IsHeadImageExist(pStrImage))
{
m_sBkImage = pStrImage;
}
else
{
TCHAR tszModule[MAX_PATH + 1] = { 0 };
::GetModuleFileName(CPaintManagerUI::GetInstance(), tszModule, MAX_PATH);
CDuiString sInstancePath = tszModule;
int pos = sInstancePath.ReverseFind(_T('\\'));
if (pos >= 0) sInstancePath = sInstancePath.Left(pos + 1);
sInstancePath.Append(pStrImage);
if (IsHeadImageExist(sInstancePath))
{
m_sBkImage = sInstancePath;
}
else
{
m_sBkImage = pStrImage;
}
}
Invalidate();
}
void CHeadUI::PaintBkImage(HDC hDC)
{
//坐标
POINT pt = { m_rcItem.left, m_rcItem.top };
//大小
SIZE sz = { m_rcItem.right - m_rcItem.left, m_rcItem.bottom - m_rcItem.top };
Graphics graphics(hDC);
if (graphics.GetLastStatus() != Ok)
return;
//消除锯齿
graphics.SetSmoothingMode(SmoothingModeHighQuality);
GraphicsPath graphicspath;
if (graphicspath.GetLastStatus() != Ok)
return;
graphicspath.AddEllipse(pt.x, pt.y, sz.cx, sz.cy);
//设置裁剪圆
graphics.SetClip(&graphicspath, CombineModeReplace);
Image image(GetBkImage());
if (image.GetLastStatus() != Ok)
return;
//绘制图像
graphics.DrawImage(&image, pt.x, pt.y, sz.cx, sz.cy);
//绘制一个1像素宽度的圆形,用于消除锯齿
Pen myPen(GetPenColor(hDC), GetPenWidth());
if (myPen.GetLastStatus() != Ok)
return;
graphics.DrawEllipse(&myPen, pt.x, pt.y, sz.cx, sz.cy);
}
DWORD CHeadUI::GetPenColor(HDC hDC)
{
if (IsAutoPenColor())
{
//像素值颜色取点( pt.x + 1, pt.y + 1)的值
RECT rc = GetPos();
COLORREF color = GetPixel(hDC, rc.left + 1, rc.top + 1);
BYTE r = GetRValue(color);
BYTE g = GetGValue(color);
BYTE b = GetBValue(color);
return Color(255, r, g, b).GetValue();
}
return m_dwPenColor;
}
bool CHeadUI::IsHeadImageExist(LPCTSTR pStrImage)
{
return GetFileAttributes(pStrImage) == -1 ? false : true;
}
- <HeadIcon name="photo" bkimage="photo.png" autopencolor="true" float="true" pos="260,10,0,0" width="70" height="60"/>
CControlUI* CLoginWnd::CreateControl( LPCTSTR pstrClassName )
{
if (_tcsicmp(pstrClassName, _T("HeadIcon")) == 0)
{
return new CHeadUI;
}
return NULL;
}
DUILIB圆形头象的更多相关文章
- Duilib实现圆形头像控件
.h文件 #ifndef __UIHEADICON_H__ #define __UIHEADICON_H__ /* 名称:圆形头像控件(派生CButtonUI类) */ class CHeadUI: ...
- 2013 duilib入门简明教程 -- 自绘控件 (15)
在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如 ...
- MFC中混合使用Duilib制作界面
因为公司项目最近入了MFC的这个大坑,用MFC做UI做了一段时间,感觉不是很方便,开发效率有点慢. 看了c++里面做界面的类库,感觉Duilib比较符合做界面的需求,而且很多大公司也在使用Duilib ...
- duilib教程之duilib入门简明教程15.自绘控件
在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如菜单控件 ...
- 使用DUILIB建立项目
使用DUILIB加载XML界面 这篇主要目的就是教给大家怎样在自己的工程中加载XML界面,这是最基本的应用,对于界面控件响应啥的,我就不讲了,在大家懂了这个之后,我会给大家一个其它人写的博客,再看他的 ...
- DuiLib逆向分析の按钮事件定位
目录 DuiLib逆向分析の按钮事件定位 0x00 前言 DuiLib介绍 DuiLib安装 DuiLib Hello,World! Duilib逆向分析之定位按钮事件 碎碎念 第一步:获取xml布局 ...
- HTTP1.1协议-RFC2616-中文版课前资料收集
1.http rfc大致讲了什么? 2.解决了什么问题? HTTP协议描述的是发送方与接收方的通信协议 协议功能: HTTP协议(HyperText Transfer Protocol,超文本传输协议 ...
- HTTP1.1协议-RFC2616-中文版
转自:http://www.cnblogs.com/k1988/archive/2010/01/12/2165683.html 说明 本文档规定了互联网社区的标准组协议,并需要讨论和建议以便更加完善. ...
- DuiLib 源码分析之解析xml类CMarkup & CMarkupNode 头文件
xml使用的还是比较多的,duilib界面也是通过xml配置实现的 duilib提供了CMarkkup和CMarkupNode类解析xml,使用起来也是比较方便的,比较好奇它是怎么实现的,如果自己来写 ...
随机推荐
- Django1.7+JQuery+Ajax集成小例子
Ajax的出现让Web展现了更新的活力,基本所有的语言,都动态支持Ajax与起服务端进行通信,并在页面实现无刷新动态交互. 下面是散仙使用Django+Jquery+Ajax的方式来模拟实现了一个验证 ...
- oracle加并行参数PARALLEL
select /*+ PARALLEL(t,4) */ * from table1
- <iframe>标签自适应高度和宽度
<iframe src="index.html" id="iframepage" frameborder="0" scrolling= ...
- LR12.53—使用HP网络导游示例应用程序
本教程使用 的HP Web之旅,一个样本的基于Web的旅行社系统,向人们展示LoadRunner将如何作为负载测试解决方案.惠普网络旅游用户连接到Web服务器,搜索航班,预订机票,检查飞行路线. 虽然 ...
- js正则表达式replace里有变量的解决方法用到RegExp类
一直比较害怕使用正则表达式,貌似很深奥很复杂的样子,所以在用js操作字符串的时候,我最多使用的是replace.split.substring.indexOf等函数,这些函数有时候需要多次叠加使用,但 ...
- shell命令快捷键
在shell命令终端中,Ctrl+n相当于方向向下的方向键,Ctrl+p相当于方向向上的方向键. 在命令终端中通过它们或者方向键可以实现对历史命令的快速查找.这也是快速输入命令的技巧. 在命令 ...
- C# 加密解密文件
using System; using System.Collections.Generic; using System.Text; using System.Security.Cryptograph ...
- What's going on in background?
Did you know that mobile phone manufacturer collect your info without notifying you? Did you know yo ...
- MSSQL 查询数据库所有表的大小, 有助于删除一些没用的表
SELECT b.name AS tablename , a.rowcnt AS datacount FROM sysindexes a , sysobjects b WHERE a.id = b.i ...
- IOS 使用KBMMW 访问JAVA 服务
废话少说,如何使用KBMMW 做个过渡,使IOS 可以使用JAVA 的服务? 其实KBMMW 本身就要java service 的服务,但是为了把这个问题说清楚,我手工做一个例子. 首先,要使用JAV ...