Solved

Code to set Default Keyboard Layout

Posted on 2000-05-03
6
589 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 200 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
For most people, the WrapPanel seems like a magic when they switch from WinForms to WPF. Most of us will think that the code that is used to write a control like that would be difficult. However, most of the work is done by the WPF engine, and the W…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

932 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now