📄 srhword.c
字号:
//**************************************************************
// SrhWord.C
//
// Copyright 1997 by ITC, PCB. All rights reserved.
//
// Author: FengShuen Lu / Gang Fang / Gang Yan
//
// Date: 1997.5.30
//
// Description: 用於在打字/用字中取得指定位置处的单词,并返回光标位置.
//
// Function:
// LibMain() : 该函数在 DLL 被 LOAD 时被自动调用,用於初始化数据·
// DllEntryPoint() : 该函数在 DLL 被 LOAD 时被自动调用,用於初始化Thunk过程·
// WEP() : 该函数在 DLL 被释放时被自动调用·
//
// Notes:
//
// Update:
//
// Date Name Description
// ======= ====== ====================================
// 97.5.30 闫 刚 version 1.0.
//
// 97.11.13 闫 刚 将打字用字与查字合并·
// 主要是由於在实现32为拦截 API 後,对 IE4 等 UNICODE
// 的代码不需要特殊处理,同时需要将打字/用字与查字切词的
// 代码进行统一·
// 主要改动师注册一个消息,用於在 FINDWORD.C 中在得到单
// 词後向查字助理发消息,以进行显示·
//
// 由於不清楚在以後的版本中是否保留查字助理,所以与查字
// 助理有关的代码均进行条件编译,受 _DICTING_ 宏控制·
//
// 97.11.18 闫 刚 修改对 TA_CENTER 方式计算有误的BUG.
//
//**************************************************************
#include <windows.h>
#include <string.h>
#include <assert.h>
#include "srhword.h"
#include "findword.h"
#include "hookapi.h"
#include "..\pub3216.h"
#ifdef _DEBUG
#include "DbgFunc.h"
#endif //_DEBUG
// 定义 Thunk 中 16 位与 32 位 DLL 名·
#define DLL32NAME "NHW32.DLL"
#define DLL16NAME "NHW16.DLL"
// API 拦截结构·
// Gdi!TextOut
APIHOOKSTRUCT g_TextOutHook = {
"GDI", // The module name that the api in it.
"TextOut", // The api name that it will be hooked.
0,
NULL, // This api point.
{0, 0, 0, 0, 0}, // Use to record five byte at begin of api.
// these data is get from this program.
// the system may be already run the other
// program that these program change api too.
NULL, // The module name that the hook api in it.
"BlTextOut", // The hook api name that it will replace the api.
NULL, // This hook api point.
{0, 0, 0, 0, 0}, // Use to record five byte at begin of api.
// these data is get from this program.
// the system may be already run the other
// program that these program change api too.
0,
// Use to record five byte at begin of api.
// these data is get from WINICE. it is pure.
// Used when the BLIEA restart when BLIEA abort,
// Use to restore this api data.
{0X55, 0X8B, 0XEC, 0X68, 0XB7}
};
// Gdi!ExtTextOut
APIHOOKSTRUCT g_ExtTextOutHook = {
"GDI",
"ExtTextOut",
0,
NULL,
{0, 0, 0, 0, 0},
NULL,
"BlExtTextOut",
NULL,
{0, 0, 0, 0, 0},
0,
{0xb8, 0xe7, 0x05, 0x45, 0x55}
};
// Gdi!BitBlt
// 由於有关 Text 的输出是采用先向 MemDC 中输出,在采用 BitBlt 输出到屏幕·
// 因此需要拦截 BitBlt 来得到窗口与屏幕关连的 DC 的有关信息·
APIHOOKSTRUCT g_BitBltHook = {
"GDI",
"BitBlt",
0,
NULL,
{0, 0, 0, 0, 0},
NULL,
"BLBitBlt",
NULL,
{0, 0, 0, 0, 0},
0,
{0x55, 0x8b, 0xec, 0xb8, 0xf2}
};
// 该函数在 16 位系统中属於未公开函数·
WINDOWFROMDC_PROC WindowFromDC = NULL;
// 完整词数据结构·
int g_nCurrWindowVer = CHINESE_PRC; // 用於记录当前语言种类,主要用於分别简体中文和反体中文·
// 暂时不用·
char g_szTotalWord[BUFFERLENGTH] = ""; // 完整词记录缓冲区·
// 用於记录分几次输出的单词·
RECT g_TotalWordRect; // 用於记录完整词的区域大小·
int g_CharType = CHAR_TYPE_OTHER; // 用於记录完整词的类型·
// 在程序中主要用於判别新加入的串的类型是否予以有的单词类型相同·
int g_nCurCaretPlaceInTotalWord = -1; // 用於记录光标在完整词中的位置·
int g_bMouseInTotalWord = FALSE; // 用於记录光标是否在完整词中·
// 在程序中该标示主要用於判断是否需要清空buffer.
// 完整词数据结构·
// 当前词数据结构·( 当前词:为由输入缓冲区中切出的单词 )
char g_szCurWord[WORDMAXLEN] = ""; // 当前词缓冲区·
RECT g_CurWordRect; // 记录当前词区域·
int g_nCurCaretPlace; // 记录当前光标位置·
// 当前词数据结构·
// 记录与 MemDC 有关的信息·
// 由於有关 Text 的输出是采用先向 MemDC 中输出,在采用 BitBlt 输出到屏幕·
// 因此需要将 Text 的所有信息全部记录·
char szMemDCWordBuff[BUFFERLENGTH] = ""; // 用於记录所有 MemDC 中的 Text 文本·
int pnMemDCCharLeft[BUFFERLENGTH]; // 用於记录在 TextOut 中所有字的左相对值·
int pnMemDCCharRight[BUFFERLENGTH]; // 用於记录在 TextOut 中所有字的右相对值·
WORDPARA WordBuffer[MEMDC_MAXNUM]; // 用於记录在 TextOut 中切词後所有词的信息·
int nWordNum = 0; // 记录 MemDC 中单词的个数·
// 记录与 MemDC 有关的信息·
BOOL g_bAllowGetCurWord = FALSE; // 是否取词判断标志,在 UnHook 没有成功时起作用·
HWND g_hNotifyWnd = NULL; // 记录取词所要通知的窗口句柄·
POINT g_CurMousePos; // 记录当前光标位置·
UINT g_nTextAlign;
DWORD g_dwDCOrg;
int g_nExtra;
POINT g_CurPos;
TEXTMETRIC g_tm;
///////////////////////////////////////////////////////////////////////////
// Modify by Yan/Gang 1997/11/18
// 用於修改在计算 TA_CENTER 情况的失误。
BOOL bRecAllRect = FALSE;
RECT g_rcTotalRect;
// End Modify
///////////////////////////////////////////////////////////////////////////
//Added by XGL,Sep 29th,1998
RECT g_rcFirstWordRect; // contains the rect of first word of phrase
//Adding ends.
///////////////////////////////////////////////////////////////////////////
#ifdef _DICTING_
///////////////////////////////////////////////////////////////////////////
// Add by Yan/Gang 11/13/1997
// 用於向查字助理通知取得所需要的单词·
UINT BL_HASSTRING;
// Add end.
///////////////////////////////////////////////////////////////////////////
#endif
#ifdef _DICTING_
/////////////////////////////////////////////////////////////////////////////////
// Modify by Yan/Gang 1997/11/19
// 主要解决通配符的问题。
int g_nGetWordStyle;
// End Add.
/////////////////////////////////////////////////////////////////////////////////
//Added by XGL, Sep 17th, 1998
int g_nWordsInPhrase = -1 ; //current word number in phrase
BOOL g_bPhraseNeeded = FALSE ; //GETPHRASE_D(or TW)_ENABLE defined
int g_nPhraseCharType = CHAR_TYPE_OTHER ;
//Adding ends
#endif
BOOL FAR PASCAL __export DllEntryPoint (DWORD dwReason,
WORD hInst,
WORD wDS,
WORD wHeapSize,
DWORD dwReserved1,
WORD wReserved2);
BOOL FAR PASCAL thk_ThunkConnect16(LPSTR pszDll16,
LPSTR pszDll32,
WORD hInst,
DWORD dwReason);
HANDLE ghDLLInst;
//*********************************************************************
// Name : LibMain()
//
// Descriptions: 该函数在 DLL 被 LOAD 时被自动调用,用於初始化数据·
//
// Arguments : HINSTANCE hinst : Identifies the instance of the DLL.
// WORD wDataSeg : Specifies the value of the data segment
// (DS) register.
// WORD cbHeapSize : Specifies the size of the heap defined
// in the module-definition file.
// (The LibEntry routine in LIBENTRY.OBJ
// uses this value to initialize the local heap.)
// LPSTR lpszCmdLine : Points to a null-terminated string specifying
// command-line information. This parameter is
// rarely used by DLLs.
//
// Return : int : The function should return 1 if it is successful. Otherwise, it should return 0.
//
// Notes :
//
// Update:
//
// Date Name Description
// ======= ====== ====================================
// 97.5.30 闫 刚 version 1.0.
//
// 97.11.13 闫 刚 加入一个注册消息·
//
//*********************************************************************
int CALLBACK LibMain(HINSTANCE hInst,
WORD wDataSeg,
WORD cbHeapSize,
LPSTR lpszCmdLine)
{
HMODULE hUser16;
// 得到 WindowFromDC 函数的句柄·
hUser16 = LoadLibrary("USER.EXE");
if (hUser16 != NULL)
{
WindowFromDC = (WINDOWFROMDC_PROC)GetProcAddress(hUser16, "WINDOWFROMDC");
}
else
{
WindowFromDC = NULL;
}
// 初始化数据·
ghDLLInst = hInst;
g_nCurCaretPlace = -1;
g_CurMousePos.x = 0;
g_CurMousePos.y = 0;
g_TextOutHook.hInst = hInst;
g_ExtTextOutHook.hInst = hInst;
g_BitBltHook.hInst = hInst;
#ifdef _DICTING_
///////////////////////////////////////////////////////////////////////////
// Add by Yan/Gang 11/13/1997
// 用於向查字助理通知取得所需要的单词·
BL_HASSTRING = RegisterWindowMessage(MSG_HASSTRINGNAME);
// Add end.
///////////////////////////////////////////////////////////////////////////
#endif
// HookAllTextOut();
return (int)1;
}
//*********************************************************************
// Name : DllEntryPoint()
//
// Descriptions: 该函数在 DLL 被 LOAD 时被自动调用,用於初始化 Thunk 过程·
//
// Notes :
//
// Update:
//
//*********************************************************************
BOOL FAR PASCAL __export DllEntryPoint (DWORD dwReason,
WORD hInst,
WORD wDS,
WORD wHeapSize,
DWORD dwReserved1,
WORD wReserved2)
{
// 初始化 Thunk 过程·
if (!thk_ThunkConnect16(DLL16NAME,
DLL32NAME,
hInst,
dwReason))
{
return FALSE;
}
return TRUE;
}
//*********************************************************************
// Name : WEP()
//
// Descriptions: 该函数在 DLL 被释放时被自动调用·
//
// Arguments : int nExitType : Specifies whether all of Windows is shutting
// down or only the individual library. This
// parameter can be either WEP_FREE_DLL or
// WEP_SYSTEM_EXIT.
//
// Return : int : The function should return 1 if it is successful. Otherwise, it should return 0.
//
// Date Name Description
// ======= ====== ====================================
// 97.5.30 闫 刚 version 1.0.
//
//*********************************************************************
int CALLBACK WEP(int nExitType)
{
int i = 16 ;
UnHookAllTextOut();
#ifdef _DEBUG
DbgPrintf("This is %d bit dll", i) ;
#endif
return 1;
}
// Use to set current language sytle.
// Because file version functions do not work well in 16bit file.
// So I get language version in 32bit file. and then use thunk to send item
// to 16 bit.
DWORD FAR PASCAL _export BL_SetVer16(int nLangVer)
{
g_nCurrWindowVer = nLangVer;
return BL_OK;
}
/////////////////////////////////////////////////////////////////////////////////
// Add by Yan/Gang 1997/11/19
// 主要解决通配符的问题。
DWORD FAR PASCAL _export BL_SetGetWordStyle(int nGetWordStyle)
{
#ifdef _DICTING_
g_nGetWordStyle = nGetWordStyle;
//Added by XGL, Sep 17th,1997
//if phrase was required
if (nGetWordStyle == GETPHRASE_ENABLE)
{
g_nWordsInPhrase = -1 ;
g_bPhraseNeeded = TRUE ;
}
else
{
g_nWordsInPhrase = -1 ;
g_bPhraseNeeded = FALSE ;
}
//Adding ends.
#endif
return 0L;
}
// End Add.
/////////////////////////////////////////////////////////////////////////////////
// Use to record some parament. include wnd rect. and reset buffer.
DWORD FAR PASCAL _export BL_SetPara16(short hNotifyWnd, short MouseX, short MouseY)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -