HOW to control the IME Window
Posted: Sat Oct 07, 2006 6:26 pm
this tutorial is based on the IrrTT.
In the Irrlicht, the IME window appears upper left.
try this code, if you think it to be strange.
In the Irrlicht, the IME window appears upper left.
try this code, if you think it to be strange.
Code: Select all
/*
This tutorial shows how to control the IME Window.
*/
#include "stdafx.h"
#include <irrlicht.h>
using namespace irr;
using namespace core;
using namespace video;
using namespace gui;
#pragma comment(lib, "Irrlicht.lib")
#pragma comment(lib, "imm32.lib")
#define ID_EDITBOX_1 101
#define ID_EDITBOX_2 102
#define WINDOW_TITLE "Irrlicht Engine - IME Window Demo"
#define WINDOW_TITLE_L L"Irrlicht Engine - IME Window Demo"
#define FONT_PATH "C:\\WINNT\\fonts\\msgothic.ttc"
class MyEventReceiver : public IEventReceiver
{
public:
virtual bool OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT)
{
s32 id = event.GUIEvent.Caller->getID();
switch(event.GUIEvent.EventType)
{
case EGET_ELEMENT_HOVERED:
// if (Device->isWindowActive())
if(id == ID_EDITBOX_1 || id == ID_EDITBOX_2)
{
HWND hwnd = FindWindow("CIrrDeviceWin32", WINDOW_TITLE);
rect<s32> box_rect = ((IGUIScrollBar*)event.GUIEvent.Caller)->getRelativePosition();
HIMC hIMC = ImmGetContext(hwnd);
COMPOSITIONFORM cf;
/* Set preedit position */
cf.dwStyle = CFS_POINT;
cf.ptCurrentPos.x = box_rect.UpperLeftCorner.X;
cf.ptCurrentPos.y = box_rect.UpperLeftCorner.Y;
ImmSetCompositionWindow(hIMC, &cf);
ImmReleaseContext(hwnd, hIMC);
}
break;
}
}
return false;
}
};
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow )
{
IrrlichtDevice* device = 0;
device = createDevice(video::EDT_OPENGL, core::dimension2d<s32>(640, 480));
if (device == 0)
return 1;
MyEventReceiver receiver;
device->setEventReceiver(&receiver);
device->setWindowCaption(WINDOW_TITLE_L);
video::IVideoDriver* driver = device->getVideoDriver();
IGUIEnvironment* env = device->getGUIEnvironment();
IGUISkin* skin = env->getSkin();
//Set font to all GUI Ellement.
c8 fontface[512] = FONT_PATH;
IGUIFont *font = (IGUIFont *)env->getFont(fontface,12);
if (font)
{
((CGUITTFont *)font)->AntiAlias = true;
skin->setFont(font);
}
env->addStaticText(L"EditBox1:", rect<s32>(150,100,210,116));
IGUIEditBox *EditBox1 = env->addEditBox(L"Edit me!!!", rect<s32>(210, 100, 490, 116), true, 0, ID_EDITBOX_1);
env->addStaticText(L"EditBox2:", rect<s32>(150,200,210,216));
IGUIEditBox *EditBox2 = env->addEditBox(L"Me, too!!!!!", rect<s32>(210, 200, 490, 216), true, 0, ID_EDITBOX_2);
while(device->run() && driver)
// if (device->isWindowActive())
{
driver->beginScene(true, true, SColor(0,200,200,200));
env->drawAll();
driver->endScene();
}
device->drop();
return 0;
}