windows客户端开发--如何修复输入法提示框位置不正确
2016-03-05 22:30
1271 查看
应该也有人会遇到这样的困扰:就是在edit或是richedit控件中输入时,输入法的提示框位置不正确。
何为HIMC ?
什么是IME (Input Method Editors)?广义上讲,IME是微软提供的Windows平台的一套输入法编程规范,依照这套规范(框架),你不需要处理太多输入法特性相关的操作(光标跟随,输入捕获,字码转换后输出到应用程序等),你只需要使用IME规范里面提供的工具函数(imm32库),实现规范所指定必须导出的接口即可。实际上你要做的就是写一个导出函数包含IME规范规定的接口的dll,所以,狭义上讲IME就是你写的这个dll。
HIMC实际上是个DWORD类型,一般在启动或关闭输入法时用到。
头文件和库:
如何获取HIMC?
通过函数:ImmGetContext
Returns the input context associated with the specified window.
An application should routinely use this function to retrieve the current input context before attempting to access information in the context.
The application must call ImmReleaseContext when it is finished with the input context.
重要的是看返回值:
Returns the handle to the input context.
结构体COMPOSITIONFORM 是干什么的?
作用:
Contains style and position information for a composition window.
原型:
GetCaretPos函数就不需要再解释了:
该函数将插入标记的位置(按客户区坐标)信息拷贝到指定的POINT结构中
ImmSetCompositionWindow函数怎样设置的?
作用:
Sets the position of the composition window.
原型:
等等,我们还没有完。
就像获得设备描述表一样,有获取,就要有释放.
ImmReleaseContext函数来释放:
作用:
此函数释放输入上下文和解锁相关联的内存。应用程序必须调用ImmReleaseContext为对应每一个ImmGetContext。
原型:
有了以上的储备,工作变得简单。
good job!
何为HIMC ?
什么是IME (Input Method Editors)?广义上讲,IME是微软提供的Windows平台的一套输入法编程规范,依照这套规范(框架),你不需要处理太多输入法特性相关的操作(光标跟随,输入捕获,字码转换后输出到应用程序等),你只需要使用IME规范里面提供的工具函数(imm32库),实现规范所指定必须导出的接口即可。实际上你要做的就是写一个导出函数包含IME规范规定的接口的dll,所以,狭义上讲IME就是你写的这个dll。
HIMC实际上是个DWORD类型,一般在启动或关闭输入法时用到。
头文件和库:
[code]#include <imm.h> #pragma comment(lib, "imm32.lib ")
如何获取HIMC?
通过函数:ImmGetContext
Returns the input context associated with the specified window.
An application should routinely use this function to retrieve the current input context before attempting to access information in the context.
The application must call ImmReleaseContext when it is finished with the input context.
重要的是看返回值:
Returns the handle to the input context.
结构体COMPOSITIONFORM 是干什么的?
作用:
Contains style and position information for a composition window.
原型:
[code]typedef struct tagCOMPOSITIONFORM { DWORD dwStyle; POINT ptCurrentPos; RECT rcArea; } COMPOSITIONFORM, *PCOMPOSITIONFORM;
GetCaretPos函数就不需要再解释了:
该函数将插入标记的位置(按客户区坐标)信息拷贝到指定的POINT结构中
ImmSetCompositionWindow函数怎样设置的?
作用:
Sets the position of the composition window.
原型:
[code]BOOL ImmSetCompositionWindow( _In_ HIMC hIMC, _In_ LPCOMPOSITIONFORM lpCompForm );
等等,我们还没有完。
就像获得设备描述表一样,有获取,就要有释放.
ImmReleaseContext函数来释放:
作用:
此函数释放输入上下文和解锁相关联的内存。应用程序必须调用ImmReleaseContext为对应每一个ImmGetContext。
原型:
[code]BOOL ImmReleaseContext( HWND hWnd, HIMC hIMC );
有了以上的储备,工作变得简单。
[code]if (uMsg == WM_IME_COMPOSITION) { HIMC hIMC = ImmGetContext(m_hWnd);//获取 if (hIMC) { // Set composition window position near caret position POINT point; GetCaretPos(&point);//获取输入光标位置,存入point结构体 COMPOSITIONFORM Composition; Composition.dwStyle = CFS_POINT; Composition.ptCurrentPos.x = point.x; Composition.ptCurrentPos.y = point.y; ImmSetCompositionWindow(hIMC, &Composition);//设置 ImmReleaseContext(m_hWnd, hIMC);//释放 } }
good job!
相关文章推荐
- php显示判断数组是不是带下标的二维数组
- 项目开发环境搭建手记(5.Jenkins搭建)
- Nokia 5110 LCD资料
- 版本控制SVN的使用笔记
- Python Select 解析
- noj1044(并查集)
- Ubuntu run in Raspberry pi 2 之SD 卡镜像篇(ROS开发准备)
- imageView属性介绍
- HDU 5636 Shortest Path 暴力
- 加_T的原因
- 学习JAVA环境搭建之下载安装MyEclipse 6.5
- 提示:正弦曲线资料
- 【leetcode】第7题:逆转数字
- android之textview属性介绍
- iOS网络判断
- ajax学习第一天——基于jquery的简单应用
- Java内存区域,内存溢出,内存泄漏
- Android Material Design学习之四CardView
- 2016年是我的新起点?
- 文件加密——可执行,较复杂的抽取(限文本)