#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圆形头象的更多相关文章

  1. Duilib实现圆形头像控件

    .h文件 #ifndef __UIHEADICON_H__ #define __UIHEADICON_H__ /* 名称:圆形头像控件(派生CButtonUI类) */ class CHeadUI: ...

  2. 2013 duilib入门简明教程 -- 自绘控件 (15)

        在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如 ...

  3. MFC中混合使用Duilib制作界面

    因为公司项目最近入了MFC的这个大坑,用MFC做UI做了一段时间,感觉不是很方便,开发效率有点慢. 看了c++里面做界面的类库,感觉Duilib比较符合做界面的需求,而且很多大公司也在使用Duilib ...

  4. duilib教程之duilib入门简明教程15.自绘控件

    在[2013 duilib入门简明教程 -- 复杂控件介绍 (13)]中虽然介绍了界面设计器上的所有控件,但是还有一些控件并没有被放到界面设计器上,还有一些常用控件duilib并没有提供(比如菜单控件 ...

  5. 使用DUILIB建立项目

    使用DUILIB加载XML界面 这篇主要目的就是教给大家怎样在自己的工程中加载XML界面,这是最基本的应用,对于界面控件响应啥的,我就不讲了,在大家懂了这个之后,我会给大家一个其它人写的博客,再看他的 ...

  6. DuiLib逆向分析の按钮事件定位

    目录 DuiLib逆向分析の按钮事件定位 0x00 前言 DuiLib介绍 DuiLib安装 DuiLib Hello,World! Duilib逆向分析之定位按钮事件 碎碎念 第一步:获取xml布局 ...

  7. HTTP1.1协议-RFC2616-中文版课前资料收集

    1.http rfc大致讲了什么? 2.解决了什么问题? HTTP协议描述的是发送方与接收方的通信协议 协议功能: HTTP协议(HyperText Transfer Protocol,超文本传输协议 ...

  8. HTTP1.1协议-RFC2616-中文版

    转自:http://www.cnblogs.com/k1988/archive/2010/01/12/2165683.html 说明 本文档规定了互联网社区的标准组协议,并需要讨论和建议以便更加完善. ...

  9. DuiLib 源码分析之解析xml类CMarkup & CMarkupNode 头文件

    xml使用的还是比较多的,duilib界面也是通过xml配置实现的 duilib提供了CMarkkup和CMarkupNode类解析xml,使用起来也是比较方便的,比较好奇它是怎么实现的,如果自己来写 ...

随机推荐

  1. java.io.file

    package cn.edu.tongji.cims.wade.system;     import java.io.*;     public class FileOperate {     pub ...

  2. Java获取本机ip和服务器ip

    一.获取服务器IP InetAddress addr = InetAddress.getLocalHost().getHostAddress();//获得本机IP 二.获取客户端本机IP String ...

  3. RabbitMQ消息机制广播分发

    public static void SendMessage() { var factory = new ConnectionFactory(); factory.HostName = "1 ...

  4. 解决json日期格式问题的3种方法

    这篇文章主要介绍了解决json日期格式问题的3种方法 ,需要的朋友可以参考下 开发中有时候需要从服务器端返回json格式的数据,在后台代码中如果有DateTime类型的数据使用系统自带的工具类序列化后 ...

  5. Mariadb 在centos 7下的安装配置

    安装Mariadb数据库: sudo yum install mariadb-server 启动数据库: sudo systemctl start mariadb 设置自动启动: sudo syste ...

  6. Axure 资料搜集

    Axure官方核心训练(翻译) http://www.webppd.com/thread-9347-1-1.html 原文链接:http://www.axure.com/learn 下载链接:http ...

  7. How to acquire an Android phone with locked bootloader?

    As we know that some devices come with locked bootloaders like Sony, HUAWEI, hTC...If you try to unl ...

  8. 1045 - Access denied for user 'root'@'localhost'(using password NO)解决方案

    原因为输入了不正确的密码,连接数据库时输入正确的密码即可! 另外一个原因是安装MySQL后MySQL产生了一个随机密码,而登录的时候没有将随机密码填上,解决方案见:http://www.cnblogs ...

  9. 使用二分法查找mobile文件中区号归属地

    #!/usr/bin/env python #coding:utf-8 ''' Created on 2015年12月8日 @author: DL @Description: 使用二分法查找mobil ...

  10. JAVA-系统-【2】-创建自增长的用户表

    [2]创建数据库表  用户表 自增 1.用户表结构  数据excel 表1 2.创建表 Create table A_USER( id number primary key, username ) n ...