Sign in to follow this  
Followers 0
PaulOBrien

Problem switching input methods

5 posts in this topic

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

MoDaCo is part of the MoDaCo.network, © Paul O'Brien 2002-2016. MoDaCo uses IntelliTxt technology.