实现原理:

1.后台开线程遍历目录,遍历出一个文件路径在界面上更新显示(通过发消息通知主界面)

2.需要扩展一下Duilib控件,在此我扩展了CLabelUI,重写了PaintText函数

扩展控件的.h文件

 /*************************************************************************************************
*
* File Name : UILabelEx.h
*
* Created : 2016/11/11
*
* Author : http://www.cnblogs.com/chechen/
*
* Model :
*
* Description : [[CN]] 扩展Label控件 [[CN]]
*
**************************************************************************************************/
#ifndef _UILABELEX_H_
#define _UILABELEX_H_ class CLabelExUI : public CLabelUI
{
public:
CLabelExUI(void);
~CLabelExUI(void); LPCTSTR GetClass() const;
LPVOID GetInterface(LPCTSTR pstrName); void PaintText(HDC hDC);
void SetPos(RECT rc); private:
Color _MakeRGB(int a, Color cl);
Color _MakeRGB(int r, int g, int b);
};
#endif//_UILABELEX_H_

.cpp

 #include "StdAfx.h"
#include "UILabelEx.h" CLabelExUI::CLabelExUI(void)
{
} CLabelExUI::~CLabelExUI(void)
{
} LPCTSTR CLabelExUI::GetClass() const
{
return TEXT("LabelExUI");
} LPVOID CLabelExUI::GetInterface(LPCTSTR pstrName)
{
if( _tcscmp(pstrName, TEXT("LabelEx")) == ) return static_cast<CLabelExUI*>(this);
return CLabelUI::GetInterface(pstrName);
} Color CLabelExUI::_MakeRGB(int a, Color cl)
{
return Color(a, cl.GetR(), cl.GetG(), cl.GetB());
} Color CLabelExUI::_MakeRGB(int r, int g, int b)
{
return Color(, r, g, b);
} void CLabelExUI::SetPos(RECT rc)
{
__super::SetPos(rc);
} void CLabelExUI::PaintText(HDC hDC)
{
if( m_dwTextColor == ) m_dwTextColor = m_pManager->GetDefaultFontColor();
if( m_dwDisabledTextColor == ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor(); RECT rc = m_rcItem;
rc.left += m_rcTextPadding.left;
rc.right -= m_rcTextPadding.right;
rc.top += m_rcTextPadding.top;
rc.bottom -= m_rcTextPadding.bottom; if(!GetEnabledEffect())
{
if( m_sText.IsEmpty() ) return;
int nLinks = ;
if( IsEnabled() ) {
if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor,
NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
else
{
ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
::SetBkMode(hDC, TRANSPARENT);
::SetTextColor(hDC, RGB(GetBValue(m_dwTextColor), GetGValue(m_dwTextColor), GetRValue(m_dwTextColor)));
HFONT hOldFont = (HFONT)::SelectObject(hDC, m_pManager->GetFont(m_iFont)); SIZE size;
::GetTextExtentPoint32(hDC,m_sText.GetData(),m_sText.GetLength(),&size); UINT uStyle = ;
if(size.cx > rc.right - rc.left)
{
uStyle = DT_PATH_ELLIPSIS|DT_WORD_ELLIPSIS|DT_END_ELLIPSIS;
}
else
{
uStyle = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
}
::DrawText(hDC, m_sText, -, &rc, uStyle | DT_NOPREFIX);
::SelectObject(hDC, hOldFont);
}
}
else {
if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor,
NULL, NULL, nLinks, DT_SINGLELINE | m_uTextStyle);
else {
ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
::SetBkMode(hDC, TRANSPARENT);
::SetTextColor(hDC, RGB(GetBValue(m_dwTextColor), GetGValue(m_dwTextColor), GetRValue(m_dwTextColor)));
HFONT hOldFont = (HFONT)::SelectObject(hDC, m_pManager->GetFont(m_iFont)); SIZE size;
::GetTextExtentPoint32(hDC,m_sText.GetData(),m_sText.GetLength(),&size); UINT uStyle = ;
if(size.cx > rc.right - rc.left)
{
uStyle = DT_PATH_ELLIPSIS|DT_WORD_ELLIPSIS|DT_END_ELLIPSIS;
}
else
{
uStyle = DT_CENTER | DT_VCENTER | DT_SINGLELINE;
}
::DrawText(hDC, m_sText, -, &rc, uStyle | DT_NOPREFIX);
::SelectObject(hDC, hOldFont); //CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor,
//m_iFont, /* DT_SINGLELINE | */m_uTextStyle); ///< @todo
} }
}
else
{
Font nFont(hDC,m_pManager->GetFont(GetFont())); Graphics nGraphics(hDC);
nGraphics.SetTextRenderingHint(m_TextRenderingHintAntiAlias); StringFormat format;
format.SetAlignment((StringAlignment)m_hAlign);
format.SetLineAlignment((StringAlignment)m_vAlign); RectF nRc((float)rc.left,(float)rc.top,(float)rc.right-rc.left,(float)rc.bottom-rc.top);
RectF nShadowRc = nRc;
nShadowRc.X += m_ShadowOffset.X;
nShadowRc.Y += m_ShadowOffset.Y; int nGradientLength = GetGradientLength(); if(nGradientLength == )
nGradientLength = (rc.bottom-rc.top); LinearGradientBrush nLineGrBrushA(Point(GetGradientAngle(), ),Point(,nGradientLength),_MakeRGB(GetTransShadow(),GetTextShadowColorA()),_MakeRGB(GetTransShadow1(),GetTextShadowColorB() == -?GetTextShadowColorA():GetTextShadowColorB()));
LinearGradientBrush nLineGrBrushB(Point(GetGradientAngle(), ),Point(,nGradientLength),_MakeRGB(GetTransText(),GetTextColor()),_MakeRGB(GetTransText1(),GetTextColor1() == -?GetTextColor():GetTextColor1())); if(GetEnabledStroke() && GetStrokeColor() > )
{
LinearGradientBrush nLineGrBrushStroke(Point(GetGradientAngle(),),Point(,rc.bottom-rc.top+),_MakeRGB(GetTransStroke(),GetStrokeColor()),_MakeRGB(GetTransStroke(),GetStrokeColor())); #ifdef _UNICODE
nRc.Offset(-,);
nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(,);
nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(-,-);
nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(,);
nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(,-);
#else
USES_CONVERSION;
wstring mTextValue = A2W(m_TextValue.GetData()); nRc.Offset(-,);
nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(,);
nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(-,-);
nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(,);
nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushStroke);
nRc.Offset(,-);
#endif }
#ifdef _UNICODE
if(GetEnabledShadow() && (GetTextShadowColorA() > || GetTextShadowColorB() > ))
nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nShadowRc,&format,&nLineGrBrushA); nGraphics.DrawString(m_TextValue,m_TextValue.GetLength(),&nFont,nRc,&format,&nLineGrBrushB);
#else
USES_CONVERSION;
wstring mTextValue = A2W(m_TextValue.GetData()); if(GetEnabledShadow() && (GetTextShadowColorA() > || GetTextShadowColorB() > ))
nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nShadowRc,&format,&nLineGrBrushA); nGraphics.DrawString(mTextValue.c_str(),mTextValue.length(),&nFont,nRc,&format,&nLineGrBrushB);
#endif }
}

