📄 myfunc.cpp
字号:
#include "stdafx.h"
#include <windowsx.h>
#include <string.h>
#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 ; ) //开始显示
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -