#include "StdAfx.h"
#include "UIDlgBuilder.h"
/////////////////////////////////////////////////////////////////////////////////////
CStdPtrArray::CStdPtrArray(int iPreallocSize) : m_ppVoid(NULL), m_nCount(0), m_nAllocated(iPreallocSize)
{
ASSERT(iPreallocSize>=0);
if( iPreallocSize > 0 ) m_ppVoid = static_cast<LPVOID*>(malloc(iPreallocSize * sizeof(LPVOID)));
}
CStdPtrArray::~CStdPtrArray()
{
if( m_ppVoid != NULL ) free(m_ppVoid);
}
void CStdPtrArray::Empty()
{
if( m_ppVoid != NULL ) free(m_ppVoid);
m_ppVoid = NULL;
m_nCount = m_nAllocated = 0;
}
void CStdPtrArray::Resize(int iSize)
{
Empty();
m_ppVoid = static_cast<LPVOID*>(malloc(iSize * sizeof(LPVOID)));
::ZeroMemory(m_ppVoid, iSize * sizeof(LPVOID));
m_nAllocated = iSize;
m_nCount = iSize;
}
bool CStdPtrArray::IsEmpty() const
{
return m_nCount == 0;
}
bool CStdPtrArray::Add(LPVOID pData)
{
if( ++m_nCount >= m_nAllocated) {
m_nAllocated *= 2;
if( m_nAllocated == 0 ) m_nAllocated = 11;
m_ppVoid = static_cast<LPVOID*>(realloc(m_ppVoid, m_nAllocated * sizeof(LPVOID)));
if( m_ppVoid == NULL ) return false;
}
m_ppVoid[m_nCount - 1] = pData;
return true;
}
bool CStdPtrArray::InsertAt(int iIndex, LPVOID pData)
{
if( iIndex == m_nCount ) return Add(pData);
if( iIndex < 0 || iIndex > m_nCount ) return false;
if( ++m_nCount >= m_nAllocated) {
m_nAllocated *= 2;
if( m_nAllocated == 0 ) m_nAllocated = 11;
m_ppVoid = static_cast<LPVOID*>(realloc(m_ppVoid, m_nAllocated * sizeof(LPVOID)));
if( m_ppVoid == NULL ) return false;
}
memmove(&m_ppVoid[iIndex + 1], &m_ppVoid[iIndex], (m_nCount - iIndex - 1) * sizeof(LPVOID));
m_ppVoid[iIndex] = pData;
return true;
}
bool CStdPtrArray::SetAt(int iIndex, LPVOID pData)
{
if( iIndex < 0 || iIndex >= m_nCount ) return false;
m_ppVoid[iIndex] = pData;
return true;
}
bool CStdPtrArray::Remove(int iIndex)
{
if( iIndex < 0 || iIndex >= m_nCount ) return false;
if( iIndex < --m_nCount ) ::CopyMemory(m_ppVoid + iIndex, m_ppVoid + iIndex + 1, (m_nCount - iIndex) * sizeof(LPVOID));
return true;
}
int CStdPtrArray::Find(LPVOID pData) const
{
for( int i = 0; i < m_nCount; i++ ) if( m_ppVoid[i] == pData ) return i;
return -1;
}
int CStdPtrArray::GetSize() const
{
return m_nCount;
}
LPVOID* CStdPtrArray::GetData()
{
return m_ppVoid;
}
LPVOID CStdPtrArray::GetAt(int iIndex) const
{
if( iIndex < 0 || iIndex >= m_nCount ) return NULL;
return m_ppVoid[iIndex];
}
LPVOID CStdPtrArray::operator[] (int iIndex) const
{
ASSERT(iIndex>=0 && iIndex<m_nCount);
return m_ppVoid[iIndex];
}
/////////////////////////////////////////////////////////////////////////////////////
//
//
CStdString::CStdString() : m_pstr(m_szBuffer)
{
m_szBuffer[0] = '\0';
}
CStdString::CStdString(const TCHAR ch) : m_pstr(m_szBuffer)
{
m_szBuffer[0] = ch;
m_szBuffer[1] = '\0';
}
CStdString::CStdString(LPCTSTR lpsz, int nLen) : m_pstr(m_szBuffer)
{
ASSERT(!::IsBadStringPtr(lpsz,-1) || lpsz==NULL);
Assign(lpsz, nLen);
}
CStdString::CStdString(const CStdString& src) : m_pstr(m_szBuffer)
{
Assign(src.m_pstr);
}
CStdString::~CStdString()
{
if( m_pstr != m_szBuffer ) free(m_pstr);
}
int CStdString::GetLength() const
{
return (int) _tcslen(m_pstr);
}
CStdString::operator LPCTSTR() const
{
return m_pstr;
}
void CStdString::Append(LPCTSTR pstr)
{
int nNewLength = GetLength() + (int) _tcslen(pstr);
if( nNewLength >= MAX_LOCAL_STRING_LEN ) {
if( m_pstr == m_szBuffer ) {
m_pstr = static_cast<LPTSTR>(malloc((nNewLength + 1) * sizeof(TCHAR)));
_tcscpy(m_pstr, m_szBuffer);
_tcscat(m_pstr, pstr);
}
else {
m_pstr = static_cast<LPTSTR>(realloc(m_pstr, (nNewLength + 1) * sizeof(TCHAR)));
_tcscat(m_pstr, pstr);
}
}
else {
if( m_pstr != m_szBuffer ) {
free(m_pstr);
m_pstr = m_szBuffer;
}
_tcscat(m_szBuffer, pstr);
}
}
void CStdString::Assign(LPCTSTR pstr, int cchMax)
{
if( pstr == NULL ) pstr = _T("");
cchMax = (cchMax < 0 ? (int) _tcslen(pstr) : cchMax);
if( cchMax < MAX_LOCAL_STRING_LEN ) {
if( m_pstr != m_szBuffer ) {
free(m_pstr);
m_pstr = m_szBuffer;
}
}
else if( cchMax > GetLength() || m_pstr == m_szBuffer ) {
if( m_pstr == m_szBuffer ) m_pstr = NULL;
m_pstr = static_cast<LPTSTR>(realloc(m_pstr, (cchMax + 1) * sizeof(TCHAR)));
}
_tcsncpy(m_pstr, pstr, cchMax);
m_pstr[cchMax] = '\0';
}
bool CStdString::IsEmpty() const
{
return m_pstr[0] == '\0';
}
void CStdString::Empty()
{
if( m_pstr != m_szBuffer ) free(m_pstr);
m_pstr = m_szBuffer;
m_szBuffer[0] = '\0';
}
LPCTSTR CStdString::GetData()
{
return m_pstr;
}
TCHAR CStdString::GetAt(int nIndex) const
{
return m_pstr[nIndex];
}
TCHAR CStdString::operator[] (int nIndex) const
{
return m_pstr[nIndex];
}
const CStdString& CStdString::operator=(const CStdString& src)
{
Assign(src);
return *this;
}
const CStdString& CStdString::operator=(LPCTSTR lpStr)
{
ASSERT(!::IsBadStringPtr(lpStr,-1));
Assign(lpStr);
return *this;
}
#ifndef _UNICODE
const CStdString& CStdString::operator=(LPCWSTR lpwStr)
{
ASSERT(!::IsBadStringPtrW(lpwStr,-1));
int cchStr = ((int) wcslen(lpwStr) * 2) + 1;
LPSTR pstr = (LPSTR) _alloca(cchStr);
if( pstr != NULL ) ::WideCharToMultiByte(::GetACP(), 0, lpwStr, -1, pstr, cchStr, NULL, NULL);
Assign(pstr);
return *this;
}
#endif // _UNICODE
const CStdString& CStdString::operator=(const TCHAR ch)
{
Empty();
m_szBuffer[0] = ch;
m_szBuffer[1] = '\0';
return *this;
}
CStdString CStdString::operator+(const CStdString& src)
{
Append(src);
return *this;
}
CStdString CStdString::operator+(LPCTSTR lpStr)
{
ASSERT(!::IsBadStringPtr(lpStr,-1));
Append(lpStr);
return *this;
}
const CStdString& CStdString::operator+=(const CStdString& src)
{
Append(src);
return *this;
}
const CStdString& CStdString::operator+=(LPCTSTR lpStr)
{
ASSERT(!::IsBadStringPtr(lpStr,-1));
Append(lpStr);
return *this;
}
const CStdString& CStdString::operator+=(const TCHAR ch)
{
TCHAR str[] = { ch, '\0' };
Append(str);
return *this;
}
bool CStdString::operator == (LPCTSTR str) const { return (Compare(str) == 0); };
bool CStdString::operator != (LPCTSTR str) const { return (Compare(str) != 0); };
bool CStdString::operator <= (LPCTSTR str) const { return (Compare(str) <= 0); };
bool CStdString::operator < (LPCTSTR str) const { return (Compare(str) < 0); };
bool CStdString::operator >= (LPCTSTR str) const { return (Compare(str) >= 0); };
bool CStdString::operator > (LPCTSTR str) const { return (Compare(str) > 0); };
void CStdString::SetAt(int nIndex, TCHAR ch)
{
ASSERT(nIndex>=0 && nIndex<GetLength());
m_pstr[nIndex] = ch;
}
int CStdString::Compare(LPCTSTR lpsz) const
{
return _tcscmp(m_pstr, lpsz);
}
int CStdString::CompareNoCase(LPCTSTR lpsz) const
{
return _tcsicmp(m_pstr, lpsz);
}
void CStdString::MakeUpper()
{
_tcsupr(m_pstr);
}
void CStdString::MakeLower()
{
_tcslwr(m_pstr);
}
CStdString CStdString::Left(int iLength) const
{
if( iLength < 0 ) iLength = 0;
if( iLength > GetLength() ) iLength = GetLength();
return CStdString(m_pstr, iLength);
}
CStdString CStdString::Mid(int iPos, int iLength) const
{
if( iLength < 0 ) iLength = GetLength() - iPos;
if( iPos + iLength > GetLength() ) iLength = GetLength() - iPos;
if( iLength <= 0 ) return CStdString();
return CStdString(m_pstr + iPos, iLength);
}
CStdString CStdString::Right(int iLength) const
{
int iPos = GetLength() - iLength;
if( iPos < 0 ) {
iPos = 0;
iLength = GetLength();
}
return CStdString(m_pstr + iPos, iLength);
}
int CStdString::Find(TCHAR ch, int iPos /*= 0*/) const
{
ASSERT(iPos>=0 && iPos<=GetLength());
if( iPos != 0 && (iPos <
没有合适的资源?快使用搜索试试~ 我知道了~
WIN32界面开发之三:DUI雏形开发(二)
共33个文件
h:6个
cpp:5个
obj:5个
5星 · 超过95%的资源 需积分: 11 153 下载量 125 浏览量
2013-07-30
11:26:50
上传
评论 1
收藏 2.44MB RAR 举报
温馨提示
WIN32界面开发之三:DUI雏形开发(二) 对应源码,对应博客地址:http://blog.csdn.net/harvic880925/article/details/9612075,转载要标明出处哦!!!
资源推荐
资源详情
资源评论
收起资源包目录
DUIRudiment.rar (33个子文件)
DUIRudiment
DUIRudiment
Main.cpp 8KB
Base.cpp 2KB
stdafx.h 820B
Base.h 686B
UIMarkup.cpp 14KB
targetver.h 1KB
DUIRudiment.vcproj.20120402-1425.Administrator.user 1KB
DUIRudiment.vcproj 4KB
Main.h 570B
UIDlgBuilder.cpp 18KB
Debug
DUIRudiment.exe.intermediate.manifest 621B
stdafx.obj 44KB
vc90.idb 635KB
Base.obj 55KB
BuildLog.htm 7KB
DUIRudiment.exe.embed.manifest.res 728B
mt.dep 67B
Main.obj 73KB
vc90.pdb 452KB
DUIRudiment.exe.embed.manifest 663B
UIDlgBuilder.obj 187KB
UIMarkup.obj 83KB
stdafx.cpp 210B
UIDlgBuilder.h 7KB
DUIRudiment.vcproj.20120612-1003.Administrator.user 1KB
UIMarkup.h 3KB
bg.png 67KB
DUIRudiment.suo 20KB
DUIRudiment.ncb 6.48MB
Debug
DUIRudiment.pdb 1.01MB
DUIRudiment.exe 87KB
DUIRudiment.ilk 582KB
DUIRudiment.sln 899B
共 33 条
- 1
资源评论
- 沫影2014-04-11很补错的资源,正好拿来用用
- otox2017-09-17谢谢,不错,正在找
启舰
- 粉丝: 4w+
- 资源: 197
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功