转载:http://blog.csdn.net/chenlycly/article/details/24294639

参考QQ的效果,如下所示:

DT_END_ELLIPSIS:对于显示的字符串,如果结束的字符串的范围不在矩形内,它会被截断并以省略号标识。

DT_WORDBREAK:当一行中的字符将会延伸到由lpRect指定的矩形的边框时,此行自动地在字之间换行。

DT_WORD_ELLIPSIS:截短不符合矩形的正文,并增加省略号。

DT_PATH_ELLIPSIS:对于显示的字符串,会用省略号替换字符串中间的字符,以确保结果能在矩形范围内。 如果该字符串包含反斜杠(\)字符,它会尽可能的保留最后一个反斜杠之后的正文。

xml文件:

 <?xml version="1.0" encoding="UTF-8"?>
<Window size="750,500" caption="0,0,0,60" sizebox="0,0,0,0" roundcorner="4,4">
<!-- 窗口的初始尺寸(宽500,高350) 标题栏拖拽区域(高32)、可拖拽边框大小(这里添加sizebox后就可以拖拽边框调整大小了) -->
<Font name="微软雅黑" size="13"/>
<Font name="微软雅黑" size="16" />
<Font name="微软雅黑" size="16" bold="true"/>
<Font name="微软雅黑" size="13" underline="true"/>
<Font name="宋体" size="13" />
<Font name="微软雅黑" size="13" /> <VerticalLayout bkcolor="#FFCCCCCC" bordersize="2" bordercolor="#FFE5DED8" >
<!-- 整个窗口的背景色 -->
<!-- 标题栏区 -->
<HorizontalLayout name="appbar" height="28" bkcolor="#FF13A8E0">
<Control width="100"/>
<HorizontalLayout name="apptitle" >
<Label text="DuiLibTraverseFolderDemo http://www.cnblogs.com/chechen/" align="center" textcolor="#FFF5F6F7"/>
</HorizontalLayout>
<Button name="minbtn" padding="4,0,0,0" width="24" height="24" tooltip="最小化" normalimage="file='sysbtn/Min.png'" hotimage="file='sysbtn/Min_hot.png'"/>
<Button name="maxbtn" padding="4,0,0,0" width="24" height="24" tooltip="最大化" normalimage="file='sysbtn/Max.png'" hotimage="file='sysbtn/Max_hot.png'"/>
<Button name="restorebtn" padding="4,0,0,0" width="24" height="24" tooltip="还原" visible="false" normalimage="file='sysbtn/Restore.png'" hotimage="file='sysbtn/Restore_hot.png'"/>
<Button name="closebtn" padding="4,0,0,0" width="24" height="24" tooltip="关闭" normalimage="file='sysbtn/Close.png'" hotimage="file='sysbtn/Close_hot.png'"/>
</HorizontalLayout> <HorizontalLayout bkcolor="#FFFFFFFF"> <Label text="正在操作,请稍后..." align="center" font="2"/>
<LabelEx name="filepath" text="" float="true" pos="225,255,0,0" width="256" height="20" font="0" /> </HorizontalLayout> </VerticalLayout>
</Window>

