資源簡介
代碼中主要是對列表控件、組合框控件、滑塊控件的自繪,以及對不是很常用的link控件的用法的演示。其中的亮點之一是列表框的滾動條的自繪,自繪時不用滾動條直接畫在列表控件上,不需要將滾動條作為另外的窗口,這是比較有亮點的,目前還沒有看到有代碼采用這種方法的。程序在win7和XP上顯示都正常。

代碼片段和文件信息
//?Log.cpp:?implementation?of?the?Log?class.
//
//////////////////////////////////////////////////////////////////////
#include?“stdafx.h“
#include?“Log.h“
//////////////////////////////////////////////////////////////////////
//?Construction/Destruction
//////////////////////////////////////////////////////////////////////
#pragma?warning(disable:4996)
//#if?(defined(_UNICODE)?||?defined(_MBCS))
//#error?Cannot?compile?with?multibyte/wide?character?support
//#endif
const?int?Log::ToDebug???=??1;
const?int?Log::ToFile????=??2;
const?int?Log::ToConsole?=??4;
const?static?int?LINE_BUFFER_SIZE?=?1024;
Log::Log(int?mode?int?level?char?*filename?bool?append)
{
m_lastLogTime?=?0;
m_filename?=?NULL;
m_append?=?false;
????hlogfile?=?NULL;
????m_todebug?=?false;
????m_toconsole?=?false;
????m_tofile?=?false;
????SetFile(filename?append);
????SetMode(mode);
SetLevel(level);
//?If?the?compiler?returns?full?path?names?in?__FILE__
//?remember?the?path?prefix?to?remove?it?from?the?log?messages.
char?*path?=?__FILE__;
char?*ptr?=?strrchr(path?‘\\‘);
if?(ptr?!=?NULL)?{
m_prefix_len?=?ptr?+?1?-?path;
m_prefix?=?(char?*)malloc(m_prefix_len?+?1);
memcpy(m_prefix?path?m_prefix_len);
m_prefix[m_prefix_len]?=?‘\0‘;
}
}
void?Log::SetMode(int?mode)?{
????
m_mode?=?mode;
????if?(mode?&?ToDebug)
????????m_todebug?=?true;
????else
????????m_todebug?=?false;
????if?(mode?&?ToFile)??{
if?(!m_tofile)
OpenFile();
}?else?{
CloseFile();
????????m_tofile?=?false;
????}
????
????if?(mode?&?ToConsole)?{
????????if?(!m_toconsole)
????????????AllocConsole();
????????m_toconsole?=?true;
????}?else?{
????????m_toconsole?=?false;
????}
}
int?Log::GetMode()?{
return?m_mode;
}
void?Log::SetLevel(int?level)?{
????m_level?=?level;
}
int?Log::GetLevel()?{
return?m_level;
}
void?Log::Setstyle(int?style)?{
m_style?=?style;
}
int?Log::Getstyle()?{
return?m_style;
}
void?Log::SetFile(const?char?*filename?bool?append)
{
CloseFile();
if?(m_filename?!=?NULL)
free(m_filename);
m_filename?=?strdup(filename);
m_append?=?append;
if?(m_tofile)
OpenFile();
}
void?Log::OpenFile()
{
//?Is?there?a?file-name?
if?(m_filename?==?NULL)
{
????????m_todebug?=?true;
????????m_tofile?=?false;
????????Print(0?“Error?opening?log?file\n“);
return;
}
????m_tofile??=?true;
m_lastLogTime?=?0;
//?If?there‘s?an?existing?log?and?we‘re?not?appending?then?move?it
if?(!m_append)
{
//?Build?the?backup?filename
char?*backupfilename?=?new?char[strlen(m_filename)+5];
if?(backupfilename)
{
strcpy(backupfilename?m_filename);
strcat(backupfilename?“.bak“);
//?Attempt?the?move?and?replace?any?existing?backup
//?Note?that?failure?is?silent?-?where?would?we?log?a?message?to??;)
DeleteFileA(backupfilename);
MoveFileA(m_filename?backupfilename);
delete?[]?backupfilename;
}
}
????//?If?filen
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
????..A..H.?????37888??2013-01-31?11:25??test068SliderAndListctrlUI.suo
?????文件????4422992??2011-06-11?01:58??Release\mfc100u.dll
?????文件?????421200??2011-06-11?01:58??Release\msvcp100.dll
?????文件?????773968??2011-06-11?01:58??Release\msvcr100.dll
?????文件???????3856??2013-01-14?17:53??Release\Skin\(old)cb_dropped.bmp
?????文件???????1256??2013-01-06?14:09??Release\Skin\(old)sl_left.bmp
?????文件???????1256??2013-01-06?14:08??Release\Skin\(old)sl_mid.bmp
?????文件???????1256??2013-01-06?14:08??Release\Skin\(old)sl_readychannel.bmp
?????文件???????1256??2013-01-06?14:10??Release\Skin\(old)sl_right.bmp
?????文件???????3856??2013-01-06?14:05??Release\Skin\(old)sl_thumbon.bmp
?????文件???????3856??2013-01-06?14:06??Release\Skin\(old)sl_thumbunon.bmp
?????文件???????3856??2013-01-15?10:19??Release\Skin\cb_dropped.bmp
?????文件???????3856??2013-01-14?17:53??Release\Skin\cb_undropped.bmp
?????文件???????1256??2013-01-10?14:08??Release\Skin\li_downarrow.bmp
?????文件???????1256??2013-01-10?14:08??Release\Skin\li_downarrow_1.bmp
?????文件????????356??2013-01-10?14:26??Release\Skin\li_thumbbottom.bmp
?????文件????????356??2013-01-10?14:26??Release\Skin\li_thumbbottom_1.bmp
?????文件????????656??2013-01-10?14:29??Release\Skin\li_thumbmid.bmp
?????文件????????356??2013-01-10?14:25??Release\Skin\li_thumbmidbk.bmp
?????文件????????356??2013-01-10?14:25??Release\Skin\li_thumbmidbk_1.bmp
?????文件????????656??2013-01-10?14:29??Release\Skin\li_thumbmid_1.bmp
?????文件????????356??2013-01-10?14:25??Release\Skin\li_thumbtop.bmp
?????文件????????356??2013-01-10?14:25??Release\Skin\li_thumbtop_1.bmp
?????文件???????1256??2013-01-10?14:08??Release\Skin\li_uparrow.bmp
?????文件???????1256??2013-01-10?14:09??Release\Skin\li_uparrow_1.bmp
?????文件???????1016??2013-01-06?15:30??Release\Skin\sl1_left.bmp
?????文件???????1016??2013-01-06?15:29??Release\Skin\sl1_mid.bmp
?????文件???????1016??2013-01-06?15:30??Release\Skin\sl1_right.bmp
?????文件???????1976??2013-01-06?15:32??Release\Skin\sl1_thumbon.bmp
?????文件???????1976??2013-01-06?15:31??Release\Skin\sl1_thumbunon.bmp
............此處省略52個文件信息
評論
共有 條評論