LoginSignup
3
2

More than 3 years have passed since last update.

【C#】IMEの入力を受けるユーザーコントロールの作成(補足)

Last updated at Posted at 2019-10-05

はじめに

C#でIMEの入力を受けるユーザーコントロールの作成
https://qiita.com/takao_mofumofu/items/24c060a1d4f6b3df5c73

この記事の補足です。IMEウィンドウの表示位置に加えIMEウィンドウの表示領域の設定方法です。
元のソースに // 追加コード ってところを追加します。

コード

// 追加コード
const uint CFS_RECT = 0x0001;

// 変更箇所
case WM_IME_STARTCOMPOSITION: {
    //入力コンテキストにアクセスするためのお約束
    IntPtr hImc = ImmGetContext(this.Handle);

    //コンポジションウィンドウの位置を設定
    COMPOSITIONFORM info = new COMPOSITIONFORM();
    info.dwStyle = CFS_POINT;
    info.ptCurrentPos.x = 10;
    info.ptCurrentPos.y = 10;
    ImmSetCompositionWindow(hImc, ref info);

    // 追加コード(IMEウィンドウ領域の設定)
    info.dwStyle = CFS_RECT;
    info.rcArea._Left = 10;
    info.rcArea._Top = 10;
    info.rcArea._Right = 100;
    info.rcArea._Bottom = 100;
    ImmSetCompositionWindow(hImc, ref info);

    //コンポジションウィンドウのフォントを設定
    //ImmSetCompositionFont(hImc, m_Focus->GetFont()->GetInfoLog());

    //入力コンテキストへのアクセスが終了したらロックを解除する
    ImmReleaseContext(Handle, hImc);

    base.WndProc(ref m);
    break;

実行結果

「CFS_RECT」指定無しの場合

指定した位置から表示される
image.png

「CFS_RECT」指定有りの場合

指定した位置と領域に表示される
image.png

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2