Jump to content


Photo

Problem switching input methods

- - - - -

  • Please log in to reply
4 replies to this topic

#1
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,344 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
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

  • 0

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#2
NeilC_MVP

NeilC_MVP

    Newbie

  • Members
  • Pip
  • 44 posts
  • Location:Llanberis, Gwynedd, UK
  • Interests:C#, .NET Compact Framework, Smartphones, Pocket PCs, rock climbing, mountaineering, mountain biking
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

  • 0
Neil Cowburn
Microsoft MVP (.NET Compact Framework)

www.opennetcf.org | http://blog.opennetcf.org/ncowburn/

#3
PaulOBrien

PaulOBrien

    It's My Party

  • Founder
  • PipPipPipPipPipPip
  • 36,344 posts
  • Gender:Male
  • Location:Norwich, UK
  • Devices:All the Nexus!
  • Twitter:@paulobrien
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

  • 0

You can follow me on Twitter - http://twitter.com/paulobrien / Follow MoDaCo on Twitter - http://twitter.com/modaco

Want to donate? MoDaCo is raising money for the Multiple Sclerosis society.

Posted Image


#4
NeilC_MVP

NeilC_MVP

    Newbie

  • Members
  • Pip
  • 44 posts
  • Location:Llanberis, Gwynedd, UK
  • Interests:C#, .NET Compact Framework, Smartphones, Pocket PCs, rock climbing, mountaineering, mountain biking
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.

  • 0
Neil Cowburn
Microsoft MVP (.NET Compact Framework)

www.opennetcf.org | http://blog.opennetcf.org/ncowburn/

#5
jemmitch

jemmitch

    Newbie

  • Members
  • Pip
  • 2 posts
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);
}
}
}

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users