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

输入法编程

开发平台:

Visual C++

  1. #include "stdafx.h"
  2. #include "stdio.h"
  3. #include "CMyWnd.h"
  4. #include "stdafx.h"
  5. #include "windows.h"
  6. #include "ResManager.h"
  7. mytimers::mytimers()
  8. {
  9. int i;
  10. for(i=0;i<6;i++)
  11. {
  12. time[i]=0;
  13. num[i]=0;
  14. }
  15. pt=0;
  16. }
  17. mytimers::~mytimers()
  18. {
  19. ;
  20. }
  21. mytimers::appnum(int applong)//增加长度计数
  22. {
  23. num[pt]+=applong;
  24. }
  25. mytimers::apptime()//增加一次计数
  26. {
  27.   time[pt]++;
  28. if(time[pt]==60)
  29. {
  30. pt=(pt+1)%5;
  31. time[pt]=0;
  32. num[pt]=0;
  33. }
  34. }
  35. mytimers::reset()//重设计器器
  36. {
  37. int i;
  38. for(i=0;i<6;i++)
  39. {
  40. time[i]=0;
  41. num[i]=0;
  42. }
  43. pt=0;
  44. }
  45. int mytimers::GetAverage()//得到平均数
  46. {
  47. int i,tt=0,tn=0,ret;
  48. for(i=0;i<5;i++)
  49. {
  50. tt+=time[i];
  51. tn+=num[i];
  52. }
  53. if(tt==0)
  54. ret=0;
  55. else
  56. ret=tn*60/tt;
  57. if(ret==0&& tt>0)
  58. reset();
  59. return ret;//每分多少个。
  60. }
  61. /////////////////////////////////////////////////////////////////
  62. /////////////////////////////////////////////////////////////////
  63. ResManager::ResManager()
  64. {
  65. char ss[100]="";
  66.  
  67. //注册表的读取
  68. ////////////////////////////////////////////////////////////////
  69. //
  70.     RegReadString("textflage",ss);  //
  71. if(ss[0]==0)
  72. textflage[0]='1';
  73. else
  74. textflage[0]=ss[0];
  75. textflage[1]=0;
  76. ////////////////////////////////////////////////////////////////
  77. //窗口跟踪灵敏度,默认为3
  78.     RegReadString("traceflage",ss);  //跟踪10个级别0立即,9锁定
  79. if(ss[0]<'0' || ss[0]>'9')
  80. {
  81. //RegSaveString("traceflage","3"); 
  82. traceflage[0]='3';
  83. }
  84. else
  85. textflage[0]=ss[0];
  86. traceflage[1]=0;
  87. ////////////////////////////////////////////////////////////////
  88. //默认为有滚动
  89.     RegReadString("scrollflage",ss);   //滚动显示1,0
  90. if(ss[0]==0)
  91. scrollflage[0]='1';
  92. else
  93. scrollflage[0]=ss[0];
  94. scrollflage[1]=0;//设置字符串结尾
  95. ////////////////////////////////////////////////////////////////
  96. //默认为200
  97.     clarityflage=(unsigned char)ReadReg("clarityflage"); //透明度
  98. if(clarityflage==0)
  99. clarityflage=200;
  100. ////////////////////////////////////////////////////////////////
  101. //默认为有边框
  102.     RegReadString("frameflage",ss);  //边框1为有,0为没有
  103. if(ss[0]==0)
  104. frameflage[0]='1';
  105. else
  106. frameflage[0]=ss[0];
  107. frameflage[1]=0;//设置字符串结尾
  108. ////////////////////////////////////////////////////////////////
  109. //
  110.     RegReadString("autoword",ss);  
  111. if(ss[0]==0)
  112. autoword[0]='1';
  113. else
  114. autoword[0]=ss[0];
  115. autoword[1]=0;
  116. ////////////////////////////////////////////////////////////////
  117. //窗花
  118.     RegReadString("flowerflage",ss);   //启用窗花1,0
  119. if(ss[0]==0)
  120. flowerflage[0]='1';
  121. else
  122. flowerflage[0]=ss[0];
  123. flowerflage[1]=0;
  124. CurBackPic[0]=0;
  125. ////////////////////////////////////////////////////////////////
  126.     //模式号:1基本优先 2扩展优先 3五笔模式 4扩展模式
  127.     RegReadString("CurModleNum",ss);   //启用窗花1,0
  128. if(ss[0]==0)
  129. CurModleNum=1;
  130. else
  131. CurModleNum=ss[0]-0x30;
  132. }
  133. ResManager::~ResManager()
  134. {
  135. DeleteDC (LinebarDC);
  136. DeleteObject(LinebarhBmp);
  137. DeleteDC (LinebarDC1);
  138. DeleteObject(LinebarhBmp1);
  139. ////////////////////////////////
  140. DeleteDC (BackDC);
  141. DeleteObject(BackhBmp);
  142. DeleteDC (reBackDC);
  143. DeleteObject(reBackhBmp);
  144.     ///////////////////////////////
  145. DeleteDC (oldBackDC);
  146. DeleteObject(oldBackhBmp);
  147. /////////////////////////////////
  148. DeleteDC (Flashhdc);
  149. DeleteObject(Flashhdcbmp);
  150. }
  151. int   ResManager::FixBackPic()
  152. {
  153. char dd[500]="";
  154.     RegReadString("backpic",dd);
  155.     if(dd[0]==0){
  156. // MessageBox(0,0,dd,0);
  157. RegSaveString("backpic",CurBackPic);
  158. //RegReadString("backpic",dd);
  159. //MessageBox(0,CurBackPic,dd,0);
  160. }else{
  161. RegSaveString("backpic","");
  162. //MessageBox(0,CurBackPic,"save",0);
  163. }
  164. // RegSaveString("backpic",CurBackPic);
  165.     return 0;
  166. }
  167. ResManager::InitResManager(HDC L_WindDC,HINSTANCE L_hInst,int L_WinWidth,int L_WinHeight)
  168. {
  169. // HBRUSH hHBr;
  170.   try {
  171. WindDC    =L_WindDC;;
  172. hInst     =L_hInst; ;
  173. WinWidth  =L_WinWidth; ;
  174. WinHeight =L_WinHeight; ;
  175.   //两个选择线图片的装入
  176. LinebarhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myLine));
  177. LinebarDC = CreateCompatibleDC(WindDC);
  178. DeleteObject(SelectObject(LinebarDC,LinebarhBmp));
  179. LinebarhBmp1=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myLine1));
  180. LinebarDC1 = CreateCompatibleDC(WindDC);
  181. DeleteObject(SelectObject(LinebarDC1,LinebarhBmp1));
  182.  
  183. loadback();
  184. oldBackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
  185. oldBackDC = CreateCompatibleDC(WindDC);
  186. DeleteObject(SelectObject(oldBackDC,oldBackhBmp));
  187.      //-------------------------------------------------
  188. Flashhdc = CreateCompatibleDC(WindDC);
  189. Flashhdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
  190. DeleteObject(SelectObject(Flashhdc,Flashhdcbmp));
  191.   } catch (...) 
  192.   {
  193. //RegSaveString("backpic","");
  194. //MessageBox(0,"ddd","dddd",0);
  195.   }
  196. }
  197. ResManager::loadback()
  198. {
  199. HANDLE  hfile;
  200. long tt=0;
  201. char fpath[500];
  202. char fname[500];
  203. DeleteDC (BackDC);
  204. DeleteObject(BackhBmp);
  205. DeleteDC (reBackDC);
  206. DeleteObject(reBackhBmp);
  207. try {
  208. //-------------------------------------------------
  209. //如果注册表中backpic键值中有正确的文件名,并能正确装载,背景图片就固定下来
  210. RegReadString("backpic",fname);
  211. BackhBmp=NULL;
  212. hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  213. if(hfile!=INVALID_HANDLE_VALUE)
  214. {
  215. CloseHandle(hfile);
  216. if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
  217. BackhBmp=jpegpic.hBitmap;
  218. if(BackhBmp==NULL)
  219. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  220. //MessageBox(0,fname,"CreateFile",0);
  221. }
  222. } catch (...) {
  223. //if( BackhBmp!=NULL)
  224. // DeleteObject(BackhBmp);
  225. BackhBmp=NULL;
  226. RegSaveString("backpic",""); 
  227. //MessageBox(0,"loadback","有错误发生",0);
  228. }
  229.     if(BackhBmp==NULL)
  230. {
  231. GetModuleFileName(hInst,fpath,255);
  232. myGetPath(fpath);   //取路径
  233. sprintf(fname,"%sback.jpg",fpath);
  234. if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
  235.     BackhBmp=jpegpic.hBitmap;
  236. if(BackhBmp==NULL)
  237. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  238. //////////////////////////////////////////////////////////////////////
  239. if(BackhBmp==NULL){   
  240. tt=findpicfile(fpath,"jpg");
  241. if(tt>0){
  242. sprintf(fname,"%s%d.jpg",fpath,tt);
  243. if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
  244.    BackhBmp=jpegpic.hBitmap;
  245. }
  246. }
  247. if(BackhBmp==NULL){   
  248. tt=findpicfile(fpath,"bmp");
  249. if(tt>0){
  250. sprintf(fname,"%s%d.bmp",fpath,tt);
  251. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  252. }
  253. }
  254. ///////////////////////////////////////////////////////////////////////
  255. if(BackhBmp==NULL){
  256. BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
  257. fname[0]=0;
  258. //当所有的装载都失败时,就启用DLL中的背景图片,保证所有情况下都有背景图片显示
  259. }
  260. }
  261. //保存当前的装入的图片名称,为空时说明使用了DLL中的背景。
  262. strcpy(CurBackPic,fname);
  263. //if(BackhBmp!=NULL)
  264. // MessageBox(0,CurBackPic,"功能暂时未编码",0);
  265. // DeleteObject(SelectObject(BackDC, hUIFont));
  266. BackDC = CreateCompatibleDC(WindDC);
  267. DeleteObject(SelectObject(BackDC,BackhBmp));
  268. //保存的一个备份背景
  269. reBackDC = CreateCompatibleDC(WindDC);
  270. reBackhBmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
  271. DeleteObject(SelectObject(reBackDC,reBackhBmp));
  272. BitBlt(reBackDC,0,0,WinWidth,WinHeight,BackDC,0,0,SRCCOPY);
  273. }
  274. //得到随机文件的序号,
  275. long ResManager::findpicfile(char *fpath,char *typestr)
  276. {
  277. HANDLE  hfile;
  278. long tt=0,i;
  279. char fname[500];
  280. fname[0]=0;
  281. for(i=0;i<100;i++){
  282. sprintf(fname,"%s\%d.%s",fpath,tt+1,typestr);
  283. hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  284. if(hfile!=INVALID_HANDLE_VALUE){
  285. CloseHandle(hfile);
  286. tt++;
  287. }
  288. else
  289. break;
  290. }
  291. if(tt>0){
  292. tt=GetTickCount()%(tt+1);
  293. if(tt<1)
  294. tt=1;
  295. return tt;
  296. }