CText更新至V1.1.0

//========================================================================
//TITLE:
// CText更新至V1.1.0
//AUTHOR:
// norains
//DATE:
// Saturday 28-April-2007
//Environment:
// EVC4.0 + Standard SDK 4.2
// EVC4.0 + Standard SDK 5.0
//========================================================================

版本历史:
v1.0: http://blog.csdn.net/norains/archive/2007/04/17/1568429.aspx


接口和上一版本的差异:
*SetTextHeight()更名为SetPointSize()


修正的bug:
*创建字体时没有lfCharSet变量,在wince5.0中会导致文字无法对准.


增加的函数:
*SetStrikeOut(BOOL bStrikeOut) //文件中划线
*SetUnderline(BOOL bUnderline) //下划线
*SetItalic(BOOL bItalic) //斜体
*SetWeight(int iWeight) //粗细
*重载 "="操作符,下列代码功能能够正常运作:
CText a, b;
a.SetText(TEXT("TEXT"));
a.SetTextColor(RGB(0,0,255));
b = a;


基本的操作可参照版本v1.0的文章


/**/ //
// Text.h:interfacefortheCTextclass.
//
// Version:
// 1.1.0
// Data:
// 2007.04.28
/**/ //

#ifndefTEXT_H
#define TEXT_H


// ------------------------------------------------------------------
class CText
... {
public:
CText
&operator=(constCText&rhs);
voidSetStrikeOut(BOOLbStrikeOut);
voidSetUnderline(BOOLbUnderline);
voidSetItalic(BOOLbItalic);
BOOLSetWeight(
intiWeight);
voidGetPosition(RECT*prcOut);
voidSetPointSize(intiPointSize);
voidSetFormat(UINTuFormat);
voidSetBkColor(COLORREFcrColor);
voidSetTextColor(COLORREFcrColor);
BOOLSetBkMode(
intiMode);
voidDraw(HDChdc);
BOOLSetText(
constTCHAR*pszText);
voidSetPosition(constRECT*prc);
CText();
virtual~CText();
protected:
RECTm_rcWndPos;
TCHAR
*m_pszText;
ULONGm_ulSizeText;
UINTm_uFormat;
intm_iPointSize;
intm_iBkMode;
COLORREFm_crTextColor;
COLORREFm_crBkColor;
intm_iWeight;
BOOLm_bItalic;
BOOLm_bUnderline;
BOOLm_bStrikeOut;
}
;

#endif // !defined(AFX_TEXT_H__15E5AD94_9958_4AAC_A6DD_37527FC294CB__INCLUDED_)






/**/ //
// Text.cpp:implementationoftheCTextclass.
//
/**/ //

#include
" stdafx.h "
#include
" Text.h "


// --------------------------------------------------------------------
// Macrodefine
#define DEFAULT_BKMODETRANSPARENT
#define DEFAULT_TEXT_COLORRGB(0,0,0)
#define DEFAULT_BK_COLORRGB(255,255,255)
#define DEFAULT_FORMAT(DT_LEFT|DT_SINGLELINE)
#define DEFAULT_POINT_SIZE0
#define DEFAULT_WEIGHT0


#define MAX_WEIGHT1000
#define MIN_WEIGHT0
// --------------------------------------------------------------------
/**/ //
// Construction/Destruction
/**/ //

CText::CText()
... {
memset(
&m_rcWndPos,0,sizeof(m_rcWndPos));
m_pszText
=NULL;
m_ulSizeText
=0;
m_iBkMode
=DEFAULT_BKMODE;
m_crTextColor
=DEFAULT_TEXT_COLOR;
m_crBkColor
=DEFAULT_BK_COLOR;
m_uFormat
=DEFAULT_FORMAT;
m_iPointSize
=DEFAULT_POINT_SIZE;
m_iWeight
=0;
m_bItalic
=FALSE;
m_bUnderline
=FALSE;
m_bStrikeOut
=FALSE;
}


CText::
~ CText()
... {
if(m_pszText!=NULL)
...{
delete[]m_pszText;
m_pszText
=NULL;
}

}


// --------------------------------------------------------------------
// Description:
// Setthecontrolposition
//
// --------------------------------------------------------------------
void CText::SetPosition( const RECT * prc)
... {
m_rcWndPos
=*prc;
}



// --------------------------------------------------------------------
// Description:
// Setthetext.Ifyouwanttodisplaythetext,youshouldcalltheDisplay()
//
// --------------------------------------------------------------------
BOOLCText::SetText( const TCHAR * pszText)
... {
ULONGulLen
=_tcslen(pszText);

if(m_pszText==NULL)
...{
m_pszText
=newTCHAR[ulLen+1];

if(m_pszText==NULL)
...{
returnFALSE;
}


m_ulSizeText
=ulLen+1;
}

elseif(ulLen+1>m_ulSizeText)
...{
delete[]m_pszText;

m_pszText
=newTCHAR[ulLen+1];

if(m_pszText==NULL)
...{
returnFALSE;
}


m_ulSizeText
=ulLen+1;
}


_tcscpy(m_pszText,pszText);

returnTRUE;
}



