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

输入法编程

开发平台:

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. ResManager::ResManager()
  8. {
  9. POINT pp[10];
  10. ControlHeight=24;
  11. WinHeight=100+ControlHeight;
  12. WinWidth=170;
  13. hUIFont = CreateFont(20, 0, 0, 0, FW_NORMAL,
  14. FALSE, FALSE, FALSE, ANSI_CHARSET,
  15. OUT_TT_PRECIS, CLIP_TT_ALWAYS, ANTIALIASED_QUALITY,
  16. DEFAULT_PITCH, "宋体");
  17. pp[0].x=0; pp[0].y=ControlHeight;
  18. pp[1].x=WinWidth; pp[1].y=ControlHeight;
  19. pp[2].x=WinWidth; pp[2].y=WinHeight;
  20. pp[3].x=20; pp[3].y=WinHeight;
  21. pp[4].x=20; pp[4].y=ControlHeight+40;
  22. pp[5].x=0; pp[5].y=ControlHeight+20;
  23. pp[6].x=0; pp[6].y=ControlHeight;
  24. //文本区
  25. TextRGN=CreatePolygonRgn(pp,7,1);
  26. WinRGN1=CreatePolygonRgn(pp,7,1);
  27. WinRGN2=CreatePolygonRgn(pp,7,1);
  28. CurBackPic[0]=0;
  29. }
  30. ResManager::~ResManager()
  31. {
  32. DeleteObject(hUIFont);
  33. DeleteObject (WinRGN1);
  34. }
  35. int   ResManager::FixBackPic()
  36. {
  37. char dd[500];
  38.     RegReadString("backpic",dd);
  39.     if(dd[0]==0)
  40. RegSaveString("backpic",CurBackPic);
  41. else
  42. RegSaveString("backpic","");
  43.     return 0;
  44. }
  45. ResManager::InitResManager(HDC WindDC,HINSTANCE hInst)
  46. {
  47. HANDLE  hfile;
  48. long tt=0,i;
  49. char fpath[500];
  50. char fname[500];
  51. // HBRUSH hHBr;
  52.   try {
  53. LinebarhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myLine));
  54. LinebarDC = CreateCompatibleDC(WindDC);
  55. DeleteObject(SelectObject(LinebarDC,LinebarhBmp));
  56. LinebarhBmp1=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_myLine1));
  57. LinebarDC1 = CreateCompatibleDC(WindDC);
  58. DeleteObject(SelectObject(LinebarDC1,LinebarhBmp1));
  59.  
  60. //-------------------------------------------------
  61. //如果注册表中backpic键值中有正确的文件名,并能正确装载,背景图片就固定下来
  62.     RegReadString("backpic",fname);
  63. BackhBmp=NULL;
  64. hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  65. if(hfile!=INVALID_HANDLE_VALUE)
  66. {
  67. CloseHandle(hfile);
  68. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  69. }
  70.     if(BackhBmp==NULL)
  71. {
  72. GetModuleFileName(hInst,fpath,255);
  73. myGetPath(fpath);   //取路径
  74. sprintf(fname,"%sback.bmp",fpath);
  75. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  76. if(BackhBmp==NULL)
  77. {   
  78. fname[0]=0;
  79. for(i=0;i<100;i++)
  80. {
  81. sprintf(fname,"%s\%d.bmp",fpath,tt+1);
  82. hfile=CreateFile(fname,GENERIC_READ,FILE_SHARE_READ ,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  83. if(hfile!=INVALID_HANDLE_VALUE)
  84. {
  85. CloseHandle(hfile);
  86. tt++;
  87. }
  88. else
  89. break;
  90. }
  91. if(tt>0)
  92. {
  93. tt=GetTickCount()%(tt+1);
  94. if(tt<1)
  95. tt=1;
  96. sprintf(fname,"%s\%d.bmp",fpath,tt);
  97. BackhBmp=(HBITMAP)LoadImage(0, fname, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE|LR_CREATEDIBSECTION );
  98. }
  99. if(BackhBmp==NULL)
  100. {
  101. BackhBmp=(HBITMAP)LoadBitmap(hInst,MAKEINTRESOURCE(IDB_Back));
  102. fname[0]=0;
  103. //当所有的装载都失败时,就启用DLL中的背景图片,保证所有情况下都有背景图片显示
  104. }
  105. }
  106. }
  107. //保存当前的装入的图片名称,为空时说明使用了DLL中的背景。
  108. strcpy(CurBackPic,fname);
  109. BackDC = CreateCompatibleDC(WindDC);
  110. DeleteObject(SelectObject(BackDC,BackhBmp));
  111. //HRGN temrgn;
  112. //hHBr = CreateHatchBrush(7, RGB(0,0,255));
  113. //temrgn=WinRGN2;
  114. //OffsetRgn(temrgn,0,-ControlHeight);
  115. //FrameRgn(BackDC,temrgn,hHBr,2,2);
  116. //DeleteObject(hHBr);
  117.      //-------------------------------------------------
  118. Flashhdc = CreateCompatibleDC(WindDC);
  119. Flashhdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
  120. SelectObject(Flashhdc, hUIFont);
  121. DeleteObject(SelectObject(Flashhdc,Flashhdcbmp));
  122. Texthdc = CreateCompatibleDC(WindDC);
  123. Texthdcbmp=CreateCompatibleBitmap(WindDC,WinWidth,WinHeight);
  124. SelectObject(Texthdc, hUIFont);
  125. DeleteObject(SelectObject(Texthdc,Texthdcbmp));
  126. BitBlt(Texthdc,0,0,WinWidth,WinHeight,BackDC,0,0,SRCCOPY);
  127. SetBkMode(Texthdc,TRANSPARENT);
  128.   } catch (...) 
  129.   {
  130. RegSaveString("backpic","");
  131.   }
  132. }
  133. //////////////////////////////////////////////////////////////////////////////
  134. //读取注册表中的一个变量
  135. DWORD ResManager::ReadReg(char *valname)
  136. {
  137. HKEY hKey;
  138. DWORD myupdate=0, myupdate1=0;
  139. unsigned long lon;
  140. if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
  141. {
  142. //如果没有键值就建立一个
  143. if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)&myupdate1,&lon) != ERROR_SUCCESS )
  144.   RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&myupdate,sizeof(DWORD));
  145. RegCloseKey(hKey);
  146. }
  147. return myupdate1;
  148. }
  149. /////////////////////////////////////////////////////////////////////////
  150. // read string  
  151. int ResManager::RegReadString(char *valname, char *keyVal)
  152. {
  153. HKEY hKey;
  154. unsigned long lon;
  155. char dd[10]="";
  156. keyVal[0]=0;
  157. if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
  158. {
  159. //如果没有键值就建立一个
  160. if( RegQueryValueEx( hKey,valname,NULL,NULL,(LPBYTE)keyVal,&lon) != ERROR_SUCCESS )
  161.   RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)dd,0);
  162. RegCloseKey(hKey);
  163. }
  164. return 0;
  165. }
  166. int ResManager:: RegSaveString(char *valname, char *keyVal)
  167. {
  168. HKEY hKey;
  169. if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
  170. {
  171.  //   MessageBox(0,valname,keyVal,0);
  172.   RegSetValueEx(hKey, valname,0,REG_SZ,(LPBYTE)keyVal,strlen(keyVal)+1);
  173. RegCloseKey(hKey);
  174. }
  175. return 0;
  176. }
  177. int ResManager::WriteReg(char *valname,DWORD keyVal)
  178. {
  179. HKEY hKey;
  180. if ( RegCreateKey(HKEY_CURRENT_USER,"Software\jsime", &hKey) == ERROR_SUCCESS )
  181. {
  182.  //   MessageBox(0,valname,keyVal,0);
  183.   RegSetValueEx(hKey, valname,0,REG_DWORD,(LPBYTE)&keyVal,sizeof(DWORD));
  184. RegCloseKey(hKey);
  185. }
  186. return 0;
  187. }
  188. //////////////////////////////////////////////////////////////////
  189. POINT  ResManager:: ReadRegPos(char *PathName)
  190. {
  191. HKEY hKey;
  192. DWORD myupdate=0, myupdate1=0;
  193. unsigned long lon;
  194. POINT GetPos;
  195. char ss[100];
  196. GetPos.x=0;
  197. GetPos.y=0;
  198. sprintf(ss,"Software\jsime\%s",PathName);
  199. if ( RegCreateKey(HKEY_CURRENT_USER,ss, &hKey) == ERROR_SUCCESS )
  200. {
  201. //如果没有键值就建立一个
  202. if( RegQueryValueEx( hKey,"x",NULL,NULL,(LPBYTE)&GetPos.x,&lon) != ERROR_SUCCESS )
  203.   RegSetValueEx(hKey, "x",0,REG_DWORD,(LPBYTE)&GetPos.x,sizeof(DWORD));
  204. if( RegQueryValueEx( hKey,"y",NULL,NULL,(LPBYTE)&GetPos.y,&lon) != ERROR_SUCCESS )
  205.   RegSetValueEx(hKey, "y",0,REG_DWORD,(LPBYTE)&GetPos.y,sizeof(DWORD));
  206. RegCloseKey(hKey);
  207. }
  208. return GetPos;
  209. }
  210. int ResManager::WriteRegPos(char *PathName,POINT SavePos)
  211. {
  212. HKEY hKey;
  213. char ss[100];
  214. sprintf(ss,"Software\jsime\%s",PathName);
  215. if ( RegCreateKey(HKEY_CURRENT_USER,ss, &hKey) == ERROR_SUCCESS )
  216. {
  217.  //   MessageBox(0,valname,keyVal,0);
  218.   RegSetValueEx(hKey, "x",0,REG_DWORD,(LPBYTE)&SavePos.x,sizeof(DWORD));
  219.   RegSetValueEx(hKey, "y",0,REG_DWORD,(LPBYTE)&SavePos.y,sizeof(DWORD));
  220. RegCloseKey(hKey);
  221. }
  222. return 0;
  223. }
  224. int ResManager::myGetPath(char *filefullname)
  225. {
  226. int  i,lon;
  227. lon=strlen(filefullname);
  228. for(i=lon;i>0;i--)
  229. if(filefullname[i]=='\')
  230. {
  231. filefullname[i+1]=0;
  232. break;
  233. }
  234. return 0;
  235. }