转自:http://blog.youkuaiyun.com/showlong/article/details/1675197
狂郁闷ing...
昨天写的东西发出来竟然没有文字...重新编写的时候也没有看到文字...
哎狂倒啊,浪费我写了那么久.
今天还得重来...日..这个优快云怎么搞的噢?
算了.直接说怎么搞了,打字累...
因为我所说的方法是直接改HGE的内核..
所以改动的地方不多,但也不是几行代码就行了..
步骤是:
1:在 hge.h 中添加结构,用于保存我们的输入数据.
{
bool isIME;
char value[ 3 ];
};
2:在 hge.h 中添加输入数据获取接口:
3:接下来就需要一个表来存目前输入的数据了.我们采用HGE通用风格,在 hge_impl.h 中添加结构:
{
hgeIMEEvent ime;
CIMEEventList * next;
};
4:完成接口申明.在 hge_impl.h 中添加接口:
5:在 hge_impl.h 中添加数据来源及处理了.所有即时输入的数据都将保存在这里处理,但不通知你.
void _BulidIMEEvent( char key[ 3 ], bool isIME);
void _ClearIMEEvent();
6:完成上面几个接口的函数体.在 input.cpp 中添加
(欢迎转载:原创作者BLOG(ShowLong))
{
CIMEEventList* newEvent = new CIMEEventList;
newEvent->ime.isIME = isIME;
if (isIME)
{
newEvent->ime.value[0] = key[0];
newEvent->ime.value[1] = key[1];
newEvent->ime.value[2] = '/0';
}
else
{
newEvent->ime.value[0] = key[0];
newEvent->ime.value[1] = '/0';
newEvent->ime.value[2] = '/0';
}
imeEvent = newEvent;
else
{
CIMEEventList* last = imeEvent;
while (last->next)
last = last->next;
last->next = newEvent;
}
}
{
CIMEEventList *eptr;
{
eptr = imeEvent;
memcpy(ime, &eptr->ime, sizeof(hgeIMEEvent));
imeEvent = eptr->next;
delete eptr;
return true;
}
}
{
CIMEEventList* next,* ptr = imeEvent;
{
next = ptr->next;
delete ptr;
ptr = next;
}
imeEvent = 0;
}
7:查找所有调用 _ClearQueue(); 的地方.然后在其下面加上代码:
8:在 system.cpp 中找到 System_Start 函数体.将被注消掉的代码启动.下面:
9:不要忘了在构造 hge_impl 的时候写上这样一句:
10:这就是关键了. 有了上面的代码.就可以做怎么获取输入了.
在主 WindowProc 函数体的 case WM_SETCURSOR: 的下一个case 前插入代码:
{
char imeChar[3];
imeChar[0] = (char)(wparam>>8);
imeChar[1] = (char)wparam;
imeChar[2] = '/0';
pHGE->_BulidIMEEvent(imeChar, true);
}
break;
case WM_CHAR:
{
if (wparam == VK_BACK ||
wparam == VK_TAB ||
wparam == VK_RETURN ||
(char)wparam <= 0)
break;
imeChar[0] = (char)wparam;
imeChar[1] = '/0';
imeChar[2] = '/0';
pHGE->_BulidIMEEvent(imeChar, false);
}
break;
至此.所有代码就添加完成了...
如果想制作一个GUI来调用一下试试呢..行的.
只需要三句代码.
while (tKernelServer::Instance() -> Device() -> Input_GetIMEEvent( & imeEvent))
{
AddChar(imeEvent.value, imeEvent.isIME);
}
够简单吧.至于为什么imeEvent要这样定义..这里暂不做解释...如果你觉得不需要可以改的.
如果还有问题..只好来问我QQ:29774874.
或加到我的群里来:32800303