Reputation: 21
Can I change the default language of my host system (Windows XP) with a Java application? If yes, how I can do it?
Upvotes: 2
Views: 800
Reputation: 57707
You can set the default input language using the Windows SystemParametersInfo API.
BOOL WINAPI SystemParametersInfo(
__in UINT uiAction,
__in UINT uiParam,
__inout PVOID pvParam,
__in UINT fWinIni
);
Using JNA is much easier than using JNI. To invoke this API function in User32.dll using JNA, create an interface:
public interface User32 extends StdCallLibrary
{
User32 INSTANCE = (User32) Native.loadLibrary("user32", User32.class);
bool SystemParametersInfo(int uiAction, int uiParam, int[] pInt, int fWinIni);
}
You determine the LCID of the language you want to change to. (Here's the list from MSDN.) For example, English is 0x409. An then use the LCID in the call to SystemParametersInfo
:
int lcid = 0x409;
final int SPI_SETDEFAULTINPUTLANG = 90;
User32.INSTANCE.SystemParamtersInfo(SPI_SETDEFAULTINPUTLANG, 0, new int[] { lcid }, 0);
And thenn your default input language has been changed!
Upvotes: 5