⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myfunc.cpp

📁 支持Windows 3.x、Windows 9x平台上的中文(GB、Big5)、日文(Shift JIS、EUC JIS)、韩文(KS C 5601)、HZ码的显示与输入,智能内码识别
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	{
		//得到一行
		nLineLen	=GetOneLine( hdc , i , sOutBuff , cb , nRectWidth , fuFormat ) ;
		if( nLineLen <= 0 || nLineLen > 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<cb ; )
	{
		if( i < cb-1 )	//判断是否遇到回车符和换行符
		{
			if( lpsz[i] == 0x0d && lpsz[i+1] == 0x0a )
				return( i+2-nStart ) ;
				
			//判断是否是一个汉字
			if( lpsz[i]&0x80 )
				nEnOrHz	=2 ;
			else
				nEnOrHz	=1 ;
		}
		else
			nEnOrHz	=1 ;
		
		if( LOWORD( GetTextExtent( hdc , lpsz+nStart , i+nEnOrHz-nStart ) ) > 
				(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 ; i<uLastChar ; i++ )
		if( i&0x80 )
			lpnWidths[i-uFirstChar]	=max(textMetric.tmAveCharWidth,
				(textMetric.tmHeight+1)/2) ;

	HookOn( 1 ) ;
	return( 1 ) ;
}

BOOL __export FAR PASCAL MyGetCharABCWidths(
							HDC hdc ,
							UINT uFirstChar,
							UINT uLastChar,
							LPABC lpabc )
{
	HookOff( 2 ) ;
	if( GetOutputCode() )	//不需要进行汉化
	{
		BOOL bResult	=GetCharABCWidths( hdc , uFirstChar , uLastChar , 
										lpabc ) ;
		HookOn( 2 ) ;
		return	bResult ;
	}
	
	TEXTMETRIC	textMetric ;
	if( !GetTextMetrics( hdc, &textMetric ) )
	{
		HookOn( 2 ) ;
		return( 0 ) ;
	}
	
	if( !GetCharABCWidths( hdc , 
						uFirstChar , uLastChar , lpabc ) )
	{
		HookOn( 2 ) ;
		return( 0 ) ;									
	}
	
	UINT	i ;
	for( i=uFirstChar ; i<uLastChar ; i++ )
		if( i&0x80 )
			lpabc[i-uFirstChar].abcB	=max(textMetric.tmAveCharWidth,
				(textMetric.tmHeight+1)/2)-
				lpabc[i-uFirstChar].abcA - lpabc[i-uFirstChar].abcC ;	

	HookOn( 2 ) ;
	return( 1 ) ;
}		

DWORD __export FAR PASCAL GetHzTextExtent(
							HDC hdc,	/* handle of device context	*/
							LPCSTR lpszString,	/* address of string	*/
							int cbString )	/* number of bytes in string	*/
{
	WORD	wWidth=0 ;
	int		nCharExtra	=GetTextCharacterExtra( hdc) ;
	TEXTMETRIC	textMetric ;
	if( !GetTextMetrics( hdc, &textMetric ) )
		return( 0 ) ;
	
	int		nResult ;        
	int		nNowPos ; 
	for( int i=0 ; i<cbString ; )
	{
		nResult	=JudgeEnOrHz( i , cbString , lpszString , 
							(LPINT)&nNowPos ) ;
		if( !nResult )
			break ;
		if( nResult == 1 )	//是单字节
		{
			wWidth	+=LOWORD( GetTextExtent( 
							hdc , (LPCSTR)(lpszString+i) , 
							nNowPos-i ) ) + nCharExtra ;
			if( nNowPos==cbString &&	//到最后了
				 (lpszString[cbString-1]&0x80) )	//最后一个是高位字节
				wWidth	+=max(textMetric.tmAveCharWidth,
				(textMetric.tmHeight+1)/2)+nCharExtra ;	//增加半字汉字宽度
		}				 
		else	//是双字节
			wWidth	+=(nNowPos-i)*(max(textMetric.tmAveCharWidth,
					(textMetric.tmHeight+1)/2)+nCharExtra) ;

		i	=nNowPos ;
	}

	DWORD	dwResult=MAKELONG(  
					wWidth ,
					HIWORD( GetTextExtent( hdc , lpszString , cbString ) ) )  ;

	return( dwResult ) ;
}

DWORD __export FAR PASCAL MyGetTextExtent(
							HDC hdc,	/* handle of device context	*/
							LPCSTR lpszString,	/* address of string	*/
							int cbString )	/* number of bytes in string	*/
{
	HookOff( 3 ) ;
	if( GetOutputCode()==5 )	//不需要进行汉化
	{
		DWORD	dwResult	=GetTextExtent( hdc , lpszString ,cbString ) ;
		HookOn( 3 ) ;
		return	dwResult ;
	}

	WORD	wWidth=0 ;
	int		nCharExtra	=GetTextCharacterExtra( hdc) ;
	TEXTMETRIC	textMetric ;
	if( !GetTextMetrics( hdc, &textMetric ) )
	{
		HookOn( 3 ) ;
		return( 0 ) ;
	}
	
	int		nResult ;        
	int		nNowPos ; 
	for( int i=0 ; i<cbString ; )
	{
		nResult	=JudgeEnOrHz( i , cbString , lpszString , 
								(LPINT)&nNowPos ) ;
		if( !nResult )
			break ;
		if( nResult == 1 )	//是单字节
		{
			wWidth	+=LOWORD( GetTextExtent( 
									hdc , (LPCSTR)(lpszString+i) , 
									nNowPos-i ) ) + nCharExtra ;
			if( nNowPos==cbString &&	//到最后了
				 (lpszString[cbString-1]&0x80) )	//最后一个是高位字节
				wWidth	+=max(textMetric.tmAveCharWidth,
				(textMetric.tmHeight+1)/2)+nCharExtra ;	//增加半字汉字宽度
		}				 
		else	//是双字节
			wWidth	+=(nNowPos-i)*(max(textMetric.tmAveCharWidth,
					(textMetric.tmHeight+1)/2)+nCharExtra) ;

		i	=nNowPos ;
	}

	DWORD	dwResult=MAKELONG(  
						wWidth ,
						HIWORD( GetTextExtent( hdc , lpszString , cbString ) ) )  ;

	HookOn( 3 ) ;	

	return( dwResult ) ;
}

int __export FAR PASCAL GetCurrentSystemMetrics( int nIndex )
{
	HookOff( 6 ) ;
	int	nResult	=GetSystemMetrics( nIndex ) ; 	//缺省是不加中文系统
	HookOn( 6 ) ;
	return	nResult ;
}
	
int __export FAR PASCAL MyGetSystemMetrics( int nIndex )
{
	HookOff( 6 ) ;
	int	nResult	=GetSystemMetrics( nIndex ) ; 	//缺省是不加中文系统
	if( GetOutputCode()<5 && nIndex==SM_DBCSENABLED )	//加了自己的中文系统
		nResult	=1 ;
	
	HookOn( 6 ) ;
	return	nResult ;
}
/*
BOOL __export FAR PASCAL MyGetTextMetrics(
	HDC hdc ,	// handle of device context	
	TEXTMETRIC FAR* lptm )	// pointer to structure for font metrics	
{
	HookOff( 7 ) ;
	if( GetOutputCode()==5 )	//不需要进行汉化
	{
		BOOL	bResult	=GetTextMetrics( hdc , lptm ) ;
		HookOn( 7 ) ;
		return	bResult ;
	}

	if( !GetTextMetrics( hdc, lptm ) )
	{
		HookOn( 7 ) ;
		return	FALSE ;
	}
	
	if( lptm->tmHeight%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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -