Guest Paul [MVP] Posted September 2, 2003 Report Share Posted September 2, 2003 Can anyone give me an idea why the following code doesn't correctly switch input methods when called? Cheers, P Enum InputMode As Integer IM_SPELL = &H0 IM_AMBIG = &H1 IM_NUMBERS = &H2 End Enum _ Public Shared Function GetCapture() As IntPtr End Function Sub SetInputMode(ByVal InputMode As InputMode, ByVal Control As Windows.Forms.Control) Const EM_SETINPUTMODE As Integer = &HDE Dim wparam As New IntPtr(0) Dim lparam As New IntPtr(InputMode) Dim message As New Microsoft.WindowsCE.Forms.Message Dim container As New Microsoft.WindowsCE.Forms.MessageWindow Control.Capture = True Dim hWnd As IntPtr = GetCapture() Control.Capture = False message.Create(hWnd, EM_SETINPUTMODE, wparam, lparam) container.PostMessage(message) End Sub Link to comment Share on other sites More sharing options...
Guest NeilC_MVP Posted September 4, 2003 Report Share Posted September 4, 2003 I think your problem lies with this line: message.Create(hWnd, EM_SETINPUTMODE, wparam, lparam) Create is a shared method in the Message class, and you are try to call it from an instance of the Message class. This is not allowed. The reason why it seems to work, that is, no errors, is because you have given your instance paramater (message) the same name as the Message class, and since your coding in VB .NET, the compiler makes no beef about it. Try this instead: Enum InputMode As Integer IM_SPELL = &H0 IM_AMBIG = &H1 IM_NUMBERS = &H2 End Enum _ Public Shared Function GetFocus() As IntPtr End Function Sub SetInputMode(ByVal InputMode As InputMode, ByVal Control As Windows.Forms.Control) Const EM_SETINPUTMODE As Integer = &HDE Dim wparam As New IntPtr(0) Dim lparam As New IntPtr(InputMode) Dim msg As New Microsoft.WindowsCE.Forms.Message Dim container As New Microsoft.WindowsCE.Forms.MessageWindow Control.Capture = True Dim hWnd As IntPtr = GetFocus() Control.Capture = False msg = Microsoft.WindowsCE.Forms.Message.Create(hWnd, EM_SETINPUTMODE, wparam, lparam) container.PostMessage(ByRef msg) End Sub Link to comment Share on other sites More sharing options...
Guest Paul [MVP] Posted September 5, 2003 Report Share Posted September 5, 2003 Cheers, that works a treat, although the lines Control.Capture = True Control.Capture = False can be omitted as we are getting the hWnd of the currently focused object rather than capturing one, hence also there is no need to pass object details on the function parameters. Wonder why GetCapture doesn't work? Ah well! Cheers! P Link to comment Share on other sites More sharing options...
Guest NeilC_MVP Posted September 6, 2003 Report Share Posted September 6, 2003 That's very true. I was just being lazy in not trimming the code :) It may well work witih GetCapture, I just haven't tried that. Link to comment Share on other sites More sharing options...
Guest jemmitch Posted December 5, 2003 Report Share Posted December 5, 2003 this is the c# version of the code: using System; using System.Windows.Forms; using System.Runtime.InteropServices; using Microsoft.WindowsCE.Forms; namespace somenamespace { public class Forms { [DllImport("coredll")] public static extern IntPtr GetFocus(); public enum InputMode {IM_SPELL = 0x0, IM_AMBIG = 0x1, IM_NUMBERS = 0x2}; public Forms() { } public static void SetInputMode(InputMode InputMode, System.Windows.Forms.Control Control) { const int EM_SETINPUTMODE = 0xDE; IntPtr wparam = new IntPtr(0); IntPtr lparam = new IntPtr((int)InputMode); Message msg = new Message(); IntPtr hWnd = GetFocus(); msg = Microsoft.WindowsCE.Forms.Message.Create(hWnd, EM_SETINPUTMODE, wparam, lparam); MessageWindow.PostMessage(ref msg); } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now