热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

英语词典2,用二分法预查范围,基于文本词典库,unicode,TTS发声,RichEdit显示,Win32SDK编程

MDX2.cpp:Definestheentrypointfortheapplication.1.改成unicode以支持音标和中文2.改用词库比较大的21世纪英汉汉英双向词典3.

// MDX2.cpp : Defines the entry point for the application.
//
// 1. 改成unicode以支持音标和中文
// 2. 改用词库比较大的 21世纪英汉汉英双向词典
// 3. 在之前的基础上增加了二分法搜索起始段,在段里面再查找关键字。
// 4. 二分法比较字符串大小的前提是词典库按顺序排列,比较大小前把字符串都转换为小写字母。
// 5. 只有一个字母的时候查到的数据比较多,会比较耗时,可以跳过,但是汉字只有一个字不能跳过
// 6. 不同字典的字体格式不同,太麻烦了
// 7. 基本上查找都在0.1s以下
//
// 2022-8-18 SZ XGZ

 

 

 

 

 MDX2.cpp

// MDX2.cpp : Defines the entry point for the application.
//
//
// 1. 改成unicode以支持音标和中文
// 2. 改用词库比较大的 21世纪英汉汉英双向词典
// 3. 在之前的基础上增加了二分法搜索起始段,在段里面再查找关键字。
// 4. 二分法比较字符串大小的前提是词典库按顺序排列,比较大小前把字符串都转换为小写字母。
// 5. 只有一个字母的时候查到的数据比较多,会比较耗时,可以跳过,但是汉字只有一个字不能跳过
// 6. 不同字典的字体格式不同,太麻烦了
// 7. 基本上查找都在0.1s以下
//
// 2022-8-18 SZ XGZ

#include
"stdafx.h"
#include
"resource.h"
#include

#include

#include

#include

#include
<string>
#include

#pragma comment(lib,"comctl32.lib")
using namespace std;
#define MAX_LOADSTRING 100
// Global Variables:
HINSTANCE hInst; // current instance
TCHAR szTitle[MAX_LOADSTRING]; // The title bar text
TCHAR szWindowClass[MAX_LOADSTRING]; // the main window class name
// Forward declarations of functions included in this code module:
ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE,
int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
INT_PTR CALLBACK About(HWND, UINT, WPARAM, LPARAM);
//xgz==========
#define IDC_RICHEDIT 1010
#define IDC_EDIT 1011
#define IDC_LIST 1012
#define IDC_EDITINPUT 1013
#define IDC_MAINTOOLSBAR 1014
#define IDM_TEST_TEST1 1015
#define IDM_TEST_TEST2 1016
#define IDM_TEST_TEST3 1017
#define IDM_TEST_TEST4 1018
#define IDM_TEST_TEST5 1019
#define IDM_TEST_TEST6 1020
HWND hWndMain;
HWND hWndMainToolbar;
HWND hWndStcrol;
HWND hWndRichEdit;
HWND hWndEdit;
HWND hWndEditInput;
HWND hWndList;
//vector NameIndex;
vector <string> NameIndex;
vector
<int> PosIndex;
int OnCreate(HWND, UINT, WPARAM, LPARAM);
int OnSize(HWND, UINT, WPARAM, LPARAM);
int OnPaint(HWND, UINT, WPARAM, LPARAM);
int OnVScroll(HWND, UINT, WPARAM, LPARAM);
int OnTimer(HWND, UINT, WPARAM, LPARAM);
int OnTest1(HWND, UINT, WPARAM, LPARAM);
int OnTest2(HWND, UINT, WPARAM, LPARAM);
int OnTest3(HWND, UINT, WPARAM, LPARAM);
int OnTest4(HWND, UINT, WPARAM, LPARAM);
int OnTest5(HWND, UINT, WPARAM, LPARAM);
int OnTest6(HWND, UINT, WPARAM, LPARAM);
int OnListSelChange(HWND, UINT, WPARAM, LPARAM);
int OnEditInputUpdate(HWND, UINT, WPARAM, LPARAM);
int OnEditInputChange(HWND, UINT, WPARAM, LPARAM);
//打印输出
//int PRINT(TCHAR* fmt, ...)
TCHAR buffer[1000000];
int PRINT(const TCHAR* fmt, ...)
{
va_list argptr;
int cnt;
int iEditTextLength;
HWND hWnd
= hWndEdit;
if (NULL == hWnd) return 0;
va_start(argptr, fmt);
cnt
= _vstprintf(buffer, fmt, argptr); // A or W but ISO C
//cnt = vswprintf(buffer, fmt, argptr); // only W
//cnt = wvsprintf(buffer, fmt, argptr); // not %f

va_end(argptr);
iEditTextLength
= GetWindowTextLength(hWnd);
if (iEditTextLength + cnt > 30000) // edit text max length is 30000
{
SendMessage(hWnd, EM_SETSEL,
0, 10000);
SendMessage(hWnd, WM_CLEAR,
0, 0);
iEditTextLength
= iEditTextLength - 10000;
}
SendMessage(hWnd, EM_SETSEL, iEditTextLength, iEditTextLength);
SendMessage(hWnd, EM_REPLACESEL,
0, (LPARAM)buffer);
return(cnt);
}
int RPRINT(const TCHAR* fmt, ...)
{
va_list argptr;
int cnt;
int iEditTextLength;
HWND hWnd
= hWndRichEdit;
if (NULL == hWnd) return 0;
va_start(argptr, fmt);
cnt
= _vstprintf(buffer, fmt, argptr); // A or W but ISO C
//cnt = vswprintf(buffer, fmt, argptr); // only W
//cnt = wvsprintf(buffer, fmt, argptr); // not %f

va_end(argptr);
iEditTextLength
= GetWindowTextLength(hWnd);
if (iEditTextLength + cnt > 30000) // edit text max length is 30000
{
SendMessage(hWnd, EM_SETSEL,
0, 10000);
SendMessage(hWnd, WM_CLEAR,
0, 0);
iEditTextLength
= iEditTextLength - 10000;
}
SendMessage(hWnd, EM_SETSEL, iEditTextLength, iEditTextLength);
SendMessage(hWnd, EM_REPLACESEL,
0, (LPARAM)buffer);
return(cnt);
}
//----------------------------
//sql执行回调函数
int sqlcallback(void* NotUsed, int argc, char** argv, char** azColName)
{
int i;
for (i = 0; i ) {
PRINT(_T("%s = %s\n"), azColName[i], argv[i] ? argv[i] : "NULL");
}
PRINT(_T(
"\r\n"));
return 0;
}
//xgz-----------

