それとなくHSP>HSP関連>IMEを操作する
IMEを操作する




ウィンドウを開いているとき全角で文字を入力するとウィンドウの左上にIMEのウィンドウが出てきます。これを自由自在に操ることができると、オリジナルのエディットコントロール(インプットボックス)が作れるかも知れません。
#module
#uselib "imm32.dll"
#cfunc ImmCreateContext "ImmCreateContext"
#cfunc ImmAssociateContext "ImmAssociateContext" int, int
#func ImmSetCompositionWindow "ImmSetCompositionWindow" int,int,int
#func ImmGetCompositionString "ImmGetCompositionStringA" int,int,var,int
#func ImmSetCompositionFont "ImmSetCompositionFontA" int,int
#func ImmReleaseContext "ImmReleaseContext" int,int
#func ImmDestroyContext "ImmDestroyContext" int
#cfunc ImmGetContext "ImmGetContext" int

//ウィンドウに関係づけられたIMEのハンドルを取得
#deffunc ime_hwnd int hwnd2_
defime=ImmGetContext(hwnd_2)
return defime

//ウィンドウにIMEを割り当て
#deffunc ime_creat int hwnd3_
hwnd_ime=ImmCreateContext()
k=ImmAssociateContext(hwnd3_,hwnd_ime)
return hwnd_ime

//IMEの出現場所指定 標準0,0
#deffunc ime_pos int hwnd2_ime,int com_posx, int com_posy
compositionform = 0x0002 ,com_posx ,com_posy
ImmSetCompositionWindow hwnd2_ime,varptr(compositionform)
return

//IMEに入力された決定文字を取得
#deffunc ime_getstr int hwnd2_ime,var buf,var str_size
str_size=0
ImmGetCompositionString hwnd2_ime,$800,buf,str_size
str_size=stat
sdim buf,str_size+1
ImmGetCompositionString hwnd2_ime,$800,buf,str_size
return

//IMEに入力された決定文字を取得 リアルタイム
#deffunc ime_getstr_rt int hwnd6_ime,var buf3
buf3=""
str_size2=0
ImmGetCompositionString hwnd6_ime,$8,buf3,str_size2
str_size2=stat
sdim buf3,str_size2+1
ImmGetCompositionString hwnd6_ime,$8,buf3,str_size2
return

//IMEフォント指定
#deffunc ime_font int hwnd4_ime,str font_name,int font_size
dim logfont,20
lfFaceName =font_name
logfont(0)=font_size
poke logfont,23,1
memcpy logfont, lfFaceName, strlen(lfFaceName), 28, 0
ImmSetCompositionFont hwnd4_ime,varptr(logfont)
return

//決定さてた文字を取得しやすくする
#deffunc ime_getstrex int hwnd3_ime,var buf2
ime_getstr hwnd3_ime,buf2,s
if s=0:ss=0
if s!0&&ss=0:str1_=buf:ss=1:else :buf2=""
return

//初期化簡略関数
#deffunc ime_ini int hwnd4_, var hwnd5_ime
ime_hwnd hwnd4_
hwnd5_ime=stat
if hwnd5_ime=0{
ime_creat hwnd4_
hwnd5_ime=stat
}
return

//ウィンドウに関係づけられたIMEを削除
#deffunc ime_dest int hwnd5_
ime_ini hwnd5_, hwnd6_ime
defime=ImmGetContext(hwnd5_)
if defime!0{
    ImmReleaseContext hwnd5_,defime
    ImmDestroyContext defime
}
return
#global
//////////////////////////////////////////////////

sdim buf1,512
sdim buf2,512
sdim buf3,512

fn="":fs=14
font fn,fs                    //HSPのフォント・フォントサイズを指定する

ime_ini hwnd, hwnd_ime        //IMEを初期化
ime_font hwnd_ime,fn,fs        //IMEのフォント・フォントサイズを指定する
ime_pos hwnd_ime,0,40        //IMEの位置 X,Y

repeat
    ime_getstrex hwnd_ime,buf1//IMEで決定された文字を取得
    ime_getstr_rt hwnd_ime,buf3//IMEで入力途中の文字列を取得

    if buf1!=""{
        buf2+=buf1+"\n"
    }
    color 255,255,255:boxf:color 0,0,0
    pos 0,0
    mes "全角モードにしてください。"
    pos 0,20
    mes buf3
    pos 0,100
    mes buf2

    redraw 1
    wait 3
    redraw 0
loop

このモジュールでできることは

IMEの出現場所を任意の位置にすること
IMEで使用されるフォントを変更すること
IMEで変換決定された文字を取得すること

です。

Copyright(C)Begriff 2007-2009.
inserted by FC2 system