分类: C/C++
2008-03-17 17:54:44
HKEY hk,hk1; long cp=16; char lp[15]; char a[2]; a[0]=''1''; a[1]=''\0''; CString str,str1; str=".DEFAULT\\keyboard layout\\preload\\";//已装的输入法。注:win2000有所不同 str+=a; int i=0; while(::RegOpenKey(HKEY_USERS,str,&hk)==ERROR_SUCCESS)//打开键 { a[0]++;//下一子键 str=".DEFAULT\\keyboard layout\\preload\\"; str+=a; if(::RegQueryValue(hk,NULL,lp,&cp)!=ERROR_SUCCESS)//已装的输入法 MessageBox("Error"); ::RegEnumKeyEx str1="System\\CurrentControlSet\\Control\\Keyboard Layouts\\";//keyboardlayoutLayout str1+=lp; lst[i++]=lp; //打开对应的keyboardlayoutLayout if(RegOpenKey(HKEY_LOCAL_MACHINE,str1,&hk1)==ERROR_SUCCESS) { LPBYTE lpD=new BYTE[80];//DataValue DWORD lpT=REG_SZ;//DataType DWORD lpS=80; //DataSize if(RegQueryValueEx(hk1,"Layout text",NULL,&lpT,lpD,&lpS)!=ERROR_SUCCESS) MessageBox("Query error",(LPCTSTR)lpD); m_cb1.AddString((LPCTSTR)lpD); delete lpD; } else MessageBox("open error"); RegCloseKey(hk1); } ::RegCloseKey(hk); m_cb1.SetCurSel(0);在OnSetfocusEdit1()加入如下代码:
CString temp; temp=m_cb1.GetCurSel()!=CB_ERR?lst[m_cb1.GetCurSel()]:"00000409"; HKL hkl; hkl=LoadKeyboardLayout(temp,KLF_ACTIVATE);//装载输入法 if(hkl==NULL) OnOK(); ActivateKeyboardLayout(hkl,KLF_SETFORPROCESS);//激活输入法在OnSelchangeCombo1()加入如下代码:
m_edt1.SetFocus();即可编译运行。