CHINESE.CPP
上传用户:zhang8947
上传日期:2007-01-08
资源大小:1910k
文件大小:6k
源码类别:

多国语言处理

开发平台:

Visual C++

  1. //汉化
  2. #include "stdafx.h"
  3. //#include <windowsx.h>
  4. #include <dos.h>
  5. #include  <string.h>
  6. #include "cspublic.h"
  7. #include "cskernel.h"
  8. #include "chinese.h"
  9. #include "myfunc.h"
  10. #include "hzout.h"
  11. static ALLHOOKFUNCMESS AllHookFuncMess ;
  12. static int  nChineseFlag =0 ; //标记是否有中文系统,0没有,1有
  13. BOOL GetHookMem( void )
  14. {
  15. AllHookFuncMess.bLongJump =0xea ;
  16. //不能超过MAX_HOOK_FUNCTION个
  17. AllHookFuncMess.nHookFuncNum =7 ;
  18. /* AllHookFuncMess.lpHookFuncMess =
  19. (ONEHOOKFUNCMESS far *)GlobalAllocPtr(
  20. GHND , 
  21. (DWORD)AllHookFuncMess.nHookFuncNum *
  22. sizeof( ONEHOOKFUNCMESS ) ) ;
  23. if( !AllHookFuncMess.lpHookFuncMess )
  24. return( FALSE ) ;
  25. */
  26. return( TRUE ) ;
  27. }
  28. BOOL GetHookMess( void )
  29. {
  30. strcpy( AllHookFuncMess.HookFuncMess[0].sModuleName ,
  31. "GDI" ) ;
  32. strcpy( AllHookFuncMess.HookFuncMess[0].sFuncName ,
  33. "TextOut" ) ;
  34. AllHookFuncMess.HookFuncMess[0].lpNewFuncAddress =
  35. (LPSTR)MyTextOut ;
  36. strcpy( AllHookFuncMess.HookFuncMess[5].sModuleName ,
  37. "GDI" ) ;
  38. strcpy( AllHookFuncMess.HookFuncMess[5].sFuncName ,
  39. "ExtTextOut" ) ;
  40. AllHookFuncMess.HookFuncMess[5].lpNewFuncAddress =
  41. (LPSTR)MyExtTextOut ;
  42. strcpy( AllHookFuncMess.HookFuncMess[1].sModuleName ,
  43. "GDI" ) ;
  44. strcpy( AllHookFuncMess.HookFuncMess[1].sFuncName ,
  45. "GetCharWidth" ) ;
  46. AllHookFuncMess.HookFuncMess[1].lpNewFuncAddress =
  47. (LPSTR)MyGetCharWidth ;
  48. strcpy( AllHookFuncMess.HookFuncMess[2].sModuleName ,
  49. "GDI" ) ;
  50. strcpy( AllHookFuncMess.HookFuncMess[2].sFuncName ,
  51. "GetCharABCWidths" ) ;
  52. AllHookFuncMess.HookFuncMess[2].lpNewFuncAddress =
  53. (LPSTR)MyGetCharABCWidths ;
  54. strcpy( AllHookFuncMess.HookFuncMess[3].sModuleName ,
  55. "GDI" ) ;
  56. strcpy( AllHookFuncMess.HookFuncMess[3].sFuncName ,
  57. "GetTextExtent" ) ;
  58. AllHookFuncMess.HookFuncMess[3].lpNewFuncAddress =
  59. (LPSTR)MyGetTextExtent ;
  60. strcpy( AllHookFuncMess.HookFuncMess[4].sModuleName ,
  61. "USER" ) ;
  62. strcpy( AllHookFuncMess.HookFuncMess[4].sFuncName ,
  63. "DrawText" ) ;
  64. AllHookFuncMess.HookFuncMess[4].lpNewFuncAddress =
  65. (LPSTR)MyDrawText ;
  66. strcpy( AllHookFuncMess.HookFuncMess[6].sModuleName ,
  67. "USER" ) ;
  68. strcpy( AllHookFuncMess.HookFuncMess[6].sFuncName ,
  69. "GetSystemMetrics" ) ;
  70. AllHookFuncMess.HookFuncMess[6].lpNewFuncAddress =
  71. (LPSTR)MyGetSystemMetrics ;
  72. /*
  73. strcpy( AllHookFuncMess.HookFuncMess[7].sModuleName ,
  74. "GDI" ) ;
  75. strcpy( AllHookFuncMess.HookFuncMess[7].sFuncName ,
  76. "GetTextMetrics" ) ;
  77. AllHookFuncMess.HookFuncMess[7].lpNewFuncAddress =
  78. (LPSTR)MyGetTextMetrics ;*/
  79. //--------------------------------------------------------------------------//     
  80. LPSTR lpOldFunction ;
  81. int i , j ;
  82. for( i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
  83. {
  84. lpOldFunction =(LPSTR)GetProcAddress(
  85. GetModuleHandle( 
  86. (LPCSTR)AllHookFuncMess.HookFuncMess[i].sModuleName ) ,
  87. (LPCSTR)AllHookFuncMess.HookFuncMess[i].sFuncName ) ;
  88. if( !lpOldFunction )
  89. {
  90. ::MessageBox( 0 , "GetProcAddress error" , 0 , MB_OK ) ;
  91. return( FALSE ) ;
  92. }
  93. AllHookFuncMess.HookFuncMess[i].wOldFuncCodeSelector =
  94. FP_SEG( lpOldFunction ) ;
  95. GlobalPageLock( (HGLOBAL)
  96. AllHookFuncMess.HookFuncMess[i].wOldFuncCodeSelector ) ;
  97. AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector =
  98. AllocCSToDSAlias( FP_SEG( lpOldFunction ) ) ; 
  99. if( !AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector )
  100. {
  101. ::MessageBox( 0 , "AllocCSToDSAlias error" , 0 , MB_OK ) ;
  102. return( FALSE ) ;
  103. }
  104.                         
  105. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress =
  106. (LPSTR)MK_FP(
  107. AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector ,
  108. FP_OFF( lpOldFunction ) ) ; 
  109. for( j=0 ; j<5 ; j++ )
  110. AllHookFuncMess.HookFuncMess[i].sOldFuncFiveCodes[j] =
  111. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j];
  112. }
  113. return( TRUE ) ;
  114. }
  115. void FreeMemory( void ) 
  116. {
  117. // if( AllHookFuncMess.lpHookFuncMess )
  118. // {
  119. for( int i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
  120. if( AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector )
  121. {
  122. GlobalPageUnlock( (HGLOBAL)
  123. AllHookFuncMess.HookFuncMess[i].wOldFuncCodeSelector ) ;
  124. FreeSelector( 
  125. AllHookFuncMess.HookFuncMess[i].wOldFuncDataSelector ) ;
  126. }
  127. // GlobalFreePtr( AllHookFuncMess.lpHookFuncMess ) ;
  128. // }
  129. }
  130. void HookOn( int i )
  131. {
  132. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[0] =
  133. AllHookFuncMess.bLongJump ;
  134. for( int j=1 ; j<5 ; j++ )
  135. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
  136. ((LPSTR)&AllHookFuncMess.HookFuncMess[i].lpNewFuncAddress)[j-1];
  137. }
  138. void HookOff( int i )
  139. {
  140. for( int j=0 ; j<5 ; j++ )
  141. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
  142. AllHookFuncMess.HookFuncMess[i].sOldFuncFiveCodes[j] ;
  143. }
  144. //------------------------------------------------------------------//
  145. #ifdef __cplusplus
  146. extern "C" {
  147. #endif
  148. //挂上汉字系统
  149. BOOL __export FAR PASCAL ToChinese( void )
  150. {
  151. if( nChineseFlag ) //已经汉化过了
  152. return FALSE ;
  153. nChineseFlag =1 ; //标记已经汉化过了
  154. if( !GetHookMem() )
  155. {
  156. ::MessageBox( 0 , "Get hook memory error" , 0 , MB_OK ) ;
  157. FreeMemory() ;
  158. return( FALSE ) ;
  159. }
  160. if( !GetHookMess() )
  161. {
  162. ::MessageBox( 0 , "Get hook message error" , 0 , MB_OK ) ;
  163. FreeMemory() ;
  164. return( FALSE ) ;
  165. }
  166. //---------------------------------------------------------------------------------------//
  167. //装入显示字库
  168. if( !LoadZk() )
  169. return FALSE ;
  170. int i , j ;
  171. for( i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
  172. {
  173. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[0] =
  174. AllHookFuncMess.bLongJump ;
  175. for( j=1 ; j<5 ; j++ )
  176. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
  177. ((LPSTR)&AllHookFuncMess.HookFuncMess[i].lpNewFuncAddress)[j-1];
  178. }
  179. UpdateScreen() ;
  180. return TRUE ;
  181. }
  182. //卸掉汉字系统
  183. void __export FAR PASCAL ToEnglish( void )
  184. {
  185. if( !nChineseFlag ) //没有中文系统
  186. return ;
  187. nChineseFlag =0 ;
  188. int i , j ;
  189. for( i=0 ; i<AllHookFuncMess.nHookFuncNum ; i++ )
  190. for( j=0 ; j<5 ; j++ )
  191. AllHookFuncMess.HookFuncMess[i].lpOldFuncDataAddress[j] =
  192. AllHookFuncMess.HookFuncMess[i].sOldFuncFiveCodes[j] ;
  193. FreeMemory() ;
  194. //卸掉显示字库
  195. UnloadZk( 0 ) ;
  196. UpdateScreen() ;
  197. }
  198. #ifdef __cplusplus
  199. }
  200. #endif