HWND m_hWnd
= NULL;
int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine);
// TODO: Place code here.
MSG msg;
HACCEL hAccelTable;
// Initialize global strings
LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);
LoadString(hInstance, IDC_MDX2, szWindowClass, MAX_LOADSTRING);
MyRegisterClass(hInstance);
// Perform application initialization:
if (!InitInstance (hInstance, nCmdShow))
{
return FALSE;
}
hAccelTable
= LoadAccelerators(hInstance, MAKEINTRESOURCE(IDC_MDX2));
// Main message loop:
while (GetMessage(&msg, NULL, 0, 0))
{
if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))
{
TranslateMessage(
&msg);
DispatchMessage(
&msg);
}
}
return (int) msg.wParam;
}
//
// FUNCTION: MyRegisterClass()
//
// PURPOSE: Registers the window class.
//
// COMMENTS:
//
// This function and its usage are only necessary if you want this code
// to be compatible with Win32 systems prior to the 'RegisterClassEx'
// function that was added to Windows 95. It is important to call this function
// so that the application will get 'well formed' small icons associated
// with it.
//
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASSEX wcex;
wcex.cbSize
= sizeof(WNDCLASSEX);
wcex.style
= CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc
= WndProc;
wcex.cbClsExtra
= 0;
wcex.cbWndExtra
= 0;
wcex.hInstance
= hInstance;
wcex.hIcon
= LoadIcon(hInstance, MAKEINTRESOURCE(IDI_MDX2));
wcex.hCursor
= LoadCursor(NULL, IDC_ARROW);
wcex.hbrBackground
= (HBRUSH)(COLOR_WINDOW+1);
wcex.lpszMenuName
= MAKEINTRESOURCE(IDC_MDX2);
wcex.lpszClassName
= szWindowClass;
wcex.hIconSm
= LoadIcon(wcex.hInstance, MAKEINTRESOURCE(IDI_SMALL));
return RegisterClassEx(&wcex);
}
//
// FUNCTION: InitInstance(HINSTANCE, int)
//
// PURPOSE: Saves instance handle and creates main window
//
// COMMENTS:
//
// In this function, we save the instance handle in a global variable and
// create and display the main program window.
//
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst
= hInstance; // Store instance handle in our global variable

