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,"%s\pic\back.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\pic\%d.jpg",fpath,tt);
  243. if(jpegpic.LoadJpegFile(WindDC,fname)) //成功,则重画窗口
  244.    BackhBmp=jpegpic.hBitmap;
  245. }
  246. //MessageBox(0,fname,"有错误发生",0);
  247. }
  248. if(BackhBmp==NULL){   
  249. tt=findpicfile(fpath,"bmp");
  250. if(tt>0){
  251. sprintf(fname,"%s\pic\%d.bmp",fpath,tt);
  252. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  253. }
  254. }
  255. ///////////////////////////////////////////////////////////////////////
  256. if(BackhBmp==NULL){
  257. BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
  258. fname[0]=0;
  259. //当所有的装载都失败时,就启用DLL中的背景图片,保证所有情况下都有背景图片显示
  260. }
  261. }
  262. //保存当前的装入的图片名称,为空时说明使用了DLL中的背景。
  263. strcpy(CurBackPic,fname);
  264. //if(BackhBmp!=NULL)
  265. // MessageBox(0,CurBackPic,"功能暂时未编码",0);
  266. // DeleteObject(SelectObject(BackDC, hUIFont));
  267. BackDC = CreateCompatibleDC(WindDC);
  268. DeleteObject(SelectObject(BackDC,BackhBmp));
  269. //保存的一个备份背景
  270. reBackDC = CreateCompatibleDC(WindDC);
  271. reBackhBmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
  272. DeleteObject(SelectObject(reBackDC,reBackhBmp));
  273. BitBlt(reBackDC,0,0,WinWidth,WinHeight,BackDC,0,0,SRCCOPY);
  274. }
  275. //得到随机文件的序号,
  276. long ResManager::findpicfile(char *fpath,char *typestr)
  277. {
  278. HANDLE  hfile;
  279. long tt=0,i;
  280. char fname[500];
  281. fname[0]=0;
  282. for(i=0;i<100;i++){
  283. sprintf(fname,"%s\pic\%d.%s",fpath,tt+1,typestr);
  284. hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  285. if(hfile!=INVALID_HANDLE_VALUE){
  286. CloseHandle(hfile);
  287. tt++;
  288. }
  289. else
  290. break;
  291. }
  292. if(tt>0){
  293. tt=GetTickCount()%(tt+1);
  294. if(tt<1)
  295. tt=1;
  296. return tt;
  297. }