WNDPROC s_pOldProc = NULL;
LRESULT CALLBACK CImeFilterDlg::SubProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
switch (Msg)
{
case WM_IME_NOTIFY:
if(wParam==IMN_OPENCANDIDATE || wParam==IMN_CHANGECANDIDATE )
{
HIMC hIMC = ::ImmGetContext(hWnd);
if(hIMC != NULL)
{
DWORD dwSize = 0;
::ImmGetCandidateListCount(hIMC, &dwSize);
for(UINT32 i=0; i<dwSize; ++i)
{
if((dwSize=::ImmGetCandidateList(hIMC, i, NULL, 0)) > 0)
{
LPCANDIDATELIST lpList = (LPCANDIDATELIST)new CHAR[dwSize];
if (lpList == NULL)
{
continue;
}
lpList->dwSize = sizeof(CANDIDATELIST);
dwSize = ::ImmGetCandidateList(hIMC, i, lpList, dwSize);
if(lpList->dwCount > 0)
{
DWORD dwStart = lpList->dwPageStart;
DWORD dwEnd = lpList->dwPageStart+lpList->dwPageSize > lpList->dwCount
? lpList->dwCount : lpList->dwPageStart+lpList->dwPageSize;
CString data = (CString)(LPCWSTR)((PBYTE)lpList + lpList->dwOffset[dwStart]);
for (UINT32 j = dwStart+1; j< dwEnd; j++)
{
LPCWSTR lpszString = (LPCWSTR)((PBYTE)lpList + lpList->dwOffset[j]);
data += TEXT(" ");
data += (CString)lpszString;
}
((CImeFilterDlg *)AfxGetMainWnd())->SetDlgItemText(IDC_LBLCANDIDATE, data);
data = (CString)(LPCWSTR)((PBYTE)lpList + lpList->dwOffset[lpList->dwSelection]);
((CImeFilterDlg *)AfxGetMainWnd())->SetDlgItemText(IDC_LBLCURCAND, data);
}
delete []lpList;
}
}
::ImmReleaseContext(hWnd, hIMC);
}
}
else if(wParam == IMN_CLOSECANDIDATE)
{
((CImeFilterDlg *)AfxGetMainWnd())->SetDlgItemText(IDC_LBLCANDIDATE, TEXT("输入法候选项..."));
((CImeFilterDlg *)AfxGetMainWnd())->SetDlgItemText(IDC_LBLCURCAND, TEXT("当前候选项..."));
}
break;
default:
break;
}
return CallWindowProc(s_pOldProc, hWnd, Msg, wParam, lParam);
}
s_pOldProc = (WNDPROC)(INT64)::SetWindowLong(GetDlgItem(IDC_EDIT1)->GetSafeHwnd(), GWL_WNDPROC, (LONG)(INT64)SubProc);