?
Solved

Code to set Default Keyboard Layout

Posted on 2000-05-03
6
Medium Priority
?
602 Views
Last Modified: 2013-12-03
Hi,

I need to programmatically set the default keyboard layout.  I've looked around a little at the LoadKeyboardLayout, ActivateKeyboardLayout,  GetKeyboardLayoutList APIs but can't figure out how to use them to accomplish what I want.  Basically, I want to show the user a combobox with possible countries, and based on their selection, set the default keyboard layout.  I would like a small code example if possible.

TIA,
Joe
0
Comment
Question by:joeslow
  • 3
  • 2
6 Comments
 
LVL 14

Expert Comment

by:AlexVirochovsky
ID: 2784004
I think, you can simple change value in
HKEY_CURRENT_USER\keyboard layout\preload\1 key "default" to
ID of lang. List all Langs see in
description of LoadKeyboardLayout,..
For make list you can use standart ListBox. For change entry in Regitry
I can send you my porogramm(if you have't this one).
Alex
0
 
LVL 14

Accepted Solution

by:
AlexVirochovsky earned 800 total points
ID: 2789355
You don't react.

I send you my code for read/write in
system registry

Next is my code for make it
int Test(void)
{
  int bStop = 0;
      // skip registry key opening sequence for clarity
  const INT nSIZE = 4096; //maximum(real 8)
  const DWORD dwLen = 8;
  const char *lpszPathName = "SOFTWARE\\COMPANY\\MYCOMPANY";
  const char *pszValueName = "Param01";

  HKEY hKey,hBaseKey = HKEY_LOCAL_MACHINE;
  DWORD dwType;
  DWORD dwData  = nSIZE;
  char* bData   = (char *)::calloc(nSIZE, sizeof(char));
  struct date dDate;
  LONG retValue;

//open key
  retValue = ::RegOpenKeyEx(hBaseKey, lpszPathName,
       NULL, KEY_ALL_ACCESS,&hKey);
  if (retValue != ERROR_SUCCESS)//no such : 1-st time
    {                           //create key
       uint32 disposition;
       retValue = ::RegCreateKeyEx(hBaseKey, lpszPathName, 0, ""/*class*/,
    REG_OPTION_NON_VOLATILE,KEY_ALL_ACCESS,
    0/*SecurityAttributes*/, &hKey,
    &disposition);
       if (retValue == ERROR_SUCCESS)//must be!
{
    //you code for form bData
//save data
   ::RegSetValueEx(hKey, pszValueName, 0, REG_BINARY,
  (LPBYTE)bData, dwLen);
   ::RegCloseKey(hKey); //close key
}
    }
  else //exist, read data
    {
      retValue = ::RegQueryValueEx(hKey, pszValueName,
  NULL, &dwType,(LPBYTE)bData, &dwData);

       if (retValue == ERROR_SUCCESS && REG_BINARY == dwType)
{
   if (Empty(bData)) //no data?
     {
       //you code for form bData
// Save
      ::RegSetValueEx(hKey, pszValueName, 0, REG_BINARY,
  (LPBYTE)bData, dwLen);
     }
   else  //test data
     {
     }

}
      ::RegCloseKey(hKey); //close key
    }
  if (bData)
    free (bData);
  return bStop;
}
Alex
0
 

Author Comment

by:joeslow
ID: 2789512
Hi Alex,

I saw your reply this morning and have been playing around with it a little.  I am not sure it does all the necessary things though.  For example:

I go to the control panel and start the keyboard cpl, then set the default locale input to something different, hit apply, start notepad, and  the new language takes effect.  

If I go directly to regedit, change it myself, then start notepad, the change does not seem to take effect.

There seems to be a place under HKEY_USERS\.DEFAULT that may do the trick as you described but I haven'tr tried yet...

Thanks,
Joe
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

Expert Comment

by:meamox
ID: 2823799
The value under HKEY_USERS\.DEFAULT\Keyboard Layout\Preload will only change the keyboard layout for the default, non-logged on user. (i.e In Windows NT, the keyboard layout you are typing with when you are typing your account and password to logon in the security dialog.)  Once you log on, the settings in HKEY_CURRENT_USER take over.


   I've been attempting to do something similar to change the keyboard layout for all threads for a given user, but for some reason, the LoadKeyboardLayout API call (with KLF_ACTIVATE flag) only changes the layout for the current thread (the one that changes the layout) in Windows NT.  That is the documented behavior for Windows 9x, but for Windows NT it is supposed to change the layout for more than just the current thread.

I can post my code if you are interested, but as I'm sort of still looking for the same answers that you are, I'll assume for now that it wouldn't help much.  =)
0
 

Author Comment

by:joeslow
ID: 2825753
That explains alot.  I was thinking the default user was used whenever a new user was created.  So are you saying you can not set the default keyboard layout for the "computer" to Swedish, so that all users created will have this as a default?

Thanks,
Joe
0
 

Author Comment

by:joeslow
ID: 2834882
Alex,

Sorry it took so long to get back on this.  I had to settle on setting the HKEY_CURRENT_USER\Keyboard\Preload\1 key as you suggested in your first reply.  I was hoping I could set it for the whole system, not just one user...

Thanks again,
Joe
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question