www.pudn.com > 智能内码识别,支持屏幕取词翻译的程序.zip > MYFUNC.CPP


#include	"stdafx.h" 
#include	 
#include	 
 
#include	"cspublic.h" 
 
#include	"myfunc.h" 
#include	"chinese.h" 
 
#include	"hzout.h" 
#include	"multcode.h" 
#include	"cskernel.h" 
 
#ifdef __cplusplus 
extern "C" { 
#endif 
 
BOOL __export FAR PASCAL MyTextOut(  
					HDC hdc , int nXStart , int nYStart ,  
				   LPCSTR lpStr , int cbString ) 
{ 
	HookOff( 5 ) ; 
	HookOff( 0 ) ; 
	if( cbString < 1 ) 
	{ 
		BOOL	bResult	=TextOut( hdc , nXStart , nYStart , lpStr , cbString) ; 
		HookOn( 5 ) ; 
		HookOn( 0 ) ; 
		return( bResult ) ; 
	} 
 
	//分配空间 
	LPSTR	sOutBuff	=(LPSTR)GlobalAllocPtr( GMEM_FIXED , 
										cbString ) ; 
	if( !sOutBuff )	//失败 
	{ 
		BOOL	bResult	=TextOut( hdc , nXStart , nYStart , sOutBuff , cbString) ;//lpStr , cbString ) ; 
		HookOn( 5 ) ; 
		HookOn( 0 ) ; 
		return( bResult ) ; 
	} 
 
	//复制内容 
	_fstrncpy( sOutBuff , lpStr , cbString ) ; 
	//判断当前显示内码,0为GB码,1为BIG5码,2,3,4为其它缺省内码 
	int	nOutputCode	=JudgeCode( sOutBuff , cbString ) ; 
 
	if( GetFingerTranslate()==2 )	//需要进行动态翻译,并且可以写 
	{ 
		POINT	p ; 
		if( GetTextAlign( hdc ) & TA_UPDATECP ) 	//要改变当前位置 
		{ 
			DWORD	dwPos	=GetCurrentPosition( hdc ) ;	//得到当前位置 
			p.x	=LOWORD( dwPos ) ;                                
			p.y	=HIWORD( dwPos ) ; 
		} 
		else 
		{ 
			p.x	=nXStart ; 
			p.y	=nYStart ; 
		} 
 
		//转换成设备坐标 
		LPtoDP( hdc , &p , 1 ) ; 
		 
		DWORD	temp	=GetDCOrg( hdc ) ;		//得到转换原点 
		p.x	+=LOWORD( temp ) ; 
		p.y	+=HIWORD( temp ) ; 
 
		SetOutPos( p , hdc ) ;		//设置当前显示起始位置 
		SetStrBuff( (LPSTR)sOutBuff , cbString ) ;		//设置要显示的字符串 
	} 
//--------------------------------------------------------------------// 
	if( GetOutputCode()==5 ||	//不需要进行汉化 
	     (  GetCurrentSystemMetrics( SM_DBCSENABLED )&& 
	     	GetSystemFirst()&&GetSystemCode()==(nOutputCode+1)) ) 
	{ 
		BOOL bResult	=TextOut( hdc , nXStart , nYStart ,  
							sOutBuff , cbString ) ; 
		GlobalFreePtr( sOutBuff ) ; 
		HookOn( 5 ) ; 
		HookOn( 0 ) ; 
		return	bResult ; 
	} 
 
	DWORD	dwTextExtent	=GetTextExtent( hdc , sOutBuff , cbString ) ; 
	RECT	rect={ nXStart , nYStart ,  
							 nXStart+LOWORD( dwTextExtent ) -1 , 0 } ; 
	if( GetMapMode( hdc	) == MM_TEXT ) 
		rect.bottom	=nYStart + HIWORD( dwTextExtent ) - 1 ; 
	else 
		rect.bottom	=nYStart - HIWORD( dwTextExtent ) + 1 ;						  
	BOOL    bResult=HzStringOut( hdc , nXStart , nYStart , 
								(RECT FAR *)&rect ,	 
								sOutBuff , cbString , NULL , nOutputCode ) ; 
 
	GlobalFreePtr( sOutBuff ) ; 
	HookOn( 5 ) ; 
	HookOn( 0 ) ; 
 
	return( bResult ) ; 
} 
 
BOOL __export FAR PASCAL MyExtTextOut(  
				   HDC hdc , int nXStart , int nYStart ,  
				   UINT fuOptions , const RECT FAR* lprc , 
				   LPCSTR lpStr , UINT cbString , 
				   int FAR* lpDx ) 
{ 
	HookOff( 5 ) ; 
	HookOff( 0 ) ; 
	if( cbString < 1 ) 
	{ 
		BOOL	bResult	=ExtTextOut( hdc , nXStart , nYStart , fuOptions , 
			lprc , lpStr , cbString , lpDx ) ; 
		HookOn( 5 ) ; 
		HookOn( 0 ) ; 
		return	bResult ; 
	} 
 
	//分配空间 
	LPSTR	sOutBuff	=(LPSTR)GlobalAllocPtr( GMEM_FIXED , 
										cbString ) ; 
	if( !sOutBuff )	//失败 
	{ 
		BOOL	bResult	=ExtTextOut( hdc , nXStart , nYStart , fuOptions , 
			lprc , lpStr , cbString , lpDx ) ; 
		HookOn( 5 ) ; 
		HookOn( 0 ) ; 
		return	bResult ; 
	} 
	 
	//复制内容 
	_fstrncpy( (LPSTR)sOutBuff , lpStr , cbString ) ; 
	//判断当前显示内码,0为GB码,1为BIG5码,2,3,4为其它缺省内码 
	int	nOutputCode	=JudgeCode( (LPSTR)sOutBuff , cbString ) ; 
 
	if( GetFingerTranslate()==2 )	//需要进行动态翻译,并且可以写 
	{ 
		POINT	p ; 
		if( GetTextAlign( hdc ) & TA_UPDATECP ) 	//要改变当前位置 
		{ 
			DWORD	dwPos	=GetCurrentPosition( hdc ) ;	//得到当前位置 
			p.x	=LOWORD( dwPos ) ;                                
			p.y	=HIWORD( dwPos ) ; 
		} 
		else 
		{ 
			p.x	=nXStart ; 
			p.y	=nYStart ; 
		} 
		UINT	uiTextAlign	=GetTextAlign( hdc ) ;	 
		TEXTMETRIC	textMetric ; 
		GetTextMetrics( hdc , &textMetric ) ; 
		switch( ( TA_BASELINE | TA_BOTTOM | TA_TOP ) & uiTextAlign ) 
		{ 
			case	 TA_BASELINE: 
				if( GetMapMode( hdc ) == MM_TEXT )			 
					p.y	-=textMetric.tmAscent ; 
				else 
					p.y	+=textMetric.tmAscent ; 
				break ; 
			case	TA_BOTTOM: 
				p.y	=lprc->bottom-textMetric.tmHeight ; 
				break ; 
//			case	TA_TOP: 
//				nYStart	=lprc->top ; 
//				break ; 
		} 
		LPtoDP( hdc , &p , 1 ) ;		//转换成设备坐标 
		 
		DWORD	temp	=GetDCOrg( hdc ) ;	//得到转换原点 
		p.x	+=LOWORD( temp ) ; 
		p.y	+=HIWORD( temp ) ; 
		 
		SetOutPos( p , hdc ) ;       
		SetStrBuff( (LPSTR)sOutBuff , cbString ) ;	 
	}		 
//-------------------------------------------------------------------// 
	if( GetOutputCode()==5 ||	//不需要进行汉化 
	     (  GetCurrentSystemMetrics( SM_DBCSENABLED )&& 
	     GetSystemFirst()&&GetSystemCode()==(nOutputCode+1)) ) 
	{ 
		BOOL bResult	=ExtTextOut( hdc , nXStart , nYStart ,  
									fuOptions , lprc ,  
									(LPSTR)sOutBuff , cbString , lpDx ) ; 
		GlobalFreePtr( sOutBuff ) ;									 
		HookOn( 5 ) ; 
		HookOn( 0 ) ; 
		return	bResult ; 
	} 
		 
	BOOL	 bResult=ExtHzStringOut( hdc , nXStart , nYStart , 
									fuOptions , lprc , 
									(LPSTR)sOutBuff , cbString , lpDx , nOutputCode ) ; 
                         
	GlobalFreePtr( sOutBuff ) ;									 
	HookOn( 5 ) ; 
 	HookOn( 0 ) ; 
 
	return( bResult ) ; 
} 
 
int __export FAR PASCAL MyDrawText(	 
						HDC hdc ,	/* handle of device context	*/ 
						LPCSTR lpStr ,	/* address of string to draw	*/ 
						int cb ,	/* string length	*/ 
						RECT FAR* lprc ,	/* address of structure with formatting dimensions	*/ 
						UINT fuFormat )	/* text-drawing flags	*/ 
{						 
	//确定字符串的长度 
	if( cb == -1 ) 
		cb	=lstrlen( lpStr ) ; 
		 
	if( cb < 1 ) 
	{ 
		HookOff( 4 ) ; 
		int	nResult	=DrawText( hdc , lpStr , cb , lprc , fuFormat ) ; 
		HookOn( 4 ) ;	 
		return	nResult ; 
	} 
	 
	//分配空间 
	LPSTR	sOutBuff	=(LPSTR)GlobalAllocPtr( GMEM_FIXED , 
										cb ) ; 
	if( !sOutBuff )	//失败 
	{ 
		HookOff( 4 ) ; 
		int	nResult	=DrawText( hdc , lpStr , cb , lprc , fuFormat ) ; 
		HookOn( 4 ) ;	 
		return	nResult ; 
	} 
 
	//复制内容 
	_fstrncpy( sOutBuff , lpStr , cb ) ; 
	//判断当前显示内码,0为GB码,1为BIG5码,2,3,4为其它缺省内码 
	int	nOutputCode	=JudgeCode( sOutBuff , cb ) ; 
	 
//	if( GetFingerTranslate() == 2 )	//需要进行指取翻译 
//	{ 
//		POINT	p={ nXStart , nYStart } ; 
//		 
//		SetOutPos( p , hdc ) ; 
//		SetStrBuff( lpsz , cb ) ; 
//	} 
//----------------------------------------------------------------------//	 
	HookOff( 4 ) ; 
	if( GetOutputCode()==5 ||	//不需要进行汉化 
	     (  GetCurrentSystemMetrics( SM_DBCSENABLED )&& 
	     GetSystemFirst()&&GetSystemCode()==(nOutputCode+1)) ) 
	{ 
		BOOL bResult	=DrawText( hdc ,  sOutBuff , cb , lprc , fuFormat ) ; 
		GlobalFreePtr( sOutBuff ) ; 
		HookOn( 4 ) ; 
		return	bResult ; 
	} 
		 
	//确定矩形的宽度和高度 
	if( DT_CALCRECT & fuFormat ) 
	{ 
		int	nResult	=DrawText( hdc , sOutBuff , cb , lprc , fuFormat ) ; 
		 
		GlobalFreePtr( sOutBuff ) ; 
		HookOn( 4 ) ; 
		return( nResult  ) ; 
	} 
 
	//确定行高度 
	TEXTMETRIC	textMetric ; 
	GetTextMetrics( hdc , &textMetric ) ; 
	int	nLineHeight	=textMetric.tmHeight ; 
	if( DT_EXTERNALLEADING & fuFormat ) 
		nLineHeight	+=textMetric.tmExternalLeading ; 
		 
	//确定字符串的Y轴起始显示位置 
	int	nMapMode	=GetMapMode( hdc ) ;	//坐标映射方式 
	int	nYStart	=lprc->top ; 
	if( DT_SINGLELINE & fuFormat )		//只有一行 
	{ 
		if( DT_BOTTOM & fuFormat )		//底对齐 
		{ 
			if( nMapMode == MM_TEXT ) 
				nYStart	=lprc->bottom - nLineHeight ; 
			else 
				nYStart	=lprc->bottom + nLineHeight ; 
		} 
		else 
		{ 
			if( DT_VCENTER & fuFormat )	//垂直中对齐 
			{ 
				if( nMapMode == MM_TEXT ) 
					nYStart	=( lprc->top + lprc->bottom - nLineHeight )/2 ; 
				else 
					nYStart	=( lprc->top + lprc->bottom + nLineHeight )/2 ; 
			} 
		} 
	} 
	int	nFirstYStart	=nYStart ;	//为了计算文字的高度 
	 
	int	nXStart ;				//X轴起始位置 
	int	nLineWidth ;		//一行宽度 
	int	nLineLen ;			//一行长度 
	int	nRectWidth	=lprc->right-lprc->left ;		//矩形宽度 
	for( int i=0 ; i cb )	//出错 
			break ; 
			 
		//得到该行宽度 
		nLineWidth	=LOWORD( GetTextExtent( hdc , sOutBuff+i , nLineLen ) ) ; 
		//计算该行起始位置 
		if( DT_CENTER & fuFormat )	//水平居中 
			nXStart	=( lprc->left + lprc->right - nLineWidth )/2 ; 
		else 
		{ 
			if( DT_RIGHT & fuFormat )	//水平居右 
				nXStart	=lprc->right - nLineWidth  ; 
			else		//水平居左 
				nXStart	=lprc->left ; 
		} 
		 
		//显示该行 
		if( DT_NOCLIP )		//不加载剪 
			TextOut( hdc , nXStart , nYStart , sOutBuff+i , nLineLen ) ; 
		else							//进行载剪 
			ExtTextOut( hdc , nXStart , nYStart , ETO_CLIPPED ,  
								lprc , sOutBuff+i , nLineLen , NULL ) ; 
 
		//调整Y轴显示位置 
		nYStart	+=nLineHeight ; 
		//调整下一行的起始位置 
		i	+=nLineLen ; 
	} 
 
	GlobalFreePtr( sOutBuff ) ; 
	HookOn( 4 ) ;	 
	return( nYStart - nFirstYStart ) ; 
} 
         
