//IMEUI.C
#include <assert.h>
#include <windows.h>
#include <imm.h>
#include "fullime.h"
static DWORD CompColor[ 4 ] = { RGB( 255, 0, 0 ),
RGB( 255, 0 , 255 ),
RGB( 0, 0, 255 ),
RGB( 0, 255, 0 ) };
//**********************************************************************
//
// void ImeUIStartComposition()
//
// This handles WM_IME_STARTCOMPOSITION message.
//
//**********************************************************************
void ImeUIStartComposition( HWND hwnd )
{
// Change caption title to DBCS composition mode.
SetWindowText( hwnd, (LPSTR)szSteCompTitle );
// Reset global variables.
gImeUIData.uCompLen = 0; // length of composition string.
gImeUIData.ImeState |= IME_IN_COMPOSITION;
}
//**********************************************************************
//
// void ImeUIComposition()
//
// This handles WM_IME_COMPOSITION message. It here just handles
// composition string and result string. For normal case, it should
// examine all posibile flags indicated by CompFlag, then do some
// actitions to reflect what kinds of composition info. IME conversion
// engine informs.
//
//**********************************************************************
void ImeUIComposition( HWND hwnd, WPARAM wParam, LPARAM CompFlag )
{
if ( CompFlag & GCS_RESULTSTR ) GetResultStr( hwnd );
else
{
if ( CompFlag & GCS_COMPSTR ) GetCompositionStr( hwnd, CompFlag );
}
}
//**********************************************************************
//
// void GetCompositionStr()
//
// This handles WM_IME_COMPOSITION message with GCS_COMPSTR flag on.
//
//**********************************************************************
void GetCompositionStr( HWND hwnd, LPARAM CompFlag )
{
DWORD dwBufLen; // Stogare for len. of composition str
LPSTR lpCompStr; // Pointer to composition str.
HIMC hIMC; // Input context handle.
HLOCAL hMem; // Memory handle.
LPSTR lpCompStrAttr; // Pointer to composition str array.
HLOCAL hMemAttr; // Memory handle for comp. str. array.
DWORD dwBufLenAttr;
// If fail to get input context handle then do nothing.
// Applications should call ImmGetContext API to get
// input context handle.
if ( !( hIMC = ImmGetContext( hwnd ) ) ) return;
// Determines how much memory space to store the composition string.
// Applications should call ImmGetCompositionString with
// GCS_COMPSTR flag on, buffer length zero, to get the bullfer
// length.
if ( ( dwBufLen = ImmGetCompositionString( hIMC, GCS_COMPSTR,
(void FAR*)NULL, 0l ) ) < 0 )
{
goto exit2;
}
// Allocates memory with dwBufLen+1 bytes to store the composition
// string. Here we allocale on more byte to put null character.
if ( !( hMem = LocalAlloc( LPTR, (int)dwBufLen + 1 ) ) ) goto exit2;
if ( !( lpCompStr = (LPSTR) LocalLock( hMem ) ) ) goto exit1;
// Reads in the composition string.
ImmGetCompositionString( hIMC, GCS_COMPSTR, lpCompStr, dwBufLen );
// Null terminated.
lpCompStr[ dwBufLen ] = 0;
// If GCS_COMPATTR flag is on, then we need to take care of it.
if ( CompFlag & GCS_COMPATTR )
{
if ( ( dwBufLenAttr = ImmGetCompositionString( hIMC, GCS_COMPATTR,
( void FAR *)NULL, 0l ) ) < 0 )
{
goto nothing;
}
// Allocate memory to store attributes of composition strings.
if ( !( hMemAttr = LocalAlloc( LPTR, (int)dwBufLenAttr + 1 ) ) )
{
goto nothing;
}
if ( !( lpCompStrAttr = (LPSTR) LocalLock( hMemAttr ) ) )
{
LocalFree( hMemAttr );
goto nothing;
}
// Reads in the attribute array.
ImmGetCompositionString( hIMC, GCS_COMPATTR, lpCompStrAttr, dwBufLenAttr );
lpCompStrAttr[ dwBufLenAttr ] = 0;
}
else
{
nothing:
lpCompStrAttr = NULL;
}
// Display new composition chars.
DisplayCompString( hwnd, lpCompStr, lpCompStrAttr );
// Keep the length of the composition string for using later.
gImeUIData.uCompLen = (UINT)dwBufLen;
LocalUnlock( hMem );
if ( lpCompStrAttr )
{
LocalUnlock( hMemAttr );
LocalFree( hMemAttr );
}
exit1:
LocalFree( hMem );
exit2:
ImmReleaseContext( hwnd, hIMC );
}
//***********************************************************************
//
// void GetResultStr()
//
// This handles WM_IME_COMPOSITION with GCS_RESULTSTR flag on.
//
//***********************************************************************
void GetResultStr( HWND hwnd )
{
DWORD dwBufLen; // Storage for length of result str.
LPSTR lpResultStr; // Pointer to result string.
HIMC hIMC; // Input context handle.
HLOCAL hMem; // Memory handle.
// If fail to get input context handle then do nothing.
if ( !( hIMC = ImmGetContext( hwnd ) ) ) return;
// Determines how much memory space to store the result string.
// Applications should call ImmGetCompositionString with
// GCS_RESULTSTR flag on, buffer length zero, to get the bullfer
// length.
if ( ( dwBufLen = ImmGetCompositionString( hIMC, GCS_RESULTSTR,
(void FAR *)NULL, (DWORD) 0 ) ) <= 0 )
{
goto exit2;
}
// Allocates memory with dwBufLen+1 bytes to store the result
// string. Here we allocale on more byte to put null character.
if ( !( hMem = LocalAlloc( LPTR, (int)dwBufLen + 1 ) ) ) goto exit2;
if ( !( lpResultStr = (LPSTR) LocalLock( hMem ) ) ) goto exit1;
// Reads in the result string.
ImmGetCompositionString( hIMC, GCS_RESULTSTR, lpResultStr, dwBufLen );
// Displays the result string.
DisplayResultString( hwnd, lpResultStr );
LocalUnlock( hMem );
exit1:
LocalFree( hMem );
exit2:
ImmReleaseContext( hwnd, hIMC );
}
//**********************************************************************
//
// void ImeUIEndComposition
//
// This handles WM_IME_ENDCOMPOSITION message.
//
//**********************************************************************
void ImeUIEndComposition( HWND hwnd )
{
RECT rect;
// Change caption title to normal
SetWindowText( hwnd, (LPSTR)szSteTitle );
// Update client area.
GetClientRect( hwnd, (LPRECT)&rect );
InvalidateRect( hwnd, (LPRECT)&rect, FALSE );
// Reset the length of composition string to zero.
gImeUIData.uCompLen = 0;
gImeUIData.ImeState &= ~IME_IN_COMPOSITION;
}
//**********************************************************************
//
// BOOL ImeUINotify()
//
// This handles WM_IME_NOTIFY message.
//
//**********************************************************************
BOOL ImeUINotify( HWND hwnd, WPARAM wParam, LPARAM lParam )
{
switch (wParam )
{
case IMN_OPENCANDIDATE:
ImeUIOpenCandidate( hwnd, lParam );
break;
case IMN_CLOSECANDIDATE:
ImeUICloseCandidate( hwnd, lParam );
break;
case IMN_CHANGECANDIDATE:
ImeUIChangeCandidate( hwnd, lParam );
break;
case IMN_SETOPENSTATUS:
ImeUISetOpenStatus( hwnd );
break;
default:
return FALSE;
}
return TRUE;
}
//**********************************************************************
//
// void ImeUIOpenCandidate()
//
// This handles WM_IME_NOTIFY message with wParam = IMN_OPENCANDIDATE.
//
//**********************************************************************
void ImeUIOpenCandidate( HWND hwnd, LPARAM CandList )
{
HIMC hIMC; // Input context handle.
LPCANDIDATELIST lpCandList; // Storage for LP to candidate list.
DWORD dwBufLen; // St
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
微软输入法编程例子.zip (54个子文件)
微软输入法编程例子
IMEAPPS
MAKEFILEM 2KB
TOOLBAR.BMP 4KB
IMEAPPS.ICO 766B
IMEAPPS.ncb 89KB
WAPI.H 1KB
IMEMENU.C 7KB
MAKEFILE 1KB
IMEAPPS.H 4KB
MAKEFILEW 2KB
SUBS.C 2KB
MAKEFILEA 2KB
RESOURCE.H 2KB
TOOLBAR.C 8KB
WSUBS.C 869B
PAINT.C 11KB
TOOLBAR.H 114B
PCH.H 132B
MODE.C 5KB
IMEAPPS.DSP 5KB
DATA.C 1KB
STATUS.C 6KB
IMEAPPS.opt 51KB
COMP.C 14KB
SETCOMP.C 5KB
IMEAPPS.C 18KB
IMEAPPS.RCV 676B
IMEAPPS.APS 42KB
IMEAPPS.RC 4KB
IMEAPPS.DSW 539B
IMEAPPS.PLG 7KB
IME
HalfIme
halfime.h 232B
HalfIme.ncb 41KB
resource.h 963B
HalfIme.dsw 539B
Script1.aps 33KB
Script1.rc 3KB
Main.c 29KB
icon1.ico 766B
HalfIme.dsp 4KB
HalfIme.plg 1KB
HalfIme.opt 49KB
FullIme
FullIme.opt 49KB
resource.h 1KB
Script1.aps 33KB
Script1.rc 3KB
Main.c 29KB
icon1.ico 766B
ImeUI.c 30KB
CanUI.c 4KB
FullIme.plg 2KB
FullIme.dsp 4KB
FullIme.dsw 539B
FullIme.ncb 49KB
fullime.h 2KB
共 54 条
- 1
schlafenhamster
- 粉丝: 2516
- 资源: 131
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
前往页