unsafe private IntPtr HandleIMR_DocumnetFeed(IntPtr lParam) { ImeDocumentFeedEventArgs e = new ImeDocumentFeedEventArgs(); this.ImeDocumentFeed(this, e); if (lParam.ToInt32() != 0) { if (e.pos > e.Pragraph.Length) { e.pos = e.Pragraph.Length; } else if (e.pos < 0) { e.pos = 0; } RECONVERTSTRING *reconv = (RECONVERTSTRING *)lParam.ToPointer(); char * paragraph = (char *)((byte *)reconv + sizeof(RECONVERTSTRING)); reconv->dwSize = (uint)sizeof(RECONVERTSTRING); reconv->dwVersion = 0; reconv->dwStrLen = (uint)e.Pragraph.Length; reconv->dwStrOffset = (uint)sizeof(RECONVERTSTRING); reconv->dwCompStrLen = 0; reconv->dwCompStrOffset = 0; reconv->dwTargetStrLen = 0; reconv->dwTargetStrOffset = (uint)e.pos * sizeof(char); for (int i = 0; i < e.Pragraph.Length; i++) { paragraph[i] = e.Pragraph[i]; } } return(new IntPtr(sizeof(RECONVERTSTRING) + e.Pragraph.Length * sizeof(char))); }
static void SetIMEString(string str) { unsafe { uint len = 0; RECONVERTSTRING *reconv = (RECONVERTSTRING *)Marshal.AllocHGlobal( sizeof(RECONVERTSTRING) + Encoding.Unicode.GetByteCount(str) + 1); char *paragraph = (char *)((byte *)reconv + sizeof(RECONVERTSTRING)); reconv->dwSize = (uint)sizeof(RECONVERTSTRING) + (uint)Encoding.Unicode.GetByteCount(str) + 1; reconv->dwVersion = 0; reconv->dwStrLen = (uint)str.Length; reconv->dwStrOffset = (uint)sizeof(RECONVERTSTRING); reconv->dwCompStrLen = 0; reconv->dwCompStrOffset = len * sizeof(char); reconv->dwTargetStrLen = 0; reconv->dwTargetStrOffset = len * sizeof(char); for (int i = 0; i < str.Length; i++) { paragraph[i] = str[i]; } ImmSetCompositionStringW(hIMC, SCS_SETRECONVERTSTRING, (IntPtr)reconv, sizeof(RECONVERTSTRING) + Encoding.Unicode.GetByteCount(str) + 1, 0, 0); } }
unsafe private IntPtr HandleIMR_ReconvertString(IntPtr lParam) { ImeReconvertStringEventArgs e = new ImeReconvertStringEventArgs(); this.ImeReconvert(this, e); RECONVERTSTRING *reconv = (RECONVERTSTRING *)lParam.ToPointer(); char * paragraph = (char *)((byte *)reconv + sizeof(RECONVERTSTRING)); int reconvlen = sizeof(RECONVERTSTRING) + e.TargetString.Length * sizeof(char); if (reconv != null) { reconv->dwSize = (uint)sizeof(RECONVERTSTRING); reconv->dwVersion = 0; reconv->dwStrLen = (uint)e.TargetString.Length; reconv->dwStrOffset = (uint)sizeof(RECONVERTSTRING); reconv->dwTargetStrLen = 0; reconv->dwTargetStrOffset = 0; for (int i = 0; i < e.TargetString.Length; i++) { paragraph[i] = e.TargetString[i]; } if (e.AutoAdjust) { IntPtr ime = ImmGetContext(this.Handle); ImmSetCompositionStringW(ime, SCS_QUERYRECONVERTSTRING, reconv, (uint)reconvlen, (void *)IntPtr.Zero, 0); ImmReleaseContext(this.Handle, ime); this.ImeQueryReconvert(this, new ImeQueryRecovertStringEventArgs((int)reconv->dwTargetStrOffset, (int)reconv->dwTargetStrLen)); } else { reconv->dwCompStrLen = (uint)e.TargetString.Length; reconv->dwCompStrOffset = 0; } this.Location = e.CaretPostion; } return(new IntPtr(reconvlen)); }