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

输入法编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "CMyMenu.h"
  4. #include "windows.h"
  5. #include "string.h"
  6. int  EDIT1_NUM;
  7. char EDIT1_txt[200];
  8. char EDIT2_txt[200];
  9. BOOL WINAPI About(HWND hDlg,UINT message,WPARAM wParam,LPARAM lParam )
  10. {
  11. switch (message)
  12. {
  13. case WM_INITDIALOG:
  14. SetDlgItemText(hDlg,IDC_EDIT1,EDIT1_txt);
  15. SetDlgItemText(hDlg,IDC_EDIT2,EDIT2_txt);
  16. SetWindowPos(hDlg, 0, 400,300,0, 0, 21); //SWP_NOACTIVATE|SWP_NOSIZE|SWP_NOZORDER  //16/1/4
  17. return TRUE;
  18. case WM_COMMAND:
  19. switch(wParam) {
  20. case IDOK:
  21. GetDlgItemText(hDlg,IDC_EDIT1,EDIT1_txt,2);
  22. EDIT1_NUM=GetDlgItemInt(hDlg,IDC_EDIT1,0,FALSE);
  23. EndDialog(hDlg,IDOK);
  24. break;
  25. case IDCANCEL:
  26. EndDialog(hDlg,IDCANCEL);
  27. break;
  28. default:
  29. break;
  30. }
  31. break;
  32. }
  33.     return FALSE;
  34. }
  35. //链接到目标地址
  36. HINSTANCE GotoURL(LPCTSTR url, int showcmd)
  37. {
  38.     // 调用函数ShellExecute()
  39. //    HINSTANCE result = (HINSTANCE)ShellExecute(NULL, "open", url, NULL,NULL, showcmd);
  40.     return 0;
  41. }
  42. CMyMenu::CMyMenu(CMyWnd *mcmyWnd){
  43. char subMenuName[100][256];
  44. long iMenu,nMenus,subnMenus,i,flag;
  45. char MenuName[20][256]={"词语管理","-----","输入模式","选择背景","透 明 度","窗体边框","跟踪灵敏"
  46.   ,"滚动显示","锁定背景","自动造词","窗    花"," 帮  助 ","关于极速"};
  47. char fpath[256],cur_dic_lib[256],*pp[100];
  48. cmyWnd=mcmyWnd;
  49. hInst=cmyWnd->hInst;
  50. hMenu = CreatePopupMenu();
  51.     subhMenu = CreatePopupMenu();
  52.     mode_subhMenu = cmyWnd->ConWind->createModlePopup(cmyWnd->myResM.CurModleNum,21);
  53. /////////////////////////////////////////////////////////////
  54. //生成库子菜单
  55.   GetModuleFileName(hInst,fpath,255);
  56. for(i=0;i<100;i++)
  57. pp[i]=subMenuName[i];
  58. subnMenus=getallfile("c:\jsime\lib",pp);
  59. subMenuID_start=100;
  60. subMenuID_end=subMenuID_start;
  61. RegReadString("cur_dic_lib",cur_dic_lib); 
  62.   //MessageBox(0,cur_dic_lib,"功能暂时未编码",0);
  63.     for(i = 0 ;i<subnMenus;i++){
  64. flag=MF_ENABLED;
  65. if(strcmp(cur_dic_lib,subMenuName[i])==0)
  66. flag|=MF_CHECKED;
  67. AppendMenu (subhMenu, flag, subMenuID_end, subMenuName[i]);
  68. subMenuID_end++;
  69.   //MessageBox(0,MenuName[0],"功能暂时未编码",0);
  70.     }
  71. /////////////////////////////////////////////////////////////
  72. //主菜单部分
  73.     nMenus = 13;
  74.     for(iMenu = 1 ;iMenu<=nMenus;iMenu++){
  75. flag=MF_ENABLED;
  76. if(9==iMenu){
  77.     char dd[500];
  78. cmyWnd->RegReadString("backpic",dd);
  79. //MessageBox(0,"ddd",dd,0);
  80. if(dd[0]!=0)
  81. flag|=MF_CHECKED;
  82. }
  83. switch (iMenu)
  84. {
  85. case 6:
  86. if(cmyWnd->myResM.frameflage[0]=='1')
  87. flag|=MF_CHECKED;
  88. break;
  89. case 8:
  90. if(cmyWnd->myResM.scrollflage[0]=='1'){
  91. SetTimer(cmyWnd->m_hWnd,1,20,NULL);
  92. flag|=MF_CHECKED;
  93. }
  94. break;
  95. case 10:
  96. if(cmyWnd->myResM.autoword[0]=='1')
  97. flag|=MF_CHECKED;
  98. break;
  99. case 11:
  100. if(cmyWnd->myResM.flowerflage[0]=='1')
  101. flag|=MF_CHECKED;
  102. break;
  103. default:
  104.         //flag=MF_GRAYED|MF_DISABLED;
  105. break;
  106. }
  107.    if(iMenu==8)
  108.            flag|=MF_MENUBREAK|MF_MENUBARBREAK;
  109. AppendMenu (hMenu, flag, iMenu, MenuName[iMenu-1]);
  110.    // wIDNewItem -----  Long,指定菜单条目的新命令ID。如果在wFlags参数中指定了MF_POPUP字段,那么这应该是指向一个弹出式菜单的句柄
  111.    if(iMenu!=7)
  112.   AppendMenu (hMenu, MF_SEPARATOR, iMenu, "");
  113.     }//for
  114. ModifyMenu (hMenu, 2,MF_POPUP, (UINT)subhMenu, "编码库选择");
  115. ModifyMenu (hMenu, 3,MF_POPUP, (UINT)mode_subhMenu, "输入模式");
  116. }
  117. CMyMenu::~CMyMenu(){
  118.     //DestroyMenu(mode_subhMenu);
  119.     //DestroyMenu(subhMenu);
  120.     DestroyMenu(hMenu);
  121. }
  122. //返回所选菜单项
  123. long CMyMenu::Popup(){
  124. long iMenu,result,retabout,flag;
  125. POINT p ;
  126. char buffer [256];
  127. int CurentKbdNum=0;
  128.     GetCursorPos(&p);
  129. flag=TPM_RIGHTBUTTON + TPM_LEFTALIGN + TPM_NONOTIFY + TPM_RETURNCMD;
  130.     iMenu = TrackPopupMenu(hMenu, flag, p.x, p.y, 0, GetForegroundWindow(), 0);
  131.     //得到菜单的选择字符串
  132.     result = GetMenuString(hMenu, (iMenu-1), buffer, 255, MF_BYPOSITION);
  133.    
  134. if(iMenu>0){
  135. switch (iMenu)
  136. {
  137. case 1:
  138. {
  139. char AppPath[500];
  140. int i;
  141. GetModuleFileName(hInst,AppPath,256);
  142. for(i=strlen(AppPath)-1;i>=0;i--){
  143. if(AppPath[i]=='\'){
  144. AppPath[i]=0;
  145. strcat(AppPath,"\词语管理.exe ShowMessageBox");
  146. break;
  147. }
  148. }
  149. WinExec(AppPath,1);
  150. break;
  151. }
  152. case 2:
  153. break;
  154. case 3:
  155. GotoURL("www.cctv.com",1);
  156. //cmyWnd->ConWind->createModlePopup(cmyWnd->myResM.CurModleNum,20);
  157. break;
  158. case 4:
  159. cmyWnd->selectback();
  160. break;
  161. case 5:
  162. {
  163. char tem[20];
  164. sprintf(tem,"%d",cmyWnd->myResM.clarityflage);
  165. strcpy(EDIT1_txt,tem);
  166. strcpy(EDIT2_txt,"        透明度设置,值越小透明度越高,可以是1-255中的一个值。当前的值为:");
  167.        retabout=DialogBox(cmyWnd->hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,About);
  168. if(retabout==IDOK){
  169. cmyWnd->myResM.clarityflage=EDIT1_NUM;
  170. if(cmyWnd->myResM.clarityflage==0||cmyWnd->myResM.clarityflage>255)
  171. cmyWnd->myResM.clarityflage=200;
  172. WriteReg("clarityflage",(DWORD)cmyWnd->myResM.clarityflage);
  173. cmyWnd->SetAllWinAttrib(cmyWnd->myResM.clarityflage);
  174. }
  175. }
  176. break;
  177. case 6:
  178. if(cmyWnd->myResM.frameflage[0]=='1')
  179. {
  180. RegSaveString("frameflage","0");
  181. cmyWnd->myResM.frameflage[0]='0';
  182. }else{
  183. cmyWnd->myResM.RegSaveString("frameflage","1");
  184. cmyWnd->myResM.frameflage[0]='1';
  185. }
  186. cmyWnd->DrawFrame();
  187. break;
  188. case 7:
  189. if(cmyWnd->myResM.traceflage[0]>'0' && cmyWnd->myResM.traceflage[0]<='9')
  190. EDIT1_txt[0]=cmyWnd->myResM.traceflage[0];
  191. else
  192. EDIT1_txt[0]='0';
  193. EDIT1_txt[1]=0;
  194. strcpy(EDIT2_txt,"        跟踪灵敏度设10个级别:0立即移动,1为20个单位,……,8为160个单位,9锁定,默认为3。以下为当前灵敏度");
  195. retabout=DialogBox(cmyWnd->hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,About);
  196. if(retabout==IDOK){
  197. cmyWnd->myResM.traceflage[0]=EDIT1_txt[0];
  198. cmyWnd->myResM.traceflage[1]=0;
  199. if(cmyWnd->myResM.traceflage[0]>'0' && cmyWnd->myResM.traceflage[0]<='9')
  200. RegSaveString("traceflage",cmyWnd->myResM.traceflage); 
  201. else
  202. RegSaveString("traceflage","0"); 
  203. }
  204. break;
  205. case 8:
  206. if(cmyWnd->myResM.scrollflage[0]=='1')
  207. {
  208. cmyWnd->RegSaveString("scrollflage","0");
  209. cmyWnd->myResM.scrollflage[0]='0';
  210. }
  211. else
  212. {
  213. cmyWnd->myResM.RegSaveString("scrollflage","1");
  214. cmyWnd->myResM.scrollflage[0]='1';
  215. }
  216. break;
  217. case 9:
  218. cmyWnd->myResM.FixBackPic();
  219. {
  220.     char dd[500]="";
  221. //RegReadString("backpic",dd);
  222. //MessageBox(0,"dd",dd,0);
  223. }
  224. break;
  225. case 10:
  226. if(cmyWnd->myResM.autoword[0]=='1')
  227. {
  228. cmyWnd->RegSaveString("autoword","0");
  229. cmyWnd->myResM.autoword[0]='0';
  230. }else{
  231. cmyWnd->myResM.RegSaveString("autoword","1");
  232. cmyWnd->myResM.autoword[0]='1';
  233. }
  234. break;
  235. case 11:
  236. if(cmyWnd->myResM.flowerflage[0]=='1')
  237. {
  238. cmyWnd->RegSaveString("flowerflage","0");
  239. cmyWnd->myResM.flowerflage[0]='0';
  240. }else{
  241. cmyWnd->myResM.RegSaveString("flowerflage","1");
  242. cmyWnd->myResM.flowerflage[0]='1';
  243. }
  244. cmyWnd->DrawFrame();
  245. break;
  246. case 12:
  247. WinExec("hh c:\jsime\jsime.CHM",1);
  248. //WinHelp(NULL,"c:\jsime\jsime.hlp",HELP_CONTENTS,0);
  249. break;
  250. case 13:
  251. strcpy(EDIT1_txt,"E-MAIL:whln669@sohu.com ");
  252. strcpy(EDIT2_txt,"        首先感谢各位用户使用《极速五笔》,本软件是由王华设计开发,如对本软件有意见和建议,或需要得到帮助,请发电子邮件与本人联系。谢谢!");
  253. DialogBox(cmyWnd->hInst,MAKEINTRESOURCE(IDD_DIALOG1),0,About);
  254. break;
  255. default:
  256. if(subMenuID_start<=iMenu && iMenu<=subMenuID_end){
  257.     iMenu=iMenu-subMenuID_start;
  258.     result = GetMenuString(subhMenu, (iMenu), buffer, 255, MF_BYPOSITION);
  259.   //if(strlen(buffer)>0)
  260. // MessageBox(0,buffer,"功能暂时未编码",0);
  261. RegSaveString("cur_dic_lib",buffer); 
  262. WriteReg("jsime",1);
  263. }
  264. if(20<=iMenu && iMenu<=30){
  265.     iMenu=iMenu-20;
  266.   cmyWnd->ConWind->setModle(iMenu);
  267. buffer[0]=0;
  268.     result = GetMenuString(mode_subhMenu, (iMenu), buffer, 255, MF_BYPOSITION);
  269. //if(strlen(buffer)>0)
  270. // MessageBox(0,buffer,"功能暂时未编码",0);
  271. }
  272. //MessageBox(0,"过两天补上","功能暂时未编码",0);
  273. break;
  274. }
  275. }
  276. return  0;
  277. }