当前位置: 首页 > news >正文

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;
}

转载于:https://www.cnblogs.com/jackieron/p/6055161.html

相关文章:

  • #include
  • The content of element type configuration must match (properties?,settings?,typeAliases?,typeHa...
  • xCode8支持iOS7.0
  • C#跨窗体传值的几种方法分析(很详细)
  • 数据结构:二叉树的链式存储
  • 用正则表示式分析网页
  • iOS AFNetworking 打印从服务器返回的错误提示信息
  • Ubuntu16.04安装网易云音乐
  • OC 图片圆角实现
  • 常用设计模式之适配器
  • 加速度传感器检测物体倾角的原理
  • codeforces 734E(DFS,树的直径(最长路))
  • php-fpm服务启动脚本
  • html关于图片和链接的笔记
  • jQuery 语法
  • 【Leetcode】101. 对称二叉树
  • 【跃迁之路】【699天】程序员高效学习方法论探索系列(实验阶段456-2019.1.19)...
  • Linux各目录及每个目录的详细介绍
  • python docx文档转html页面
  • React+TypeScript入门
  • react-core-image-upload 一款轻量级图片上传裁剪插件
  • React-Native - 收藏集 - 掘金
  • session共享问题解决方案
  • SQLServer插入数据
  • 阿里云ubuntu14.04 Nginx反向代理Nodejs
  • 解决iview多表头动态更改列元素发生的错误
  • 解析带emoji和链接的聊天系统消息
  • 精彩代码 vue.js
  • 普通函数和构造函数的区别
  • 试着探索高并发下的系统架构面貌
  • 说说动画卡顿的解决方案
  • 微信小程序实战练习(仿五洲到家微信版)
  • 一些关于Rust在2019年的思考
  • 自定义函数
  • 积累各种好的链接
  • 容器镜像
  • 曾刷新两项世界纪录,腾讯优图人脸检测算法 DSFD 正式开源 ...
  • #FPGA(基础知识)
  • (12)Hive调优——count distinct去重优化
  • (C语言)fgets与fputs函数详解
  • (Redis使用系列) Springboot 整合Redisson 实现分布式锁 七
  • (Redis使用系列) SpringBoot 中对应2.0.x版本的Redis配置 一
  • (附源码)springboot家庭财务分析系统 毕业设计641323
  • (深入.Net平台的软件系统分层开发).第一章.上机练习.20170424
  • (太强大了) - Linux 性能监控、测试、优化工具
  • (一)80c52学习之旅-起始篇
  • **CI中自动类加载的用法总结
  • .NET 6 在已知拓扑路径的情况下使用 Dijkstra,A*算法搜索最短路径
  • .NET Core MongoDB数据仓储和工作单元模式封装
  • .NET成年了,然后呢?
  • .Net转Java自学之路—基础巩固篇十三(集合)
  • /usr/bin/perl:bad interpreter:No such file or directory 的解决办法
  • @GetMapping和@RequestMapping的区别
  • @property python知乎_Python3基础之:property
  • @WebServiceClient注解,wsdlLocation 可配置