hWnd
= CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
hWndMain
= hWnd;
return TRUE;
}
//
// FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
//
// PURPOSE: Processes messages for the main window.
//
// WM_COMMAND - process the application menu
// WM_PAINT - Paint the main window
// WM_DESTROY - post a quit message and return
//
//
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int wmId, wmEvent;
PAINTSTRUCT ps;
HDC hdc;
switch (message)
{
case WM_CREATE:
OnCreate(hWnd, message, wParam, lParam);
break;
case WM_SIZE:
OnSize(hWnd, message, wParam, lParam);
break;
case WM_PAINT:
OnPaint(hWnd, message, wParam, lParam);
break;
case WM_COMMAND:
wmId
= LOWORD(wParam);
wmEvent
= HIWORD(wParam);
// Parse the menu selections:
switch (wmId)
{
case IDC_EDITINPUT:
switch (wmEvent)
{
case EN_UPDATE:
OnEditInputUpdate(hWnd, message, wParam, lParam);
break;
case EN_CHANGE:
//OnEditInputChange(hWnd, message, wParam, lParam);
break;
}
break;
case IDC_LIST:
switch (wmEvent)
{
case LBN_SELCHANGE:
OnListSelChange(hWnd, message, wParam, lParam);
break;
}
break;
case IDM_TEST_TEST1:
OnTest1(hWnd, message, wParam, lParam);
break;
case IDM_TEST_TEST2:
OnTest2(hWnd, message, wParam, lParam);
break;
case IDM_TEST_TEST3:
OnTest3(hWnd, message, wParam, lParam);
break;
case IDM_TEST_TEST4:
OnTest4(hWnd, message, wParam, lParam);
break;
case IDM_TEST_TEST5:
OnTest5(hWnd, message, wParam, lParam);
break;
case IDM_TEST_TEST6:
OnTest6(hWnd, message, wParam, lParam);
break;
case IDM_ABOUT:
DialogBox(hInst, MAKEINTRESOURCE(IDD_ABOUTBOX), hWnd, About);
break;
case IDM_EXIT:
DestroyWindow(hWnd);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
break;
case WM_DESTROY:
PostQuitMessage(
0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}
// Message handler for about box.
INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
switch (message)
{
case WM_INITDIALOG:
return (INT_PTR)TRUE;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL)
{
EndDialog(hDlg, LOWORD(wParam));
return (INT_PTR)TRUE;
}
break;
}
return (INT_PTR)FALSE;
}
HWND CreateMainToolbar(HWND hWnd)
{
// image,COMMAND, STATUS, STYLE,
TBBUTTON tbButton[] = {
{ STD_FILENEW, IDM_TEST_TEST1, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_FILEOPEN, IDM_TEST_TEST2, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_FILESAVE, IDM_TEST_TEST3, TBSTATE_ENABLED , TBSTYLE_BUTTON ,
0L, 0},
{ STD_HELP, IDM_TEST_TEST4, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_FIND, IDM_TEST_TEST5, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_UNDO, IDM_TEST_TEST6, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1}, //分隔符
{ STD_REDOW, IDM_TEST_TEST1, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ STD_COPY, IDM_TEST_TEST2, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_PASTE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_CUT, IDM_TEST_TEST4, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_DELETE, IDM_TEST_TEST5, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_FILESAVE, IDM_TEST_TEST6, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{
0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0L, -1},//分隔符
{ STD_PROPERTIES, IDM_TEST_TEST1, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0L, 0},
{ STD_FIND, IDM_TEST_TEST2, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_REPLACE, IDM_TEST_TEST3, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_PRINT, IDM_TEST_TEST4, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_FILESAVE, IDM_TEST_TEST5, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_FILESAVE, IDM_TEST_TEST6, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0},
{ STD_PRINTPRE, IDM_EXIT, TBSTATE_ENABLED, TBSTYLE_BUTTON,
0L, 0}
};
HINSTANCE hLib
= (HINSTANCE)GetWindowLong(hWnd, GWL_HINSTANCE); //It can be other DLL,here same as m_hInst

HWND hWndToolbar
= CreateWindowEx(0, TOOLBARCLASSNAME, _T(""),
//WS_VISIBLE|WS_CHILD|TBSTYLE_TOOLTIPS, //| WS_BORDER|TBSTYLE_FLAT,
WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS | CCS_NORESIZE | CCS_ADJUSTABLE | CCS_NODIVIDER | CCS_NOPARENTALIGN, //for rebar
0, 0, 0, 0,
hWnd, (HMENU)IDC_MAINTOOLSBAR, hInst, NULL);
if (!hWndToolbar)
return NULL;
SendMessage(hWndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM)
sizeof(TBBUTTON), 0);
SendMessage(hWndToolbar, TB_SETEXTENDEDSTYLE,
0, (LPARAM)(DWORD)(TBSTYLE_EX_DRAWDDARROWS));
TBADDBITMAP tbBitmap1;
tbBitmap1.hInst
= HINST_COMMCTRL;
tbBitmap1.nID
= IDB_STD_SMALL_COLOR;
SendMessage(hWndToolbar, TB_ADDBITMAP,
0, (LPARAM)&tbBitmap1);
//ICO
// HIMAGELIST hImageList;
// hImageList = ImageList_Create(16, 16, ILC_COLOR32 | ILC_MASK, //size 16x16
// sizeof(tbButton)/sizeof(tbButton[0]), sizeof(tbButton)/sizeof(tbButton[0])); //double space
//
// for(unsigned int i = 0 ; i <= sizeof(tbButton)/sizeof(tbButton[0]) ; i++)
// {
// HICON hIcon = LoadIcon(hLib, MAKEINTRESOURCE(IDI_ICON1 + i));
// ImageList_AddIcon(hImageList, hIcon);
// DestroyIcon(hIcon);
// }
// SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);
// HIMAGELIST hImageList=ImageList_Create(16,16,ILC_COLOR16,1,10);
// HBITMAP hBitMap=LoadBitmap(m_hInst,MAKEINTRESOURCE(IDB_BITMAP1));
// ImageList_Add(hImageList,hBitMap,NULL);
// DeleteObject(hBitMap);
// SendMessage(hWndToolbar, TB_SETIMAGELIST, 0, (LPARAM)hImageList);

SendMessage(hWndToolbar, TB_SETBITMAPSIZE,
0, (LPARAM)MAKELONG(16, 16)); //size 16x16
SendMessage(hWndToolbar, TB_AUTOSIZE, 0, 0);
SendMessage(hWndToolbar, TB_ADDBUTTONS,
15, (LONG)&tbButton); //add 6 button
return hWndToolbar;
}
int OnCreate(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
InitCommonControls();
HINSTANCE hRich
= LoadLibrary(_T("Riched20.dll"));
hWndRichEdit
= CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS, NULL,// _T("RichEdit20W"), NULL,
WS_CHILD | WS_VISIBLE | WS_VSCROLL | ES_READONLY | ES_MULTILINE,
0, 0, 500, 500,
hWnd, (HMENU)IDC_RICHEDIT, hInst, NULL);
CHARFORMAT cf;
ZeroMemory(
&cf, sizeof(CHARFORMAT));
cf.cbSize
= sizeof(CHARFORMAT);
cf.dwMask
|= CFM_COLOR;
cf.crTextColor
= RGB(255, 0, 0); //设置颜色
cf.dwMask |= CFM_SIZE;
cf.yHeight
= 400;//设置高度
cf.dwMask |= CFM_FACE;
wcscpy(cf.szFaceName, _T(
"宋体"));//设置字体
//strcpy(cf.szFaceName, _T("宋体"));//设置字体
SendMessage(hWndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf);
hWndEditInput
= CreateWindow(_T("edit"), NULL,
WS_CHILD
| WS_BORDER | WS_VISIBLE | WS_TABSTOP | ES_WANTRETURN,//| ES_MULTILINE | WS_VSCROLL,
0, 0, 0, 0, hWnd, (HMENU)IDC_EDITINPUT, hInst, NULL);
hWndEdit
= CreateWindow(_T("edit"), NULL,
WS_CHILD
| WS_BORDER | WS_VISIBLE | ES_MULTILINE | WS_VSCROLL | ES_READONLY,
0, 0, 0, 0, hWnd, (HMENU)IDC_EDIT, hInst, NULL);
hWndList
= CreateWindow(_T("listbox"), NULL,
WS_CHILD
| WS_BORDER | WS_VISIBLE | WS_VSCROLL | WS_HSCROLL | LBS_NOTIFY,// | LBS_SORT,
0, 0, 0, 0, hWnd, (HMENU)IDC_LIST, hInst, NULL);
hWndMainToolbar
= CreateMainToolbar(hWnd);
return 1;
}
//留一个状态条的位置
int OnSize(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int cxClient, cyClient;
cxClient
= LOWORD(lParam);
cyClient
= HIWORD(lParam);
MoveWindow(hWndEditInput,
5, 0, 200, 30, TRUE);
MoveWindow(hWndList,
5, 25, 200, cyClient - 30, TRUE);
MoveWindow(hWndMainToolbar,
210, 0, 400, 25, TRUE);
MoveWindow(hWndRichEdit,
210, 25, cxClient - 215, cyClient - 160, TRUE);
MoveWindow(hWndEdit,
210, cyClient - 130, cxClient - 215, 120, TRUE);
SendMessage(hWndList, CB_SETHORIZONTALEXTENT, (WPARAM)
10, (LPARAM)0);
return DefWindowProc(hWnd, message, wParam, lParam);
}
int OnPaint(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
TCHAR
* str = _T("This is a test! 这是一个测试 0123456 +-*/ oo E5beit ");
int x = 210;
int y = 50;
PAINTSTRUCT ps;
HDC hdc;
RECT rt;
hdc
= BeginPaint(hWnd, &ps);
GetClientRect(hWnd,
&rt);
EndPaint(hWnd,
&ps);
return 1;
}
TCHAR buf[
1000001];
int strFormat(TCHAR* str, int len) //转小写
{
int i=0;
int n=0;
for (i = 0; i )
{
if ((str[i] >= 'A') && (str[i] <= 'Z'))
{
str[i]
= str[i] | 0x20;
n
++;
}
}
return n;
}
int FindPos(FILE* fp, TCHAR* strFind, int& f1, int& f2, int lev, TCHAR* buf)
{
int i;
TCHAR cfind;
TCHAR cdict;
TCHAR cfind0;
int Len = wcslen(strFind);
int res;
TCHAR strFind2[
100];
int fm;
fm
= (f1 + f2) / 2;
fseek(fp, fm,
0);
for (i = 0; i <20; i++) //最多20次 1M
{
fgetws(buf,
1000000, fp);
if (fgetws(buf, 1000000, fp) != NULL)
{
wmemcpy(strFind2, buf, Len);
strFind2[Len]
= 0;
strFormat(strFind2, Len);
res
= wcscmp(strFind, strFind2);
if (res>0)
{
f1
= fm;
fm
= (f1 + f2) / 2;
fseek(fp, fm,
0);
//PRINT(_T("\r\n %c>%c find[%d-%d-%d]"), strFind[lev], buf[lev], f1, fm, f2);
}
else if (res<0)
{
f2
= fm;
fm
= (f1 + f2) / 2;
fseek(fp, fm,
0);
//PRINT(_T("\r\n %c<%c find[%d-%d-%d]"), strFind[lev], buf[lev], f1, fm, f2);
}
else
{
break;
}
}
}
return fm;
}
int OnTest1(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
ISpVoice
* pVoice = NULL;
if (FAILED(CoInitialize(NULL)))
return -1;
HRESULT hr
= CoCreateInstance(CLSID_SpVoice, NULL,
CLSCTX_ALL, IID_ISpVoice, (
void**)&pVoice);
WCHAR ss[
200] = L"hello";
int index, iLength;
index
= SendMessage(hWndList, LB_GETCURSEL, 0, 0);
iLength
= SendMessage(hWndList, LB_GETTEXTLEN, 0, 0);
TCHAR str[
100];
iLength
= SendMessage(hWndList, LB_GETTEXT, index, (LPARAM)str);
PRINT(_T(
"\r\n Speak = %s"),str);
if (iLength <0) return 0;
if (SUCCEEDED(hr))
{
hr
= pVoice->Speak(str, 0, NULL);
pVoice
->Release();
pVoice
= NULL;
}
CoUninitialize();
return 1;
}
int FindUpdate(TCHAR *str, int Len)
{
FILE
* fp; //文件
fpos_t fpos;
LARGE_INTEGER t1, t2, tc;
//计时
double time;
int strFindLen;
TCHAR cfind, cdict;
TCHAR
* strFind; //

strFind
= str;
strFindLen
= wcslen(strFind);
strFormat(strFind, strFindLen);
QueryPerformanceFrequency(
&tc);
QueryPerformanceCounter(
&t1); //计时

fp
= _wfopen(L"e:\\lib\\21.txt", L"r, ccs=UTF-8");
if (NULL == fp)
{
PRINT(_T(
"\r\n fopen failed!"));
return 0;
}
int i = 0;
int j;
int k;
int f1;
int f2;
int fm;
f1
= ftell(fp);
j
= fseek(fp, 0, SEEK_END);
f2
= ftell(fp);
fm
= (f1 + f2) / 2;
fseek(fp, fm,
0);
for (i = 0; i )
{
fm = FindPos(fp, strFind, f1, f2, i, buf);
if (fm > 0)
{
//PRINT(_T("\r\n %c=%c%c find[%d-%d-%d]"), strFind[i], buf[i], buf[i + 1], f1, fm, f2);
}
else
{
//PRINT(_T("\r\n Failed"));
}
}
//PRINT(_T("\r\n fm(%d): %s"), i, buf);

fseek(fp, f1,
0); //起始段
fgetws(buf, 1000000, fp); //去掉可能不完整的一行
int m = 0;
int fstrlen;
fstrlen
= strFindLen;
for (i = 0; i <1000000; i++)
{
fgetpos(fp,
&fpos);
if (fgetws(buf, 1000000, fp) != NULL)
//if (fgets(buf, 1000000, fp) != NULL)
{
if (buf[0] == '-')
{
continue; //xgz 跳过奇奇怪怪的东西
}
for (j = 0; j )
{
if ((buf[j] | 0x20) != (strFind[j] | 0x20)) //xgz 都转小写比较
break;
}
if (j == fstrlen)
{
m
++; //xgz
buf[100] = 0;
for (k = 0; k <100; k++)
{
if ((buf[k] == '\t') && (buf[k + 1] == '<'))
{
buf[k]
= 0;
break;
}
}
SendMessage(hWndList, LB_ADDSTRING,
0, (LPARAM)buf);
PosIndex.push_back(fpos);
}
else if (j < fstrlen)
{
if (m > 0) //xgz 找到后再不同,就不用继续找了
{
break;
}
}
}
else
{
break;
}
}
//PRINT(_T("\r\n find: %s"), buf);

fclose(fp);
QueryPerformanceCounter(
&t2);
time
= (double)(t2.QuadPart - t1.QuadPart) / (double)tc.QuadPart;
PRINT(_T(
"\r\nFinish =%d time = %f"), i, time);
return 1;
}
int OnTest2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 1;
}
int RunCommand(char* str, int len);
int OnTest3(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 1;
}
int OnTest4(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 1;
}
int OnTest5(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 1;
}
int OnTest6(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return 1;
}
int RunCommand(TCHAR * str, int len)
{
int size = 0;
int c;
int n;
TCHAR mstr[
1000];
wcscpy(mstr, str);
TCHAR cstr[
3][100] = { 0 };
if (len == 2)
{
if ((str[0] == 'b') && (str[0] == 'r'))
{
RPRINT(_T(
"\r\n"));
}
return 2;
}
else if (len <6)
{
return 0;
}
else
{
}
TCHAR
* token;
TCHAR
* next_token = NULL;
n
= 0;
token
= wcstok_s(mstr, L" ", &next_token); //
while (token != NULL)
{
wcscpy(cstr[n], token);
token
= wcstok_s(NULL, L" ", &next_token); //股票名字
n++;
}
c
= 0x000000; //default
if (cstr[1][0] == 's') swscanf(cstr[1], L"size=%d", &size);
if ((cstr[1][0] == 'c') && (cstr[1][7] == '#'))
{
token
= wcstok_s(cstr[1], L"#", &next_token);
token
= wcstok_s(NULL, L"#", &next_token);
if (token != NULL)
{
token[
6] = 0;
swscanf(token, L
"%x", &c);
}
}
if ((cstr[1][0] == 'c') && ((cstr[1][6] | 0x20) == 'r')) c = 0x8f0000;
if ((cstr[1][0] == 'c') && ((cstr[1][6] | 0x20) == 'g')) c = 0x008f00;
if ((cstr[1][0] == 'c') && ((cstr[1][6] | 0x20) == 'b')) c = 0x00008f;
if (n == 3)
{
if (cstr[2][0] == 's') swscanf(cstr[2], L"size=%d", &size);
if ((cstr[2][0] == 'c') && (cstr[2][7] == '#'))
{
token
= wcstok_s(cstr[2], L"#", &next_token);
token
= wcstok_s(NULL, L"#", &next_token);
if (token != NULL)
{
token[
6] = 0;
swscanf(token, L
"%x", &c);
}
}
if ((cstr[2][0] == 'c') && ((cstr[2][6] | 0x20) == 'r')) c = 0x8f0000;
if ((cstr[2][0] == 'c') && ((cstr[2][6] | 0x20) == 'g')) c = 0x008f00;
if ((cstr[2][0] == 'c') && ((cstr[2][6] | 0x20) == 'b')) c = 0x00008f;
}
CHARFORMAT cf;
ZeroMemory(
&cf, sizeof(CHARFORMAT));
cf.cbSize
= sizeof(CHARFORMAT);
cf.dwMask
|= CFM_COLOR;
cf.crTextColor
= RGB(0, 0, 0); //设置颜色
cf.dwMask |= CFM_SIZE;
cf.yHeight
= 200;//设置高度
cf.dwMask |= CFM_FACE;
//wcscpy(cf.szFaceName, _T("Kingsoft Phonetic Plain"));//设置字体
wcscpy(cf.szFaceName, _T("Tahoma"));//设置字体
if (size != 0)
{
cf.dwMask
|= CFM_SIZE;
cf.yHeight
= size * 50;
}
else
{
cf.dwMask
&= ~CFM_SIZE;
}
int r, g, b;
r
= c >> 16 & 0xff;
g
= c >> 8 & 0xff;
b
= c & 0xff;
cf.dwMask
|= CFM_COLOR;
cf.crTextColor
= RGB(r, g, b); //设置颜色

SendMessage(hWndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)
&cf);
return 0;
}
int ShowWTXT(TCHAR* str)
{
TCHAR str1[
100];
TCHAR
* p;
// p = buf;//
p = str;
int mode = 0;
TCHAR command[
100];
int commandindex;
TCHAR text[
1000];
int textindex;
commandindex
= 0;
textindex
= 0;
SendMessage(hWndRichEdit, EM_SETSEL,
0, -1);
SendMessage(hWndRichEdit, EM_REPLACESEL,
0, (LPARAM)0);
while (*p != NULL)
{
switch (*p)
{
case '&':
if ((*(p + 1) == 'n') && (*(p + 2) == 'b') && (*(p + 3) == 's') && (*(p + 4) == 'p'))
{
p
= p + 5;
*p = ' ';
}
else if ((*(p + 1) == 'q') && (*(p + 2) == 'u') && (*(p + 3) == 'o') && (*(p + 4) == 't'))
{
p
= p + 5;
*p = '"';
}
else if ((*(p + 1) == 'l') && (*(p + 2) == 't'))
{
p
= p + 3;
*p = '<';
}
else if ((*(p + 1) == 'g') && (*(p + 2) == 't'))
{
p
= p + 3;
*p = '>';
}
break;
case '<':
mode
= 1; //command
if (textindex > 0)
{
text[textindex]
= 0;
RPRINT(_T(
"\r\n %s"), text);
//TextOutW(hdc, wx, wy, text, textindex);

textindex
= 0;
}
break;
case '>':
mode
= 0; //text

RunCommand(command, commandindex);
commandindex
= 0;
break;
default:
if (mode == 1)
{
command[commandindex]
= *p;
commandindex
++;
}
else
{
text[textindex]
= *p;
textindex
++;
}
break;
}
p
++;
}
return 1;
}
int OnListSelChange(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
int index, iLength;
index
= SendMessage(hWndList, LB_GETCURSEL, 0, 0);
iLength
= SendMessage(hWndList, LB_GETTEXTLEN, 0, 0);
fpos_t fpos;
fpos
= PosIndex.at(index);
PRINT(_T(
"\r\n Index=%d, Pos=%d"), index, fpos);
TCHAR fstr[
100];
iLength
= SendMessage(hWndList, LB_GETTEXT, index, (LPARAM)fstr);
PRINT(_T(
"\r\n %s "), fstr);
FILE
* fp;
fp
= _wfopen(L"e:\\lib\\21.txt", L"r, ccs=UTF-8");
//fp = fopen("e:\\lib\\lw-2.txt", "r");
if (NULL == fp)
{
PRINT(_T(
"\r\n fopen failed!"));
}
int fstrlen;
fstrlen
= iLength;
int i;
int j;
fsetpos(fp,
&fpos);
if (fgetws(buf, 1000000, fp) != NULL)
//if (fgets(buf, 1000000, fp) != NULL)
{
ShowWTXT(buf);
}
fclose(fp);
return 1;
}
int OnEditInputChange(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
PRINT(_T(
"\r\n OnEditInputChange "));
return 1;
}
int OnEditInputUpdate(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
TCHAR fstr[
200];
GetWindowText(hWndEditInput, fstr,
200);
//PRINT(_T("\r\n Search = %s "), fstr);
int numwritten;
int fstrlen;
//fstrlen = strlen(fstr);
fstrlen = wcslen(fstr);
if (fstrlen == 0) return 0;
if (fstrlen == 1) //只有一个字母的时候太耗时
{
if(fstr[0]>'A' && fstr[0] <'z')
return 0;
}
SendMessage(hWndList, LB_RESETCONTENT,
0, 0); //clear list

PosIndex.clear();
// clear index;

FindUpdate(fstr, fstrlen);
return 1;
}

 



