首先声明,这段代码是针对《金山词霸2003》的,金山词霸的其它版本需要稍为修改。
源代码说明:
1:请自己去下载LoadDll,并且研究它的使用(只需要简单修改命令行):
http://www.codeguru.com/Cpp/W-P/dll/article.php/c105/
2: 把其中的TestFunction()替换为4中的源代码
3:注意:
3.1) ////////////////////////////////////////////////////////////////////
// The following code is to read explanationlist
和
///////////////// end of code to read explanation /////////////////
之间的代码是读取单词解释的。
3.2)
////////////////////////////////////////////////////////////////////
// The following code is to read word list
和
///////////////// end of code to read word list /////////////////
是读取单词列表的。
请自己修改
4.源代码
FILE * g_fileCiba=NULL;
void WriteWord(int nIndex,LPCTSTR pszString)
{
static const int STRING_MAX = 1024 * 100;
static TCHAR pszBuffer[STRING_MAX + 1]="";
if (pszString == NULL)
{
// flush the buffer: pszBuffer
if (strlen(pszBuffer) > 0)
fputs(pszBuffer,g_fileCiba);
return;
}
if (strlen(pszString) > STRING_MAX) {
::MessageBox( 0, "Word too long!", _T("TestLib"), MB_OK );
return;
}
if (strlen(pszString) + strlen(pszBuffer) > STRING_MAX)
{
// flush the buffer: pszBuffer
fputs(pszBuffer,g_fileCiba);
// clear the content
memset(pszBuffer,0,sizeof(pszBuffer));
strcpy(pszBuffer,pszString);
}
else {
strcat(pszBuffer,"#####/r/n"); // Symbol to seperate each word
strcat(pszBuffer,pszString);
strcat(pszBuffer,"/r/n");
}
}
ULONG TestFunction()
{
/////////////////////////////////////////////////////////
// Only for ?eé?′ê°?2003!
/////////////////////////////////////////////////////////
static const int WORD_MAX = 255;
static const int STRING_MAX = 1024 * 10;
TCHAR pszText[STRING_MAX + 1];
TCHAR pszCaption[WORD_MAX];
TCHAR pszWord[WORD_MAX + 1];
// Find the main window
HWND hWndCiba=GetWindow(GetDesktopWindow(),GW_CHILD);
while (hWndCiba) {
GetWindowText(hWndCiba,pszText,WORD_MAX);
if (strstr(pszText,"?eé?′ê°?") != NULL)
break;
// did not find window, get next window in list.
hWndCiba=GetWindow(hWndCiba,GW_HWNDNEXT);
}
if (hWndCiba == NULL) {
::MessageBox( 0, "?ò2?μ??eé?′ê°?", _T("TestLib"), MB_OK );
return 0;
}
// Find the window which ID is 0x3EA , the ComboBox to show the word selected
HWND hWndCombo=GetWindow(hWndCiba,GW_CHILD);
while (hWndCombo) {
GetWindowText(hWndCombo,pszText,WORD_MAX);
if (GetWindowLong(hWndCombo,GWL_ID) == 0x3EA)
break;
hWndCombo=GetWindow(hWndCombo,GW_HWNDNEXT);
}
if (hWndCombo == NULL) {
::MessageBox( 0, "Can NOT find the combo", _T("TestLib"), MB_OK );
return 0;
}
// Find the window which ID is 0x434, the list of words. ( or which caption is "WordList")
HWND hWndWordList=GetWindow(hWndCiba,GW_CHILD);
while (hWndWordList) {
GetWindowText(hWndWordList,pszText,WORD_MAX);
if (GetWindowLong(hWndWordList,GWL_ID) == 0x434)
break;
hWndWordList=GetWindow(hWndWordList,GW_HWNDNEXT);
}
if (hWndWordList == NULL) {
::MessageBox( 0, "Can NOT find the list", _T("TestLib"), MB_OK );
return 0;
}
// Find the window which ID is 0x3F1, the explanation window.
HWND hWndExplain=GetWindow(hWndCiba,GW_CHILD);
while (hWndExplain) {
GetWindowText(hWndExplain,pszText,WORD_MAX);
if (GetWindowLong(hWndExplain,GWL_ID) == 0x3F1)
break;
hWndExplain=GetWindow(hWndExplain,GW_HWNDNEXT);
}
if (hWndExplain == NULL) {
::MessageBox( 0, "Can NOT find the explanation window", _T("TestLib"), MB_OK );
return 0;
}
/////////////////////////////////////////////////////////
// Select the next item to enable the word shown in the ComboBox
// Then read the word from the ComboBox
// I have tried to use ListView_GetItemText(hWndWordList,0,0,lpszWord,255);
// to read the word from list directly, but FAILED!
// Maybe it is because ?eé?′ê°? encrypts the list??
/////////////////////////////////////////////////////////
int nPrevIndex,nIndex;
int nCount;
g_fileCiba=fopen("c://ciba.txt","w");
if (g_fileCiba == NULL) {
::MessageBox( 0, "Can Not open the file!/nProgram exits...", _T("TestLib"), MB_OK );
return 0;
}
GetWindowText(hWndCiba,pszCaption,WORD_MAX);
nCount=ListView_GetItemCount(hWndWordList); // get item count
nPrevIndex=ListView_GetNextItem(hWndWordList,-1,LVIS_SELECTED);
////////////////////////////////////////////////////////////////////
// The following code is to read explanationlist
LPTSTR lptstr;
for (nIndex = 0;nIndex < nCount;nIndex++) {
if (nPrevIndex != -1) {
// un-select the previous item
ListView_SetItemState(hWndWordList,nPrevIndex,UINT(~LVIS_SELECTED & ~LVIS_FOCUSED ),LVIS_SELECTED | LVIS_FOCUSED);
}
// select the current item
ListView_SetItemState(hWndWordList,nIndex,LVIS_SELECTED | LVIS_FOCUSED ,LVIS_SELECTED | LVIS_FOCUSED);
nPrevIndex = nIndex; // save the previous index
SendMessage(hWndCiba,WM_COMMAND,(WPARAM)32791,NULL);
SendMessage(hWndCiba,WM_COMMAND,(WPARAM)32775,NULL);
OpenClipboard(NULL);
HGLOBAL hglb = GetClipboardData(CF_TEXT);
if (hglb != NULL)
{
lptstr = (LPTSTR)GlobalLock(hglb);
WriteWord(nIndex,lptstr); // write the word into the file
GlobalUnlock(hglb);
}
CloseClipboard();
// show the progress
if (nIndex % 100 == 0) {
_stprintf(pszText,"GetWords -[%d / %d] %%%.2f ",
nIndex, nCount, (float)nIndex / nCount * 100.0f);
HDC hDC=GetDC(NULL);
TextOut(hDC,10,10,pszText,strlen(pszText));
TextOut(hDC,10,10,pszText,strlen(pszText));
}
}
///////////////// end of code to read explanation /////////////////
////////////////////////////////////////////////////////////////////
// The following code is to read word list
/* for (nIndex = 0;nIndex < nCount;nIndex++) {
if (nPrevIndex != -1) {
// un-select the previous item
ListView_SetItemState(hWndWordList,nPrevIndex,UINT(~LVIS_SELECTED & ~LVIS_FOCUSED ),LVIS_SELECTED | LVIS_FOCUSED);
}
// select the current item
ListView_SetItemState(hWndWordList,nIndex,LVIS_SELECTED | LVIS_FOCUSED ,LVIS_SELECTED | LVIS_FOCUSED);
GetWindowText(hWndCombo,pszWord,WORD_MAX);
// _stprintf(pszText,_T("Count: %d/nword: %s"), nCount, pszWord);
// ::MessageBox( 0, pszText, _T("TestLib"), MB_OK );
nPrevIndex = nIndex; // save the previous index
WriteWord(nIndex,pszWord); // write the word into the file
// show the progress
if (nIndex % 100 == 0) {
_stprintf(pszText,"GetWords -[%d / %d] %%%.2f ",
nIndex, nCount, (float)nIndex / nCount * 100.0f);
HDC hDC=GetDC(NULL);
TextOut(hDC,10,10,pszText,strlen(pszText));
TextOut(hDC,10,10,pszText,strlen(pszText));
}
}
*/
///////////////// end of code to read word list /////////////////
WriteWord(0,NULL); // flush the buffer
fclose(g_fileCiba);
return 1;
}