fff.cpp
上传用户:hyb6888
上传日期:2016-01-24
资源大小:5186k
文件大小:3k
源码类别:

输入法编程

开发平台:

Visual C++

  1. // fff.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include "windows.h"
  5. #include "setup.h"
  6. #include "imm.h"
  7. #include "RegeditOP.h"
  8. int setupIME();
  9. RegeditOP regop;
  10. int main(int argc, char* argv[])
  11. {
  12. // char ss[1000];
  13. setup mysetup;
  14. setupIME();
  15. // getchar();
  16. return 0;
  17. }
  18. //保存输入法的次序
  19. int SaveOrderIME(HKL instHKL)
  20. {
  21. char ss[1000],retss[100],temss[100],tempath[1000];
  22. int i,t=1,num;
  23. HKL hKB[100];
  24. ActivateKeyboardLayout ((HKL)804, 0);
  25. SetKeyboardState((unsigned char *)&"00000804");
  26. LoadKeyboardLayout("00000804", KLF_REORDER);
  27. num = GetKeyboardLayoutList(25, hKB) ;//取得所有输入法
  28. for(i=0;i<num;i++)
  29. {
  30. sprintf(retss,"%x",hKB[i]);
  31. if(ImmIsIME(hKB[i])==0||strlen(retss)<8)
  32. {
  33. sprintf(retss,"%x",(unsigned short int)hKB[i]);
  34. sprintf(temss,"00000000");
  35. sprintf(&temss[8-strlen(retss)],retss);
  36. sprintf(ss,"%d",t);
  37. regop.RegSaveString("Keyboard Layout\Preload",ss, temss);
  38. sprintf(tempath,"Keyboard Layout\Preload\%d",t);
  39. regop.RegSaveString(tempath,"", temss);
  40. if(t==1)
  41. {
  42. SetKeyboardState((unsigned char *)&temss);
  43. LoadKeyboardLayout(temss, KLF_REORDER);
  44. //MessageBox(0,temss,temss,0);
  45. }
  46. t++;
  47. }
  48. }
  49. //保存当 前安装的输入法
  50. sprintf(ss,"%d",t);
  51. sprintf(retss,"%x",instHKL);
  52. regop.RegSaveString("Keyboard Layout\Preload",ss, retss);
  53. sprintf(tempath,"Keyboard Layout\Preload\%d",t);
  54. regop.RegSaveString(tempath,"", retss);
  55. t++;
  56. for(i=0;i<num;i++)
  57. {
  58. sprintf(retss,"%x",hKB[i]);
  59. if(ImmIsIME(hKB[i])==1 && hKB[i]!=instHKL&&strlen(retss)==8 )//跳过当前输入法
  60. {
  61. sprintf(ss,"%d",t);
  62. regop.RegSaveString("Keyboard Layout\Preload",ss, retss);
  63. sprintf(tempath,"Keyboard Layout\Preload\%d",t);
  64. regop.RegSaveString(tempath,"", retss);
  65. t++;
  66. }
  67. }
  68. return 0;
  69. }
  70. int setupIME()
  71. {
  72. char ss[1000];
  73. char Path[1000];
  74. char filecopy[1000];
  75. setup  mysetup;
  76. int ret;
  77. HKL dd;
  78. HKL hCurKBDLayout;
  79. sprintf(Path,"%s", "C:\jsime");
  80. mysetup.copypathfile(Path);//把当前目录下的所有文件复制到工作目录下。
  81. sprintf(filecopy,"%s%s", mysetup.AppPath,"\SysPath.txt");
  82. mysetup.FileCopyBAT(mysetup.AppPath,mysetup.SysPath,filecopy);
  83.     
  84. //////////////////////////////////////////////////////////////////////
  85. //激活输入法
  86. sprintf(ss,"%s%s", mysetup.SysPath,"\whjsmb.ime");
  87. dd = ImmInstallIME(ss,"极速五笔");
  88. if(dd != 0) 
  89. {
  90. sprintf(ss,"%x", dd);
  91. sprintf(Path,"SYSTEM\CurrentControlSet\Control\Keyboard Layouts\%s",ss);
  92. regop.RegSaveString(HKEY_LOCAL_MACHINE,Path,"Layout Display Name", "中文  极速五笔JSWH");
  93. ret=MessageBox(0,"是否调整输入法顺序","whjsmb安装成功",1);
  94. if(ret==1)
  95. {
  96. //修改输入法顺序
  97. hCurKBDLayout = GetKeyboardLayout(0); //取得目前的输入法
  98. ActivateKeyboardLayout (dd, 0);
  99. SetKeyboardState((unsigned char *)&ss);
  100. LoadKeyboardLayout(ss, KLF_REORDER);
  101. SaveOrderIME(dd);
  102. ActivateKeyboardLayout (hCurKBDLayout, 0);
  103. }
  104. }
  105. else
  106.      MessageBox(0,"安装失败!请检查文件","whjsmb",0);
  107. return 0;
  108. }