创建拼写对话框

【勇芳软件工作室】汉化HomePreviousNext

以下是拼写检查器对话框的对话框过程和支持功能。

HWND hwndMain;

HWND hwndEdit;

char achTemp[256]; /* temporary buffer */

LPSTR lpstrDict; /* buffer for dictionary file */

LPSTR *paLpDict; /* array of pointers to words */

UINT cWords; /* number of words */

/********************************************************

功能:SpellDlgProc

目的:对话框对话框对话框。

*********************************************************/

BOOL CALLBACK SpellDlgProc(hwndDlg, msg, wParam, lParam)

HWND hwndDlg;

UINT msg;

WPARAM wParam;

LPARAM lParam;

{

switch(msg){

case WM_INITDIALOG:

if(!OpenDictionary()){

EndDialog(hwndDlg, 0);

break;

}

SendMessage(hwndEdit, EM_SETSEL, 0, 0);

do

if(!SelectNextWord(hwndEdit,achTemp)){

GlobalFree((HGLOBAL) lpstrDict);

LocalFree((HLOCAL) paLpDict);

EndDialog(hwndDlg, 0);

break;

}

while(!InitSpellList(

GetDlgItem(hwndDlg, IDCOMBO), achTemp));

break;

case WM_COMMAND:

开关(LOWORD(wParam)){

case IDCOMBO:

if (HIWORD(wParam) != CBN_DBLCLK)

break;

/ *要双击,请处理OK案例。*/

case IDOK:

SendDlgItemMessage(hwndDlg,IDCOMBO,

WM_GETTEXT,sizeof(achTemp),

(LPARAM) achTemp);

SendMessage(hwndEdit,EM_REPLACESEL,0,

(LPARAM) achTemp);

/ *落下来得到下一个字。*/

case IDIGNORE:

do

if(!SelectNextWord(hwndEdit,achTemp)){

EndDialog(hwndDlg, 0);

break;

}

while(!InitSpellList(GetDlgItem(hwndDlg,

IDCOMBO), achTemp));

break;

case IDCANCEL:

EndDialog(hwndDlg, 0);

}

break;

case WM_DESTROY:

GlobalFree((HGLOBAL) lpstrDict);

LocalFree((HLOCAL) paLpDict);

break;

默认:

return FALSE;

}

return TRUE;

}

/********************************************************

功能:InitSpellList

目的:初始化选择字段和列表

对于指定的单词的建议,如果

它不在字典中。

RETURNS:如果列表被初始化,则返回

值为TRUE。如果发生错误或

词在字典中,返回

值为FALSE。

*********************************************************/

BOOL PASCAL InitSpellList(HWND hwndCombo, LPSTR lpszWord)

{

int min = 0; /* beginning of search range */

int max = cWords; /* end of search range */

int n; /* index of word */

int cmp; /* result of comparison */

char ch; /* first character in word */

ch = *lpszWord;

CharLowerBuff(&ch, 1);

/*

*对字进行二进制搜索。

*

*全局数组paLpDict包含指向字的指针

*在全局数组lpstrDict中。这两个变量是

*由OpenDictionary函数初始化。

*/

n = max / 2;

while(min < max){

cmp = lstrcmpi(lpszWord, paLpDict[n]);

if (cmp == 0)

return FALSE; /* not misspelled */

if(cmp < 0)en

max = n;

其他

min = n + 1;

n = (min + max) / 2;

}

/ *列出以与lpszWord相同的字母开头的单词。*/

SendMessage(hwndCombo, CB_RESETCONTENT, 0, 0);

while (n > 0 && *paLpDict[n - 1] == ch)

n--;

while (*paLpDict[n] == ch)

SendMessage(hwndCombo,CB_ADDSTRING,

0, (LPARAM) paLpDict[n++]);

/ *将单词放在选择字段中。*/

SendMessage(hwndCombo, WM_SETTEXT, 0, (LPARAM) lpszWord);

return TRUE;

}