Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / February 2008

Tip: Looking for answers? Try searching our database.

Windos hooking and messages

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Ofry - 20 Feb 2008 07:40 GMT
Hi,
I'm writing a c# application and I would like to know every time the input
language changes.
I have this code:
InputLanguage myCurrentLanguage = InputLanguage.CurrentInputLanguage;
String lang = myCurrentLanguage.Culture.TwoLetterISOLanguageName;
That gives me the current language, but I want to be notyfied whenever it
changes and not check every few seconds.

I've found a windows message WM_INPUTLANGUAGECHANGE, where do I need to hook
to in order to get this message?
Is there a better way? maybe another event I'm not aware of

Thanks,
Ofry
Mufaka - 20 Feb 2008 08:16 GMT
If you are writing a forms application, Form has an event handler for this.

http://msdn2.microsoft.com/en-us/library/system.windows.forms.inputlanguagechang
edeventargs.aspx


> Hi,
> I'm writing a c# application and I would like to know every time the input
[quoted text clipped - 11 lines]
> Thanks,
> Ofry
Ofry - 20 Feb 2008 08:25 GMT
Thanks, but this event rises only on input language change in my form, I want
to know every time the user changes his language, even if it is in another
form / window / process.

> If you are writing a forms application, Form has an event handler for this.
>
[quoted text clipped - 16 lines]
> > Ofry
> >  
Willy Denoyette [MVP] - 20 Feb 2008 10:24 GMT
> Thanks, but this event rises only on input language change in my form, I
> want
> to know every time the user changes his language, even if it is in another
> form / window / process.

Don't know what you mean by this, the "InputLanguageChanged" event is raised
when the *user* changes the input language at the system level, all windows
application running in the users login session will get this event (a
windows message WM_INPUTLANGCHANGE) when the user changes the input
language.

Consider following sample:

using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Threading;

public class Form1 : System.Windows.Forms.Form
{
   Label lbl = new Label();
   public Form1()
   {
       this.Controls.Add(lbl);
       lbl.Size = new Size(400, 48);
       lbl.Padding = new Padding(5);
       // uncomment if you want to handle the event in the
InputLanguageChangedEventHandler
       //this.InputLanguageChanged += new
InputLanguageChangedEventHandler(languageChange);
   }
   private void languageChange(Object sender, InputLanguageChangedEventArgs
e)
   {
       lbl.Text = e.InputLanguage.Culture.ToString();
   }
   protected override void WndProc(ref Message m)
       {
           if(m.Msg == 0x0051) // WM_INPUTLANGCHANGE
           {
               lbl.Text = string.Format("Posting Thread: {0} \n{1}",
Thread.CurrentThread.ManagedThreadId, m);
           }
           base.WndProc(ref m);
       }
   public static void Main(string[] args)
   {
       Application.Run(new Form1());
   }
}

This illustrates how you can add your own handler by overriding WndProc, or
using the predefined handler for this message, however, both handle the same
message!.

Willy.
Peter Duniho - 20 Feb 2008 08:32 GMT
> [...]
> I've found a windows message WM_INPUTLANGUAGECHANGE, where do I need to  
> hook
> to in order to get this message?
> Is there a better way? maybe another event I'm not aware of

I'm not aware of a built-in .NET event that would pass along that  
message.  However, you can always override the WndProc() method in your  
Control-inheriting class to catch window messages sent to the control or  
form.

There is also the IMessageFilter interface, but it's really intended for a  
different purpose and is probably overkill for this goal.

Pete
Ofry - 20 Feb 2008 08:44 GMT
Hi Peter, thanks,
to use the WndProc(), I have to have a running form right? But I want to
listen from a process that has no open form.

> > [...]
> > I've found a windows message WM_INPUTLANGUAGECHANGE, where do I need to  
[quoted text clipped - 11 lines]
>
> Pete
Peter Duniho - 20 Feb 2008 09:03 GMT
> Hi Peter, thanks,
> to use the WndProc(), I have to have a running form right? But I want to
> listen from a process that has no open form.

Sorry.  I didn't see anything in your original message that said that.

You may have to go with p/invoke.  I'm not really sure.  I don't know of a  
managed way to hook window messages generally.

If there's a way to do it in managed code, there are at least a couple of  
other people who read this newsgroup that are more familiar with such  
things and would know.  Hopefully they'll see this thread and reply.

Pete

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.