// --------------------------------------------------------------------
// Description:
// Displaythetextstored.
//
// --------------------------------------------------------------------
void CText::Draw(HDChdc)
... {
COLORREFcrOldTextColor
=::SetTextColor(hdc,m_crTextColor);
COLORREFcrOldBkColor
=::SetBkColor(hdc,m_crBkColor);
intiOldMode=::SetBkMode(hdc,m_iBkMode);


LOGFONTlf
=...{0};
HFONThFontNew,hFontOld;
lf.lfQuality
=CLEARTYPE_QUALITY;
lf.lfCharSet
=DEFAULT_CHARSET;
lf.lfHeight
=-1*(m_iPointSize*GetDeviceCaps(hdc,LOGPIXELSY)/72);
lf.lfItalic
=m_bItalic;
lf.lfUnderline
=m_bUnderline;
lf.lfStrikeOut
=m_bStrikeOut;

hFontNew
=CreateFontIndirect(&lf);
hFontOld
=(HFONT)SelectObject(hdc,hFontNew);


DrawText(hdc,m_pszText,
-1,&m_rcWndPos,m_uFormat);


SelectObject(hdc,hFontOld);
DeleteObject(hFontNew);

::SetTextColor(hdc,crOldTextColor);
::SetBkColor(hdc,crOldBkColor);
::SetBkMode(hdc,iOldMode);
}



// --------------------------------------------------------------------
// Description:
// Setthebackgroundmode.
//
// Parameters:
// iMode:[in]Thevalueisjustlikeasfollow:
// OPAQUE--Backgroundisfilledwiththecurrentbackgroundcolorbeforethetext,
// hatchedbrush,orpenisdrawn.
// TRANSPARENT--Backgroundremainsuntouched.

// --------------------------------------------------------------------
BOOLCText::SetBkMode( int iMode)
... {
if(iMode==OPAQUE||iMode==TRANSPARENT)
...{
m_iBkMode
=iMode;
returnTRUE;
}

else
...{
returnFALSE;
}

}



// --------------------------------------------------------------------
// Description:
// Setthetextcolor
//
// --------------------------------------------------------------------
void CText::SetTextColor(COLORREFcrColor)
... {
m_crTextColor
=crColor;
}



// --------------------------------------------------------------------
// Description:
// Setthebackgroundcolor
//
// --------------------------------------------------------------------
void CText::SetBkColor(COLORREFcrColor)
... {
m_crBkColor
=crColor;
}


// --------------------------------------------------------------------
// Description:
// SetFormat.
//
// Parameters:
// ThevalueyoushouldseetheuFormatofDrawText()
// --------------------------------------------------------------------
void CText::SetFormat(UINTuFormat)
... {
m_uFormat
=uFormat;
}



// --------------------------------------------------------------------
// Description:
// Setthepointsizeoftext
//
// ---------------------------------------------------------------------
void CText::SetPointSize( int iPointSize)
... {
m_iPointSize
=iPointSize;
}



// --------------------------------------------------------------------
// Description:
// Getthepositionasrect
//
// ---------------------------------------------------------------------
void CText::GetPosition(RECT * prcOut)
... {
*prcOut=m_rcWndPos;
}



// --------------------------------------------------------------------
// Description:
// Specifiestheweightofthefontintherange0through1000.Forexample,
// 400isnormaland700isbold.Ifthisvalueiszero,adefaultweightisused.
//
// ---------------------------------------------------------------------
BOOLCText::SetWeight( int iWeight)
... {
if(iWeight<MIN_WEIGHT||iWeight>MAX_WEIGHT)
...{
returnFALSE;
}


m_iWeight
=iWeight;

returnTRUE;
}




// --------------------------------------------------------------------
// Description:
// Settheitalic
//
// ---------------------------------------------------------------------
void CText::SetItalic(BOOLbItalic)
... {
m_bItalic
=bItalic;
}




// --------------------------------------------------------------------
// Description:
// Settheunderline
//
// ---------------------------------------------------------------------
void CText::SetUnderline(BOOLbUnderline)
... {
m_bUnderline
=bUnderline;
}



// --------------------------------------------------------------------
// Description:
// SetthestrikeOut
//
// ---------------------------------------------------------------------
void CText::SetStrikeOut(BOOLbStrikeOut)
... {
m_bStrikeOut
=bStrikeOut;
}


