FaceList.cpp
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:6k
源码类别:

游戏

开发平台:

Visual C++

  1. // FaceList.cpp: implementation of the CFaceList class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "gamehigh.h"
  6. #include "FaceList.h"
  7. #include "basefunction.h"
  8. #ifdef _DEBUG
  9. #undef THIS_FILE
  10. static char THIS_FILE[]=__FILE__;
  11. #define new DEBUG_NEW
  12. #endif
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CFaceList::CFaceList()
  17. {
  18. }
  19. CFaceList::~CFaceList()
  20. {
  21. if(m_ImgList1.GetSafeHandle() && 
  22. 0 != m_ImgList1.GetImageCount())
  23. {
  24. m_ImgList1.DeleteImageList();
  25. }
  26. if(m_ImgList2.GetSafeHandle() && 
  27. 0 != m_ImgList2.GetImageCount())
  28. {
  29. m_ImgList2.DeleteImageList();
  30. }
  31. if(m_ImgList3.GetSafeHandle() && 
  32. 0 != m_ImgList3.GetImageCount())
  33. {
  34. m_ImgList3.DeleteImageList();
  35. }
  36. if(m_ImgBkList.GetSafeHandle() && 
  37. 0 != m_ImgBkList.GetImageCount())
  38. {
  39. m_ImgBkList.DeleteImageList();
  40. }
  41. }
  42. BOOL CFaceList::Init()
  43. {
  44. char CurPath[MAX_PATH];
  45. memset(CurPath, 0, sizeof(char) * MAX_PATH);
  46. GetCurrentPath(CurPath);
  47. COLORREF clrTransparent =RGB(0, 128, 128);
  48. strcat(CurPath, "Faces\");
  49. m_ImgList1.Create(LARGEICON_SIZE, LARGEICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
  50. m_ImgList1.SetBkColor(clrTransparent);
  51. for(int i=0; i<IMG_COUNT; i++)
  52. {
  53. char buffer[20];
  54. memset(buffer, 0, sizeof(char) * 20);
  55. wsprintf(buffer, "%d-1.bmp", i + 1);
  56. CString file ="";
  57. file =CurPath;
  58. file +=buffer;
  59. HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
  60. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  61. if(hBmp)
  62. {
  63. CBitmap* pBitmap =NULL;
  64. pBitmap =pBitmap->FromHandle(hBmp);
  65. if(pBitmap && pBitmap->GetSafeHandle())
  66. {
  67. int nret =m_ImgList1.Add(pBitmap, clrTransparent);
  68. }
  69. pBitmap->DeleteObject();
  70. hBmp =NULL;
  71. }
  72. }
  73. m_ImgList2.Create(LARGEICON_SIZE, LARGEICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
  74. m_ImgList2.SetBkColor(clrTransparent);
  75. for(i=0; i<IMG_COUNT; i++)
  76. {
  77. char buffer[20];
  78. memset(buffer, 0, sizeof(char) * 20);
  79. wsprintf(buffer, "%d-2.bmp", i + 1);
  80. CString file ="";
  81. file =CurPath;
  82. file +=buffer;
  83. HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
  84. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  85. if(hBmp)
  86. {
  87. CBitmap* pBitmap =NULL;
  88. pBitmap =pBitmap->FromHandle(hBmp);
  89. if(pBitmap && pBitmap->GetSafeHandle())
  90. {
  91. int nret =m_ImgList2.Add(pBitmap, clrTransparent);
  92. }
  93. pBitmap->DeleteObject();
  94. hBmp =NULL;
  95. }
  96. }
  97. m_ImgList3.Create(LARGEICON_SIZE, LARGEICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
  98. m_ImgList3.SetBkColor(clrTransparent);
  99. for(i=0; i<IMG_COUNT; i++)
  100. {
  101. char buffer[20];
  102. memset(buffer, 0, sizeof(char) * 20);
  103. wsprintf(buffer, "%d-3.bmp", i + 1);
  104. CString file ="";
  105. file =CurPath;
  106. file +=buffer;
  107. HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
  108. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  109. if(hBmp)
  110. {
  111. CBitmap* pBitmap =NULL;
  112. pBitmap =pBitmap->FromHandle(hBmp);
  113. if(pBitmap && pBitmap->GetSafeHandle())
  114. {
  115. int nret =m_ImgList3.Add(pBitmap, clrTransparent);
  116. }
  117. pBitmap->DeleteObject();
  118. hBmp =NULL;
  119. }
  120. }
  121. //背景图片
  122. memset(CurPath, 0, sizeof(char) * MAX_PATH);
  123. GetCurrentPath(CurPath);
  124. clrTransparent =RGB(255, 0, 0);
  125. strcat(CurPath, "TabBack\");
  126. m_ImgBkList.Create(BKICON_SIZE, BKICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, BKIMG_COUNT);
  127. m_ImgBkList.SetBkColor(clrTransparent);
  128. for(i=0; i<BKIMG_COUNT; i++)
  129. {
  130. char buffer[20];
  131. memset(buffer, 0, sizeof(char) * 20);
  132. wsprintf(buffer, "%d.bmp", i + 1);
  133. CString file ="";
  134. file =CurPath;
  135. file +=buffer;
  136. HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
  137. IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
  138. if(hBmp)
  139. {
  140. CBitmap* pBitmap =NULL;
  141. pBitmap =pBitmap->FromHandle(hBmp);
  142. if(pBitmap && pBitmap->GetSafeHandle())
  143. {
  144. int nret =m_ImgBkList.Add(pBitmap, clrTransparent);
  145. }
  146. pBitmap->DeleteObject();
  147. hBmp =NULL;
  148. }
  149. }
  150. //16 * 16的图像
  151. m_ImgList4.Create(SMALLICON_SIZE, SMALLICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
  152. m_ImgList4.SetBkColor(clrTransparent);
  153. for(i=0; i<IMG_COUNT; i++)
  154. {
  155. HICON hIcon =m_ImgList1.ExtractIcon(i);
  156. SAFE_CHECKPOINTER(hIcon)
  157. {
  158. CBitmap* pBmp =MakeIcon2Bmp(hIcon, 
  159. SMALLICON_SIZE, SMALLICON_SIZE,  clrTransparent);
  160. if(NULL != pBmp && 
  161. NULL != pBmp->GetSafeHandle())
  162. {
  163. m_ImgList4.Add(pBmp, clrTransparent);
  164. pBmp->DeleteObject();
  165. delete pBmp;
  166. pBmp =NULL;
  167. }
  168. ::DestroyIcon(hIcon);
  169. hIcon =NULL;
  170. }
  171. }
  172. return TRUE;
  173. }
  174. CImageList* CFaceList::GetImageList1()
  175. {
  176. return &m_ImgList1;
  177. }
  178. CImageList* CFaceList::GetImageList2()
  179. {
  180. return &m_ImgList2;
  181. }
  182. CImageList* CFaceList::GetImageList3()
  183. {
  184. return &m_ImgList3;
  185. }
  186. CImageList* CFaceList::GetImageList4()
  187. {
  188. return &m_ImgList4;
  189. }
  190. CImageList* CFaceList::GetBkImgList()
  191. {
  192. return &m_ImgBkList;
  193. }
  194. CBitmap* CFaceList::MakeIcon2Bmp(HICON hIcon, int ncx, int ncy, COLORREF clrBk)
  195. {
  196. ASSERT(hIcon);
  197. if(NULL == hIcon)
  198. return NULL;
  199. CBitmap *newBitmap = new CBitmap;
  200. int ncolordepth =24;
  201. HWND hWnd =::GetDesktopWindow();
  202. if(::IsWindow(hWnd))
  203. {
  204. HDC hDC =::GetDC(hWnd);
  205. if(NULL != hDC)
  206. {
  207. ncolordepth =::GetDeviceCaps(hDC, BITSPIXEL);
  208. }
  209. ::ReleaseDC(hWnd, hDC);
  210. }
  211. newBitmap->CreateBitmap(ncx, ncy, 1, ncolordepth, NULL);
  212. CBrush m_Brush;
  213. m_Brush.CreateSolidBrush(clrBk);
  214. CDC memDC;
  215. memDC.CreateCompatibleDC(NULL);
  216. RECT rect;
  217. memset(&rect, 0, sizeof(RECT));
  218. rect.right =ncx;
  219. rect.bottom =ncy;
  220. memDC.FillRect(&rect, &m_Brush);
  221. m_Brush.DeleteObject();
  222. CBitmap *oldBitmap = memDC.SelectObject(newBitmap);
  223. ::DrawIconEx(memDC.GetSafeHdc(), 0, 0, hIcon, ncx, ncy, 0, 0, DI_NORMAL);
  224. memDC.SelectObject(oldBitmap);
  225. return newBitmap;
  226. }