Jump to content

Problem switching input methods


Guest PaulOBrien

Recommended Posts

Guest Paul [MVP]

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

Guest NeilC_MVP

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

Guest Paul [MVP]

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

  • 2 months later...
Guest jemmitch

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

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.