推荐阅读
  • 1简介本文结合数字信号处理课程和Matlab程序设计课程的相关知识,给出了基于Matlab的音乐播放器的总体设计方案,介绍了播放器主要模块的功能,设计与实现方法.我们将该设 ... [详细]
  • 如何在HTML中获取鼠标的当前位置
    本文介绍了在HTML中获取鼠标当前位置的三种方法,分别是相对于屏幕的位置、相对于窗口的位置以及考虑了页面滚动因素的位置。通过这些方法可以准确获取鼠标的坐标信息。 ... [详细]
  • 本文介绍了如何在给定的有序字符序列中插入新字符,并保持序列的有序性。通过示例代码演示了插入过程,以及插入后的字符序列。 ... [详细]
  • 猜字母游戏
    猜字母游戏猜字母游戏——设计数据结构猜字母游戏——设计程序结构猜字母游戏——实现字母生成方法猜字母游戏——实现字母检测方法猜字母游戏——实现主方法1猜字母游戏——设计数据结构1.1 ... [详细]
  • [大整数乘法] java代码实现
    本文介绍了使用java代码实现大整数乘法的过程,同时也涉及到大整数加法和大整数减法的计算方法。通过分治算法来提高计算效率,并对算法的时间复杂度进行了研究。详细代码实现请参考文章链接。 ... [详细]
  • 本文介绍了南邮ctf-web的writeup,包括签到题和md5 collision。在CTF比赛和渗透测试中,可以通过查看源代码、代码注释、页面隐藏元素、超链接和HTTP响应头部来寻找flag或提示信息。利用PHP弱类型,可以发现md5('QNKCDZO')='0e830400451993494058024219903391'和md5('240610708')='0e462097431906509019562988736854'。 ... [详细]
  • 前景:当UI一个查询条件为多项选择,或录入多个条件的时候,比如查询所有名称里面包含以下动态条件,需要模糊查询里面每一项时比如是这样一个数组条件:newstring[]{兴业银行, ... [详细]
  • 本文介绍了一个题目的解法,通过二分答案来解决问题,但困难在于如何进行检查。文章提供了一种逃逸方式,通过移动最慢的宿管来锁门时跑到更居中的位置,从而使所有合格的寝室都居中。文章还提到可以分开判断两边的情况,并使用前缀和的方式来求出在任意时刻能够到达宿管即将锁门的寝室的人数。最后,文章提到可以改成O(n)的直接枚举来解决问题。 ... [详细]
  • 解决文件名过长下载失败问题的jQuery方案
    本文介绍了使用jQuery解决文件名过长导致下载失败的问题。原方案中存在文件名部分丢失的问题,通过动态生成隐藏域表单并提交的方式来解决。详细的解决方案和代码示例在文章中给出。 ... [详细]
  • 本文介绍了pack布局管理器在Perl/Tk中的使用方法及注意事项。通过调用pack()方法,可以控制部件在显示窗口中的位置和大小。同时,本文还提到了在使用pack布局管理器时,应注意将部件分组以便在水平和垂直方向上进行堆放。此外,还介绍了使用Frame部件或Toplevel部件来组织部件在窗口内的方法。最后,本文强调了在使用pack布局管理器时,应避免在中间切换到grid布局管理器,以免造成混乱。 ... [详细]
  • 用Vue实现的Demo商品管理效果图及实现代码
    本文介绍了一个使用Vue实现的Demo商品管理的效果图及实现代码。 ... [详细]
  • 本文总结了在编写JS代码时,不同浏览器间的兼容性差异,并提供了相应的解决方法。其中包括阻止默认事件的代码示例和猎取兄弟节点的函数。这些方法可以帮助开发者在不同浏览器上实现一致的功能。 ... [详细]
  • 如何优化Webpack打包后的代码分割
    本文介绍了如何通过优化Webpack的代码分割来减小打包后的文件大小。主要包括拆分业务逻辑代码和引入第三方包的代码、配置Webpack插件、异步代码的处理、代码分割重命名、配置vendors和cacheGroups等方面的内容。通过合理配置和优化,可以有效减小打包后的文件大小,提高应用的加载速度。 ... [详细]
  • 学习笔记17:Opencv处理调整图片亮度和对比度
    一、理论基础在数学中我们学过线性理论,在图像亮度和对比度调节中同样适用,看下面这个公式:在图像像素中其中:参数f(x)表示源图像像素。参数g(x)表示输出图像像素。 ... [详细]
  • 初识java关于JDK、JRE、JVM 了解一下 ... [详细]
author-avatar
重生之羽
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有