CHINESE.CPP
上传用户:zhang8947
上传日期:2007-01-08
资源大小:1910k
文件大小:6k
- //汉化
- #include "stdafx.h"
- //#include <windowsx.h>
- #include <dos.h>
- #include <string.h>
- #include "cspublic.h"
- #include "cskernel.h"
- #include "chinese.h"
- #include "myfunc.h"
- #include "hzout.h"
- static ALLHOOKFUNCMESS AllHookFuncMess ;
- static int nChineseFlag =0 ; //标记是否有中文系统,0没有,1有
- BOOL GetHookMem( void )
- {
- AllHookFuncMess.bLongJump =0xea ;
-
- //不能超过MAX_HOOK_FUNCTION个
- AllHookFuncMess.nHookFuncNum =7 ;
-
- /* AllHookFuncMess.lpHookFuncMess =
- (ONEHOOKFUNCMESS far *)GlobalAllocPtr(
- GHND ,
- (DWORD)AllHookFuncMess.nHookFuncNum *
- sizeof( ONEHOOKFUNCMESS ) ) ;
- if( !AllHookFuncMess.lpHookFuncMess )
- return( FALSE ) ;
- */
- return( TRUE ) ;
- }
- BOOL GetHookMess( void )
- {
- strcpy( AllHookFuncMess.HookFuncMess[0].sModuleName ,
- "GDI" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[0].sFuncName ,
- "TextOut" ) ;
- AllHookFuncMess.HookFuncMess[0].lpNewFuncAddress =
- (LPSTR)MyTextOut ;
- strcpy( AllHookFuncMess.HookFuncMess[5].sModuleName ,
- "GDI" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[5].sFuncName ,
- "ExtTextOut" ) ;
- AllHookFuncMess.HookFuncMess[5].lpNewFuncAddress =
- (LPSTR)MyExtTextOut ;
- strcpy( AllHookFuncMess.HookFuncMess[1].sModuleName ,
- "GDI" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[1].sFuncName ,
- "GetCharWidth" ) ;
- AllHookFuncMess.HookFuncMess[1].lpNewFuncAddress =
- (LPSTR)MyGetCharWidth ;
- strcpy( AllHookFuncMess.HookFuncMess[2].sModuleName ,
- "GDI" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[2].sFuncName ,
- "GetCharABCWidths" ) ;
- AllHookFuncMess.HookFuncMess[2].lpNewFuncAddress =
- (LPSTR)MyGetCharABCWidths ;
- strcpy( AllHookFuncMess.HookFuncMess[3].sModuleName ,
- "GDI" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[3].sFuncName ,
- "GetTextExtent" ) ;
- AllHookFuncMess.HookFuncMess[3].lpNewFuncAddress =
- (LPSTR)MyGetTextExtent ;
-
- strcpy( AllHookFuncMess.HookFuncMess[4].sModuleName ,
- "USER" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[4].sFuncName ,
- "DrawText" ) ;
- AllHookFuncMess.HookFuncMess[4].lpNewFuncAddress =
- (LPSTR)MyDrawText ;
- strcpy( AllHookFuncMess.HookFuncMess[6].sModuleName ,
- "USER" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[6].sFuncName ,
- "GetSystemMetrics" ) ;
- AllHookFuncMess.HookFuncMess[6].lpNewFuncAddress =
- (LPSTR)MyGetSystemMetrics ;
- /*
- strcpy( AllHookFuncMess.HookFuncMess[7].sModuleName ,
- "GDI" ) ;
- strcpy( AllHookFuncMess.HookFuncMess[7].sFuncName ,
- "GetTextMetrics" ) ;
- AllHookFuncMess.HookFuncMess[7].lpNewFuncAddress =
- (LPSTR)MyGetTextMetrics ;*/
- //--------------------------------------------------------------------------//
- LPSTR lpOldFunction ;
- int i , j ;
- for( i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
- {
- lpOldFunction =(LPSTR)GetProcAddress(
- GetModuleHandle(
- (LPCSTR)AllHookFuncMess.HookFuncMess[i].sModuleName ) ,
- (LPCSTR)AllHookFuncMess.HookFuncMess[i].sFuncName ) ;
- if( !lpOldFunction )
- {
- ::MessageBox( 0 , "GetProcAddress error" , 0 , MB_OK ) ;
- return( FALSE ) ;
- }
- AllHookFuncMess.HookFuncMess[i].wOldFuncCodeSelector =
- FP_SEG( lpOldFunction ) ;
- GlobalPageLock( (HGLOBAL)
- AllHookFuncMess.HookFuncMess[i].wOldFuncCodeSelector ) ;
- AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector =
- AllocCSToDSAlias( FP_SEG( lpOldFunction ) ) ;
- if( !AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector )
- {
- ::MessageBox( 0 , "AllocCSToDSAlias error" , 0 , MB_OK ) ;
- return( FALSE ) ;
- }
-
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress =
- (LPSTR)MK_FP(
- AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector ,
- FP_OFF( lpOldFunction ) ) ;
- for( j=0 ; j<5 ; j++ )
- AllHookFuncMess.HookFuncMess[i].sOldFuncFiveCodes[j] =
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j];
- }
- return( TRUE ) ;
- }
- void FreeMemory( void )
- {
- // if( AllHookFuncMess.lpHookFuncMess )
- // {
- for( int i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
- if( AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector )
- {
- GlobalPageUnlock( (HGLOBAL)
- AllHookFuncMess.HookFuncMess[i].wOldFuncCodeSelector ) ;
- FreeSelector(
- AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector ) ;
- }
- // GlobalFreePtr( AllHookFuncMess.lpHookFuncMess ) ;
- // }
- }
- void HookOn( int i )
- {
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[0] =
- AllHookFuncMess.bLongJump ;
-
- for( int j=1 ; j<5 ; j++ )
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
- ((LPSTR)&AllHookFuncMess.HookFuncMess[i].lpNewFuncAddress)[j-1];
- }
- void HookOff( int i )
- {
- for( int j=0 ; j<5 ; j++ )
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
- AllHookFuncMess.HookFuncMess[i].sOldFuncFiveCodes[j] ;
- }
- //------------------------------------------------------------------//
- #ifdef __cplusplus
- extern "C" {
- #endif
- //挂上汉字系统
- BOOL __export FAR PASCAL ToChinese( void )
- {
- if( nChineseFlag ) //已经汉化过了
- return FALSE ;
- nChineseFlag =1 ; //标记已经汉化过了
- if( !GetHookMem() )
- {
- ::MessageBox( 0 , "Get hook memory error" , 0 , MB_OK ) ;
- FreeMemory() ;
- return( FALSE ) ;
- }
- if( !GetHookMess() )
- {
- ::MessageBox( 0 , "Get hook message error" , 0 , MB_OK ) ;
- FreeMemory() ;
- return( FALSE ) ;
- }
- //---------------------------------------------------------------------------------------//
- //装入显示字库
- if( !LoadZk() )
- return FALSE ;
- int i , j ;
- for( i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
- {
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[0] =
- AllHookFuncMess.bLongJump ;
- for( j=1 ; j<5 ; j++ )
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
- ((LPSTR)&AllHookFuncMess.HookFuncMess[i].lpNewFuncAddress)[j-1];
- }
-
- UpdateScreen() ;
- return TRUE ;
- }
- //卸掉汉字系统
- void __export FAR PASCAL ToEnglish( void )
- {
- if( !nChineseFlag ) //没有中文系统
- return ;
- nChineseFlag =0 ;
- int i , j ;
-
- for( i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
- for( j=0 ; j<5 ; j++ )
- AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
- AllHookFuncMess.HookFuncMess[i].sOldFuncFiveCodes[j] ;
- FreeMemory() ;
- //卸掉显示字库
- UnloadZk( 0 ) ;
- UpdateScreen() ;
- }
- #ifdef __cplusplus
- }
- #endif
-