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,使用起来也是比较方便的,比较好奇它是怎么实现的,如果自己来写 ...
随机推荐
- IIS启用兼容模式设置(win2k3—Win7)
点击添加按钮(上图),弹出下面的对话框(下图).在自定义HTTP头名处输入: X-UA-compatible 在自定义HTTP头值处输入: IE=EmulateIE7 (输入时注意不要留下空格)输入完 ...
- Oracle 常见函数
1.把数字转换为字符串:To_char(数字) 2.Oracle 拼接字符串: || ':' || select 字段1 || ':' || 字段2 from table :字段1:字段2 3. ...
- R语言向量
R语言基础:向量 心无咎 2012-04-02 13:37:00 向量(vector)1.seq():产生有规律的数列,间距省略时默认值为1. 例1:seq(10, 20, 0.5) ...
- QTP操作excel文档
对于QTP操作excel的大前提是,保证组建服务里的DCOM配置里存在 microsoft excel application ,具体的查看方式是,在运行框中输入dcomcnfg,然后会打开组件服务的 ...
- idea 小技巧
idea tomcat.debug显示如下 2.项目中java文件导入一个包下的多个文件时,idea默认超过3个时会用*代替.如果不想这样,操作如下 3.java类实现Serializable,自动生 ...
- 2016-08-16: 检测函数是否存在的C++模板
#include <iostream> struct Hello { ; } }; struct Generic {}; // SFINAE test template <typen ...
- Markdown写博客
一级目录 我接下来是不是该写二级目录了 二级目录 如果我用桌面端的Markdown会不会好很多,这个我看不到效果 听说插入表格很麻烦? 列表是这样的? 我还看不出样子 *这个是什么样子啊 引用是这样用 ...
- js back动作
history.back(-1):直接返回当前页的上一页,数据全部消息,是个新页面 history.go(-1):也是返回当前页的上一页,不过表单里的数据全部还在 history.back(0) 刷新 ...
- php中cookie技术关于跨目录调用cookie值的问题
今天做项目发现了一个奇葩错误,以cookie技术为主,反复测试发现cookie不能跨目录调用. 我在F:wamp\www\test\下面有1.php和2.php其中1.php接受2.php中setco ...
- 怎么在win7的64位旗舰版上配置coocs2d-x 3.2的android环境并且打包APK
我这用的操作系统是64位win7旗舰版打包成功. 希望有急用的能看到这篇文章,毕竟大家都是从菜鸟到大神的. 也以此证明自己的成长历程. 需要的东西有: 1.JAVA-JDK 2.Python 2.7. ...