// --------------------------------------------------------------------
// Description:
// Overloadtheoperator"="
//
// ---------------------------------------------------------------------
CText & CText:: operator = ( const CText & rhs)
... {
if(this==&rhs)
...{
return*this;
}


this->m_bItalic=rhs.m_bItalic;
this->m_bStrikeOut=rhs.m_bStrikeOut;
this->m_bUnderline=rhs.m_bUnderline;
this->m_crBkColor=rhs.m_crBkColor;
this->m_crTextColor=rhs.m_crTextColor;
this->m_iBkMode=rhs.m_iBkMode;
this->m_iPointSize=rhs.m_iPointSize;
this->m_iWeight=rhs.m_iWeight;
this->m_rcWndPos=rhs.m_rcWndPos;
this->m_uFormat=rhs.m_uFormat;
this->m_ulSizeText=rhs.m_ulSizeText;

if(this->m_pszText!=NULL)
...{
delete[]
this->m_pszText;
}

this->m_pszText=newTCHAR[_tcslen(rhs.m_pszText)+1];
_tcscpy(
this->m_pszText,rhs.m_pszText);


return*this;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
改正下面C#的代码错误public partial class Form7 : Form { private BigInteger p, q, n, phi_n, e, d; public Form7() { InitializeComponent(); } private void Form7_Load(object sender, EventArgs e) { GenerateKeys(); } private void GenerateKeys() { // 选择两个质数p和q string string1, string2; Int64 n, p, q, phi_n, e; p = BigInteger.Parse("12347534159895123"); q = BigInteger.Parse( "987654321357159852"); n = p * q; phi_n = (p - 1) * (q - 1); // 选择e并计算d e = 65537; d = ModInverse(e, phi_n); publicKeyTextBox.Text = $"{n} {e}"; privateKeyTextBox.Text = $"{n} {d}"; } private BigInteger ModInverse(BigInteger e, long phi_n) { throw new NotImplementedException(); } // 加密函数 private string Encrypt(string message, BigInteger n, BigInteger e) { BigInteger m = StrToBig(message); BigInteger c = BigInteger.ModPow(m, e, n); return BigToStr(c); } // 解密函数 private string Decrypt(string ctext, BigInteger n, BigInteger d) { BigInteger c = StrToBig(ctext); BigInteger m = BigInteger.ModPow(c, d, n); return BigToStr(m); } // 字符串转换为大整数 private BigInteger StrToBig(string str) { byte[] bytes = System.Text.Encoding.Unicode.GetBytes(str); return new BigInteger(bytes); } // 大整数转换为字符串 private string BigToStr(BigInteger big) { byte[] bytes = big.ToByteArray(); return System.Text.Encoding.Unicode.GetString(bytes); } // 计算模反元素 private BigInteger ModInverse(BigInteger a, BigInteger m) { BigInteger x, y; ExtendedGCD(a, m, out x, out y); return x; } // 扩展欧几里得算法 private void ExtendedGCD(BigInteger a, BigInteger b, out BigInteger x, out BigInteger y) { if (b == 0) { x = 1; y = 0; } else { ExtendedGCD(b, a % b, out y, out x); y -= a / b * x; } } private void encryptButton_Click(object sender, EventArgs e) { string message = inputTextBox.Text; string ctext = Encrypt(message, n, e); outputTextBox.Text = ctext; } private void decryptButton_Click(object sender, EventArgs e) { string ctext = outputTextBox.Text; string message = Decrypt(ctext, n, d); outputTextBox.Text = message; } } }
06-12
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
SQLAlchemy 是一个 SQL 工具包和对象关系映射(ORM)库,用于 Python 编程语言。它提供了一个高级的 SQL 工具和对象关系映射工具,允许开发者以 Python 类和对象的形式操作数据库,而无需编写大量的 SQL 语句。SQLAlchemy 建立在 DBAPI 之上,支持多种数据库后端,如 SQLite, MySQL, PostgreSQL 等。 SQLAlchemy 的核心功能: 对象关系映射(ORM): SQLAlchemy 允许开发者使用 Python 类来表示数据库表,使用类的实例表示表中的行。 开发者可以定义类之间的关系(如一对多、多对多),SQLAlchemy 会自动处理这些关系在数据库中的映射。 通过 ORM,开发者可以像操作 Python 对象一样操作数据库,这大大简化了数据库操作的复杂性。 表达式语言: SQLAlchemy 提供了一个丰富的 SQL 表达式语言,允许开发者以 Python 表达式的方式编写复杂的 SQL 查询。 表达式语言提供了对 SQL 语句的灵活控制,同时保持了代码的可读性和可维护性。 数据库引擎和连接池: SQLAlchemy 支持多种数据库后端,并且为每种后端提供了对应的数据库引擎。 它还提供了连接池管理功能,以优化数据库连接的创建、使用和释放。 会话管理: SQLAlchemy 使用会话(Session)来管理对象的持久化状态。 会话提供了一个工作单元(unit of work)和身份映射(identity map)的概念,使得对象的状态管理和查询更加高效。 事件系统: SQLAlchemy 提供了一个事件系统,允许开发者在 ORM 的各个生命周期阶段插入自定义的钩子函数。 这使得开发者可以在对象加载、修改、删除等操作时执行额外的逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值