//从字符串得到一行,返回行字符宽度 
int	GetOneLine( HDC hdc , int nStart , LPCSTR lpsz , int cb , int nRectWidth , UINT fuFormat ) 
{ 
	if( !(DT_WORDBREAK & fuFormat ) )	//不用自动换行 
		return( cb-nStart ) ; 
		 
	int	nEnOrHz ;	//标记是英文字符还是汉字 
	for( int i=nStart ; i  
				(WORD)nRectWidth )	//超过了载剪矩形的宽度 
			return( i - nStart ) ; 
		 
		i	+=nEnOrHz ; 
	} 
 
	return( i - nStart ) ; 
} 
		 
BOOL __export FAR PASCAL MyGetCharWidth( 
							HDC hdc ,	/* handle of device context	*/ 
							UINT uFirstChar,	/* first character in range to query	*/ 
							UINT uLastChar,	/* last character in range to query	*/ 
							int FAR* lpnWidths )	/* address of buffer for widths	*/ 
{ 
	HookOff( 1 ) ; 
	if( GetOutputCode()==5 )	//不需要进行汉化 
	{ 
		BOOL bResult	=GetCharWidth( hdc , uFirstChar , uLastChar ,  
									lpnWidths ) ; 
		HookOn( 1 ) ; 
		return	bResult ; 
	} 
	 
	TEXTMETRIC	textMetric ; 
	if( !GetTextMetrics( hdc, &textMetric ) ) 
	{ 
		HookOn( 1 ) ; 
		return( 0 ) ; 
	} 
	 
	if( !GetCharWidth( hdc ,  
					uFirstChar , uLastChar , lpnWidths ) ) 
	{ 
		HookOn( 1 ) ; 
		return( 0 ) ;									 
	} 
 
	UINT	i ; 
	for( i=uFirstChar ; itmHeight%2 ) 
	{ 
		lptm->tmHeight-- ; 
		if( lptm->tmAscent%2 ) 
			lptm->tmAscent-- ; 
		else 
			lptm->tmDescent-- ; 
		if( lptm->tmInternalLeading%2 ) 
			lptm->tmInternalLeading-- ; 
	} 
		 
	HookOn( 7 ) ; 
	return	TRUE ; 
} 
*/ 
#ifdef __cplusplus 
} 
#endif