Demo:Duilib实现类似电脑管家扫描目录效果

Duilib实现类似电脑管家扫描目录效果的更多相关文章

  1. 为什么会有可恶的腾讯电脑管家&怎么干掉它-电脑开机出现腾讯电脑管家-无法卸载腾讯电脑管家

    为什么会有可恶的腾讯电脑管家 怎么干掉它 电脑开机出现腾讯电脑管家 无法卸载腾讯电脑管家 某天,趁空闲,升级了一些常用软件,其中就升了新版电脑qq,晚上玩完电脑后关机睡觉,第二天早上开机.出现了图一: ...

  2. Java之扫描目录,修改文件内容

    扫描目录下文件,修改文件中指定内容 package org.utils.tools.fileoper; import java.io.*; import java.util.ArrayList; im ...

  3. QQMacMgr for Mac(腾讯电脑管家)安装

    1.软件简介    腾讯电脑管家是 macOS 系统上一款由腾讯公司带来到的安全管理软件.功能有垃圾清理.软件仓库.小火箭加速和防钓鱼等.而在视觉 UI 上,导入星空概念,操作过场动画全部以星空为题材 ...

  4. 自制window下core animation引擎 - demo第二弹 - 仿QQ电脑管家加速小火箭

    一年前想写一个像cocoa那样,可以方便层动画开发的引擎,写着写着又逆向它的QuartzCore.framework,也就是CoreAnimation的底层,已经大半年没有搞windows这个引擎.大 ...

  5. jquery实现章节目录效果

    <html><head><title>jquery实现章节目录效果</title> <script type="text/javascr ...

  6. PHP-递归扫描目录和删除目录

    (1) 通过递归扫描目录并打印 // php递归扫描目录 function scanMyDir($path){ // 打开目录 $dh = opendir($path); echo '<ul&g ...

  7. WPF如何实现类似iPhone界面切换的效果(转载)

    WPF如何实现类似iPhone界面切换的效果 (version .1) 转自:http://blog.csdn.net/fallincloud/article/details/6968764 在论坛上 ...

  8. Adobe Edge Animate –地球自转动画的实现,类似flash遮罩层的效果

    Adobe Edge Animate –地球自转动画的实现,类似flash遮罩层的效果 版权声明: 本文版权属于 北京联友天下科技发展有限公司. 转载的时候请注明版权和原文地址. 目前Edge的功能尚 ...

  9. TsFltMgr.sys系统蓝屏的原因就在于QQ电脑管家!

    同事一WindowsXP系统,正常执行,关闭后,第二天无法启动,详细症状为: (1)安全模式以及带网络功能的安全模式都能够进入: (2)正常模式,还没出现WindowXP滚动栏就開始重新启动: (3) ...

随机推荐

  1. 在windows7下安装CentOS

    需要用到的软件 EasyBCD 设置索引菜单 PA5.2_Portable 分区助手 WinGrub 查看硬盘代号 1.使用分区助手,腾出至少4GB的空间,并格式化为fat32格式,将CentOS的I ...

  2. Javascript算术运算

    Javascript中Math对像的一些复杂算术运算方法: Math.pow(2,53)  //2的53次幂 结果:9007199254740992 Math.round(0.6)  //0.6四舍五 ...

  3. Bootstrap css背景图片的设置

    一. 网页中添加图片的方式有两种 一种是:通过<img>标签直接插入到html中 另一种是:通过css背景属性添加 居中方法:水平居中的text-align:center 和 margin ...

  4. itertools 介绍

    在python中itertool为python提供一系列迭代iterator的方法. 第一个:组合 排列 itertools.combinations(sq, r) 该函数的作用是在列表sq中穷举所有 ...

  5. java 打开txt文件或者bat文件

    package open_exe; public class OpenExe { public static void openWinExe() { Runtime rn = Runtime.getR ...

  6. JQuery-文档处理&选择器

    <body> <div id="textDiv">...</div> <p>第一段..</p> <b>第二段 ...

  7. canvas 实现 柱状图

    define([],function(){ var myChart={ init:function(options){ this.ctx = options.ctx; this.data = opti ...

  8. Nginx下Magento伪静态规则,适用于LNMP一键包

    文件名为:magento.conf(下载),将其放在 /usr/local/nginx/conf/ 文件夹下 然后在 /usr/local/nginx/conf/vhost/www.yourname. ...

  9. ios开发xcode中设置代码块

    在开发中有很多重复的代码,很多开发者把常用的代码做成代码块提高开发效率. 在xcode里选中代码块的时候总是很不容易,点击选中的代码(文字),不要移动和松开鼠标左键,当竖线变成像拉长了的x(我也不知道 ...

  10. DevExpress中的ASPxTreeView 递归显示checknodes并获得选中值

    aspx代码 <dx:ASPxTreeView ID="ASPxTreeView1" runat="server"> </dx:ASPxTre ...