public static extern bool ImmSetCandidateWindow(IntPtr hIMC, ref CANDIDATEFORM lpCandidate);
public static int ImmSetCandidateWindow(IntPtr himc, ref CANDIDATEFORM lpCandidateForm) { NotImplemented(MethodBase.GetCurrentMethod()); return(0); }
public static extern int ImmSetCandidateWindow(IntPtr hIMC, ref CANDIDATEFORM lpCandidateForm);
public static extern int ImmSetCandidateWindow(IntPtr hIMC, [MarshalAs(UnmanagedType.Struct)] ref CANDIDATEFORM lpCandidateForm);
public static extern bool ImmSetCandidateWindow(IntPtr hIMC, ref CANDIDATEFORM candidateForm);
protected override void WndProc(ref Message m) { switch (m.Msg) { case WM_IME_STARTCOMPOSITION: _ime = new TerminalChars(this, Color.Red, Color.Transparent, cols, lines); return; case WM_IME_ENDCOMPOSITION: _ime = null; Invalidate(); return; case WM_IME_COMPOSITION: if (_ime != null) { IntPtr hIMC = ImmGetContext(Handle); if ((((int)m.LParam) & GCS_COMPSTR) != 0) { int dwSize = ImmGetCompositionString(hIMC, GCS_COMPSTR, null, 0); byte[] bs = new byte[dwSize]; ImmGetCompositionString(hIMC, GCS_COMPSTR, bs, bs.Length); string str = UnicodeEncoding.Unicode.GetString(bs); _ime.clear(); _ime.cursor = _chars._cursor; _ime.bg = Color.Black; _ime.fg = Color.Red; foreach (char c in str) { _ime.put(c, 0); } _ime.bg = Color.Transparent; _ime.fg = Color.Red; } if ((((int)m.LParam) & GCS_CURSORPOS) != 0) { _ime.cursor = _chars._cursor; for (int pos = ImmGetCompositionString(hIMC, GCS_CURSORPOS, null, 0); pos != 0; --pos) { _ime.advanceVisible(); } } CANDIDATEFORM l = new CANDIDATEFORM(); l.dwIndex = 0; l.dwStyle = CFS_CANDIDATEPOS; l.ptCurrentPos.X = (int)(10 + _ime.cursor.col * Font.Size.Width); l.ptCurrentPos.Y = (int)(10 + _ime.cursor.line * Font.Size.Height); ImmSetCandidateWindow(hIMC, ref l); ImmReleaseContext(Handle, hIMC); } base.WndProc(ref m); return; default: base.WndProc(ref m); return; } }
private void MoveImeWindow(IntPtr windowHandle, IntPtr immContext, Point p) { var x = p.X; var y = p.Y; // As written in a comment in ImeInput::CreateImeWindow(), // Chinese IMEs ignore function calls to ::ImmSetCandidateWindow() // when a user disables TSF (Text Service Framework) and CUAS (Cicero // Unaware Application Support). // On the other hand, when a user enables TSF and CUAS, Chinese IMEs // ignore the position of the current system caret and uses the // parameters given to ::ImmSetCandidateWindow() with its 'dwStyle' // parameter CFS_CANDIDATEPOS. // Therefore, we do not only call ::ImmSetCandidateWindow() but also // set the positions of the temporary system caret if it exists. var candidatePosition = new CANDIDATEFORM { dwIndex = 0, rcArea = new RECT { bottom = 0, left = 0, right = 0, top = 0 }, dwStyle = NativeConstants.CFS_CANDIDATEPOS, ptCurrentPos = new POINT(x, y + 10) }; var size = Marshal.SizeOf(candidatePosition); var cfPtr = Marshal.AllocHGlobal(size); Marshal.StructureToPtr(candidatePosition, cfPtr, true); var result = SafeNativeMethods.ImmSetCandidateWindow(immContext, cfPtr); Marshal.DestroyStructure(cfPtr, typeof(CANDIDATEFORM)); #region Chinese/Korean /*if (system_caret_) * { * switch (PRIMARYLANGID(input_language_id_)) * { * case LANG_JAPANESE: * SetCaretPos(x, y + caret_rect_.height()); * break; * default: * SetCaretPos(x, y); * break; * } * } * if (PRIMARYLANGID(input_language_id_) == LANG_KOREAN) * { * // Chinese IMEs and Japanese IMEs require the upper-left corner of * // the caret to move the position of their candidate windows. * // On the other hand, Korean IMEs require the lower-left corner of the * // caret to move their candidate windows. * y += kCaretMargin; * }*/ #endregion // Japanese IMEs and Korean IMEs also use the rectangle given to // ::ImmSetCandidateWindow() with its 'dwStyle' parameter CFS_EXCLUDE // to move their candidate windows when a user disables TSF and CUAS. // Therefore, we also set this parameter here. var excludeRectangle = new CANDIDATEFORM { dwIndex = 0, dwStyle = NativeConstants.CFS_EXCLUDE, ptCurrentPos = new POINT(x, y + 10), rcArea = new RECT { left = x, top = y + 10, right = x + 10, bottom = y + this._textView.LineHeight + 10 } }; var size2 = Marshal.SizeOf(excludeRectangle); var cfPtr2 = Marshal.AllocHGlobal(size2); Marshal.StructureToPtr(excludeRectangle, cfPtr2, true); var result2 = SafeNativeMethods.ImmSetCandidateWindow(immContext, cfPtr2); Marshal.DestroyStructure(cfPtr2, typeof(CANDIDATEFORM)); //ImmSetCandidateWindow(imm_context, exclude_rectangle); }