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,使用起来也是比较方便的,比较好奇它是怎么实现的,如果自己来写 ...
随机推荐
- linux ssh publickey登录
一.公钥认证的基本思想: 对信息的加密和解密采用不同的key,这对key分别称作private key和public key,其中,public key存放在目标服务器上,而private key为特 ...
- 基于Metronic的Bootstrap开发框架总览
基于Metronic的Bootstrap开发框架经验总结(1)-框架总览及菜单模块的处理 最近一直很多事情,博客停下来好久没写了,整理下思路,把最近研究的基于Metronic的Bootstrap开发框 ...
- 在win7下将CapsLock按键变成esc
我喜欢用vim来编辑,经常要按到esc,但是去按那个按键确实比较的远,而且CapsLock这个按键对我来说着实有些鸡肋,所以就想在win7上也能像ubuntu那样把capslock映射为esc,在网上 ...
- C语言指针变量作为函数参数
0x01 指针变量作为函数参数的作用是:将一个变量的地址传送到另一个函数中. 0x02 简单的例子:虽然都能实现功能,但意义不同. 正确的写法: #include <stdio.h> vo ...
- php工作笔记8-并发和数据类型
1.mysql在进行数据的修改时,并发情况下: $RoundsRows=$modelRounds->where("id=$roundsID and (sendMoney + $amou ...
- FireDac 的RecordCount 相关测试 记录。
unit Unit4; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System ...
- linux chmod 755
chmod是Linux下设置文件权限的命令,后面的数字表示不同用户或用户组的权限. 一般是三个数字: 第一个数字表示文件所有者的权限 第二个数字表示与文件所有者同属一个用户组的其他用户的权限 第三个数 ...
- 如何决定DCOM是否可用
如何决定DCOM是否可用
- uicollectionview registerclass vs registernib
当cell是用代码实现的时候用registerclass,当cell是用xib文件实现的时候用registernib
- C++拼接字符串
例如: 在"/data/misc/media/out.yuv"后面添加序号操作,并输出在path char path[128] = {0}; int Num=this->mN ...