RenderManager.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. #include "StdAfx.h"
  2. #include "RenderManager.h"
  3. CRenderManager::CRenderManager(void)
  4. {
  5. m_hResInstance = NULL;
  6. SetDefaultFont(TEXT("宋体"),12,false,false,false);
  7. }
  8. CRenderManager::~CRenderManager(void)
  9. {
  10. }
  11. //创建单例
  12. CRenderManager* CRenderManager::GetInstance()
  13. {
  14. static CRenderManager _Instance;
  15. return &_Instance;
  16. }
  17. static COLORREF PixelAlpha(COLORREF clrSrc, double src_darken, COLORREF clrDest, double dest_darken)
  18. {
  19. return RGB (GetRValue (clrSrc) * src_darken + GetRValue (clrDest) * dest_darken,
  20. GetGValue (clrSrc) * src_darken + GetGValue (clrDest) * dest_darken,
  21. GetBValue (clrSrc) * src_darken + GetBValue (clrDest) * dest_darken);
  22. }
  23. static BOOL WINAPI AlphaBitBlt(HDC hDC, int nDestX, int nDestY, int dwWidth, int dwHeight, HDC hSrcDC, \
  24. int nSrcX, int nSrcY, int wSrc, int hSrc, BLENDFUNCTION ftn)
  25. {
  26. HDC hTempDC = ::CreateCompatibleDC(hDC);
  27. if (NULL == hTempDC)
  28. return FALSE;
  29. //Creates Source DIB
  30. LPBITMAPINFO lpbiSrc = NULL;
  31. // Fill in the BITMAPINFOHEADER
  32. lpbiSrc = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  33. if (lpbiSrc == NULL)
  34. {
  35. ::DeleteDC(hTempDC);
  36. return FALSE;
  37. }
  38. lpbiSrc->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  39. lpbiSrc->bmiHeader.biWidth = dwWidth;
  40. lpbiSrc->bmiHeader.biHeight = dwHeight;
  41. lpbiSrc->bmiHeader.biPlanes = 1;
  42. lpbiSrc->bmiHeader.biBitCount = 32;
  43. lpbiSrc->bmiHeader.biCompression = BI_RGB;
  44. lpbiSrc->bmiHeader.biSizeImage = dwWidth * dwHeight;
  45. lpbiSrc->bmiHeader.biXPelsPerMeter = 0;
  46. lpbiSrc->bmiHeader.biYPelsPerMeter = 0;
  47. lpbiSrc->bmiHeader.biClrUsed = 0;
  48. lpbiSrc->bmiHeader.biClrImportant = 0;
  49. COLORREF* pSrcBits = NULL;
  50. HBITMAP hSrcDib = CreateDIBSection (
  51. hSrcDC, lpbiSrc, DIB_RGB_COLORS, (void **)&pSrcBits,
  52. NULL, NULL);
  53. if ((NULL == hSrcDib) || (NULL == pSrcBits))
  54. {
  55. delete [] lpbiSrc;
  56. ::DeleteDC(hTempDC);
  57. return FALSE;
  58. }
  59. HBITMAP hOldTempBmp = (HBITMAP)::SelectObject (hTempDC, hSrcDib);
  60. ::StretchBlt(hTempDC, 0, 0, dwWidth, dwHeight, hSrcDC, nSrcX, nSrcY, wSrc, hSrc, SRCCOPY);
  61. ::SelectObject (hTempDC, hOldTempBmp);
  62. //Creates Destination DIB
  63. LPBITMAPINFO lpbiDest = NULL;
  64. // Fill in the BITMAPINFOHEADER
  65. lpbiDest = (LPBITMAPINFO) new BYTE[sizeof(BITMAPINFOHEADER)];
  66. if (lpbiDest == NULL)
  67. {
  68. delete [] lpbiSrc;
  69. ::DeleteObject(hSrcDib);
  70. ::DeleteDC(hTempDC);
  71. return FALSE;
  72. }
  73. lpbiDest->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
  74. lpbiDest->bmiHeader.biWidth = dwWidth;
  75. lpbiDest->bmiHeader.biHeight = dwHeight;
  76. lpbiDest->bmiHeader.biPlanes = 1;
  77. lpbiDest->bmiHeader.biBitCount = 32;
  78. lpbiDest->bmiHeader.biCompression = BI_RGB;
  79. lpbiDest->bmiHeader.biSizeImage = dwWidth * dwHeight;
  80. lpbiDest->bmiHeader.biXPelsPerMeter = 0;
  81. lpbiDest->bmiHeader.biYPelsPerMeter = 0;
  82. lpbiDest->bmiHeader.biClrUsed = 0;
  83. lpbiDest->bmiHeader.biClrImportant = 0;
  84. COLORREF* pDestBits = NULL;
  85. HBITMAP hDestDib = CreateDIBSection (
  86. hDC, lpbiDest, DIB_RGB_COLORS, (void **)&pDestBits,
  87. NULL, NULL);
  88. if ((NULL == hDestDib) || (NULL == pDestBits))
  89. {
  90. delete [] lpbiSrc;
  91. ::DeleteObject(hSrcDib);
  92. ::DeleteDC(hTempDC);
  93. return FALSE;
  94. }
  95. ::SelectObject (hTempDC, hDestDib);
  96. ::BitBlt (hTempDC, 0, 0, dwWidth, dwHeight, hDC, nDestX, nDestY, SRCCOPY);
  97. ::SelectObject (hTempDC, hOldTempBmp);
  98. double src_darken;
  99. BYTE nAlpha;
  100. for (int pixel = 0; pixel < dwWidth * dwHeight; pixel++, pSrcBits++, pDestBits++)
  101. {
  102. nAlpha = LOBYTE(*pSrcBits >> 24);
  103. src_darken = (double) (nAlpha * ftn.SourceConstantAlpha) / 255.0 / 255.0;
  104. if( src_darken < 0.0 ) src_darken = 0.0;
  105. *pDestBits = PixelAlpha(*pSrcBits, src_darken, *pDestBits, 1.0 - src_darken);
  106. } //for
  107. ::SelectObject (hTempDC, hDestDib);
  108. ::BitBlt (hDC, nDestX, nDestY, dwWidth, dwHeight, hTempDC, 0, 0, SRCCOPY);
  109. ::SelectObject (hTempDC, hOldTempBmp);
  110. delete [] lpbiDest;
  111. ::DeleteObject(hDestDib);
  112. delete [] lpbiSrc;
  113. ::DeleteObject(hSrcDib);
  114. ::DeleteDC(hTempDC);
  115. return TRUE;
  116. }
  117. bool CRenderManager::GetWorkDirectory( TCHAR szWorkDirectory[], WORD wBufferCount )
  118. {
  119. //模块路径
  120. TCHAR szModulePath[MAX_PATH]=TEXT("");
  121. GetModuleFileName(AfxGetInstanceHandle(),szModulePath,CountArray(szModulePath));
  122. //分析文件
  123. for (INT i=lstrlen(szModulePath);i>=0;i--)
  124. {
  125. if (szModulePath[i]==TEXT('\\'))
  126. {
  127. szModulePath[i]=0;
  128. break;
  129. }
  130. }
  131. //设置结果
  132. ASSERT(szModulePath[0]!=0);
  133. lstrcpyn(szWorkDirectory,szModulePath,wBufferCount);
  134. return true;
  135. }
  136. //区域色块
  137. void CRenderManager::DrawColor(HDC hDC, const RECT& rc, COLORREF color)
  138. {
  139. ::SetBkColor(hDC, color);
  140. ::ExtTextOut(hDC, 0, 0, ETO_OPAQUE, &rc, NULL, 0, NULL);
  141. }
  142. //渐变色块
  143. void CRenderManager::DrawGradient(HDC hDC, const RECT& rc, DWORD dwFirst, DWORD dwSecond, bool bVertical, int nSteps)
  144. {
  145. typedef BOOL (WINAPI *LPALPHABLEND)(HDC, int, int, int, int,HDC, int, int, int, int, BLENDFUNCTION);
  146. static LPALPHABLEND lpAlphaBlend = (LPALPHABLEND) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "AlphaBlend");
  147. if( lpAlphaBlend == NULL ) lpAlphaBlend = AlphaBitBlt;
  148. typedef BOOL (WINAPI *PGradientFill)(HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG);
  149. static PGradientFill lpGradientFill = (PGradientFill) ::GetProcAddress(::GetModuleHandle(_T("msimg32.dll")), "GradientFill");
  150. BYTE bAlpha = (BYTE)(((dwFirst >> 24) + (dwSecond >> 24)) >> 1);
  151. if( bAlpha == 0 ) return;
  152. int cx = rc.right - rc.left;
  153. int cy = rc.bottom - rc.top;
  154. RECT rcPaint = rc;
  155. HDC hPaintDC = hDC;
  156. HBITMAP hPaintBitmap = NULL;
  157. HBITMAP hOldPaintBitmap = NULL;
  158. if( bAlpha < 255 )
  159. {
  160. rcPaint.left = rcPaint.top = 0;
  161. rcPaint.right = cx;
  162. rcPaint.bottom = cy;
  163. hPaintDC = ::CreateCompatibleDC(hDC);
  164. hPaintBitmap = ::CreateCompatibleBitmap(hDC, cx, cy);
  165. ASSERT(hPaintDC);
  166. ASSERT(hPaintBitmap);
  167. hOldPaintBitmap = (HBITMAP) ::SelectObject(hPaintDC, hPaintBitmap);
  168. }
  169. if( lpGradientFill != NULL )
  170. {
  171. TRIVERTEX triv[2] =
  172. {
  173. { rcPaint.left, rcPaint.top, GetBValue(dwFirst) << 8, GetGValue(dwFirst) << 8, GetRValue(dwFirst) << 8, 0xFF00 },
  174. { rcPaint.right, rcPaint.bottom, GetBValue(dwSecond) << 8, GetGValue(dwSecond) << 8, GetRValue(dwSecond) << 8, 0xFF00 }
  175. };
  176. GRADIENT_RECT grc = { 0, 1 };
  177. lpGradientFill(hPaintDC, triv, 2, &grc, 1, bVertical ? GRADIENT_FILL_RECT_V : GRADIENT_FILL_RECT_H);
  178. }
  179. else
  180. {
  181. // Determine how many shades
  182. int nShift = 1;
  183. if( nSteps >= 64 ) nShift = 6;
  184. else if( nSteps >= 32 ) nShift = 5;
  185. else if( nSteps >= 16 ) nShift = 4;
  186. else if( nSteps >= 8 ) nShift = 3;
  187. else if( nSteps >= 4 ) nShift = 2;
  188. int nLines = 1 << nShift;
  189. for( int i = 0; i < nLines; i++ )
  190. {
  191. // Do a little alpha blending
  192. BYTE bR = (BYTE) ((GetBValue(dwSecond) * (nLines - i) + GetBValue(dwFirst) * i) >> nShift);
  193. BYTE bG = (BYTE) ((GetGValue(dwSecond) * (nLines - i) + GetGValue(dwFirst) * i) >> nShift);
  194. BYTE bB = (BYTE) ((GetRValue(dwSecond) * (nLines - i) + GetRValue(dwFirst) * i) >> nShift);
  195. // ... then paint with the resulting color
  196. HBRUSH hBrush = ::CreateSolidBrush(RGB(bR,bG,bB));
  197. RECT r2 = rcPaint;
  198. if( bVertical )
  199. {
  200. r2.bottom = rc.bottom - ((i * (rc.bottom - rc.top)) >> nShift);
  201. r2.top = rc.bottom - (((i + 1) * (rc.bottom - rc.top)) >> nShift);
  202. if( (r2.bottom - r2.top) > 0 ) ::FillRect(hDC, &r2, hBrush);
  203. }
  204. else
  205. {
  206. r2.left = rc.right - (((i + 1) * (rc.right - rc.left)) >> nShift);
  207. r2.right = rc.right - ((i * (rc.right - rc.left)) >> nShift);
  208. if( (r2.right - r2.left) > 0 ) ::FillRect(hPaintDC, &r2, hBrush);
  209. }
  210. ::DeleteObject(hBrush);
  211. }
  212. }
  213. if( bAlpha < 255 )
  214. {
  215. BLENDFUNCTION bf = { AC_SRC_OVER, 0, bAlpha, AC_SRC_ALPHA };
  216. lpAlphaBlend(hDC, rc.left, rc.top, cx, cy, hPaintDC, 0, 0, cx, cy, bf);
  217. ::SelectObject(hPaintDC, hOldPaintBitmap);
  218. ::DeleteObject(hPaintBitmap);
  219. ::DeleteDC(hPaintDC);
  220. }
  221. }
  222. //绘制线条
  223. void CRenderManager::DrawLine(HDC hDC, const RECT& rc, int nSize, COLORREF dwPenColor,int nStyle/* = PS_SOLID*/)
  224. {
  225. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  226. LOGPEN lg;
  227. lg.lopnColor = dwPenColor;
  228. lg.lopnStyle = nStyle;
  229. lg.lopnWidth.x = nSize;
  230. HPEN hPen = CreatePenIndirect(&lg);
  231. HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
  232. POINT ptTemp = { 0 };
  233. ::MoveToEx(hDC, rc.left, rc.top, &ptTemp);
  234. ::LineTo(hDC, rc.right, rc.bottom);
  235. ::SelectObject(hDC, hOldPen);
  236. ::DeleteObject(hPen);
  237. }
  238. //绘制矩形
  239. void CRenderManager::DrawRect(HDC hDC, const RECT& rc, int nSize, COLORREF dwPenColor)
  240. {
  241. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  242. HPEN hPen = ::CreatePen(PS_SOLID | PS_INSIDEFRAME, nSize, dwPenColor);
  243. HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
  244. ::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH));
  245. ::Rectangle(hDC, rc.left, rc.top, rc.right, rc.bottom);
  246. ::SelectObject(hDC, hOldPen);
  247. ::DeleteObject(hPen);
  248. }
  249. //圆角矩形
  250. void CRenderManager::DrawRoundRect(HDC hDC, const RECT& rc, int width, int height, int nSize, COLORREF dwPenColor)
  251. {
  252. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  253. HPEN hPen = ::CreatePen(PS_SOLID | PS_INSIDEFRAME, nSize, dwPenColor);
  254. HPEN hOldPen = (HPEN)::SelectObject(hDC, hPen);
  255. ::SelectObject(hDC, ::GetStockObject(HOLLOW_BRUSH));
  256. ::RoundRect(hDC, rc.left, rc.top, rc.right, rc.bottom, width, height);
  257. ::SelectObject(hDC, hOldPen);
  258. ::DeleteObject(hPen);
  259. }
  260. void CRenderManager::DrawText(HDC hDC, RECT& rc, LPCTSTR pstrText, DWORD dwTextColor, HFONT hFont, UINT uStyle)
  261. {
  262. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  263. if( pstrText == NULL ) return;
  264. ::SetBkMode(hDC, TRANSPARENT);
  265. ::SetTextColor(hDC, RGB(GetBValue(dwTextColor), GetGValue(dwTextColor), GetRValue(dwTextColor)));
  266. HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont);
  267. ::DrawText(hDC, pstrText, -1, &rc, uStyle | DT_NOPREFIX);
  268. ::SelectObject(hDC, hOldFont);
  269. }
  270. //文字尺寸
  271. SIZE CRenderManager::GetTextSize(HDC hDC, LPCTSTR pstrText, HFONT hFont, UINT uStyle)
  272. {
  273. SIZE size = {0,0};
  274. ASSERT(::GetObjectType(hDC)==OBJ_DC || ::GetObjectType(hDC)==OBJ_MEMDC);
  275. if( pstrText == NULL ) return size;
  276. ::SetBkMode(hDC, TRANSPARENT);
  277. HFONT hOldFont = (HFONT)::SelectObject(hDC, hFont);
  278. GetTextExtentPoint32(hDC, pstrText, _tcslen(pstrText) , &size);
  279. ::SelectObject(hDC, hOldFont);
  280. return size;
  281. }
  282. void CRenderManager::SetDefaultFont( LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic )
  283. {
  284. LOGFONT lf = { 0 };
  285. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  286. _tcsncpy_s(lf.lfFaceName, pStrFontName, LF_FACESIZE);
  287. lf.lfCharSet = DEFAULT_CHARSET;
  288. lf.lfHeight = -nSize;
  289. if( bBold ) lf.lfWeight += FW_BOLD;
  290. if( bUnderline ) lf.lfUnderline = TRUE;
  291. if( bItalic ) lf.lfItalic = TRUE;
  292. m_hDefaultFont = ::CreateFontIndirect(&lf);
  293. if( m_hDefaultFont == NULL ) throw TEXT("创建字体失败");
  294. }
  295. //获取图片
  296. CImageEx * CRenderManager::GetImage( LPCTSTR lpszFileName,LPCTSTR lpszResType/*=NULL*/ )
  297. {
  298. map<LPCTSTR,tagImageInfo*>::iterator iter;
  299. pair<std::map<LPCTSTR, tagImageInfo *>::iterator, bool> pairInsert;
  300. tagImageInfo * pImageInfo = NULL;
  301. CImageEx * pImage=NULL;
  302. if (NULL == lpszFileName || NULL == *lpszFileName)
  303. return NULL;
  304. iter = m_ArrayImage.find(lpszFileName);
  305. if (iter != m_ArrayImage.end())
  306. {
  307. pImageInfo = iter->second;
  308. if (pImageInfo != NULL)
  309. {
  310. pImageInfo->nRef++;
  311. pImageInfo->pImage->DestroyImage();
  312. //路径加载资源
  313. if( lpszResType == NULL )
  314. {
  315. TCHAR szWorkDirectory[MAX_PATH]={0};
  316. GetWorkDirectory(szWorkDirectory,MAX_PATH);
  317. StrCat(szWorkDirectory,TEXT("\\"));
  318. StrCat(szWorkDirectory,lpszFileName);
  319. CFileFind fileFind;
  320. //判断是否exe目录下的资源
  321. if ( fileFind.FindFile(szWorkDirectory) )
  322. pImageInfo->pImage->LoadImage(szWorkDirectory);
  323. else //lpszFileName为完整路径
  324. pImageInfo->pImage->LoadImage(lpszFileName);
  325. }
  326. else
  327. {
  328. pImageInfo->pImage->LoadImage(m_hResInstance,lpszFileName,lpszResType);
  329. }
  330. return pImageInfo->pImage;
  331. }
  332. else
  333. {
  334. return NULL;
  335. }
  336. }
  337. else
  338. {
  339. pImageInfo = new tagImageInfo;
  340. pImage = new CImageEx;
  341. if (NULL == pImageInfo || NULL == pImage)
  342. {
  343. SafeDelete(pImageInfo);
  344. SafeDelete(pImage);
  345. return NULL;
  346. }
  347. pairInsert = m_ArrayImage.insert(pair<LPCTSTR, tagImageInfo *>(lpszFileName, pImageInfo));
  348. if (!pairInsert.second)
  349. {
  350. SafeDelete(pImageInfo);
  351. SafeDelete(pImage);
  352. return NULL;
  353. }
  354. bool bReturn = false;
  355. //路径加载资源
  356. if( lpszResType == NULL )
  357. {
  358. TCHAR szWorkDirectory[MAX_PATH]={0};
  359. GetWorkDirectory(szWorkDirectory,MAX_PATH);
  360. StrCat(szWorkDirectory,TEXT("\\"));
  361. StrCat(szWorkDirectory,lpszFileName);
  362. //sprintf_s(szWorkDirectory,_TRUNCATE,TEXT("\\%s"),lpszFileName);
  363. CFileFind fileFind;
  364. //判断是否exe目录下的资源
  365. if ( fileFind.FindFile(szWorkDirectory) )
  366. bReturn = pImage->LoadImage(szWorkDirectory);
  367. else //lpszFileName为完整路径
  368. bReturn = pImage->LoadImage(lpszFileName);
  369. }
  370. else
  371. {
  372. bReturn = pImage->LoadImage(m_hResInstance,lpszFileName,lpszResType);
  373. }
  374. if (!bReturn)
  375. {
  376. m_ArrayImage.erase(pairInsert.first);
  377. SafeDelete(pImageInfo);
  378. SafeDelete(pImage);
  379. return NULL;
  380. }
  381. pImageInfo->pImage = pImage;
  382. pImageInfo->nRef = 1;
  383. return pImage;
  384. }
  385. }
  386. //删除图片
  387. void CRenderManager::RemoveImage( CImageEx *&pImage )
  388. {
  389. map<LPCTSTR, tagImageInfo *>::iterator iter;
  390. tagImageInfo * pImageInfo;
  391. if (NULL == pImage) return;
  392. for (iter = m_ArrayImage.begin(); iter != m_ArrayImage.end(); iter++)
  393. {
  394. pImageInfo = iter->second;
  395. if (pImageInfo != NULL)
  396. {
  397. if (pImageInfo->pImage == pImage)
  398. {
  399. pImageInfo->nRef--;
  400. if (pImageInfo->nRef <= 0)
  401. {
  402. pImageInfo->pImage->DestroyImage();
  403. SafeDelete(pImageInfo->pImage);
  404. SafeDelete(pImageInfo);
  405. m_ArrayImage.erase(iter);
  406. }
  407. pImage = NULL;
  408. break;
  409. }
  410. }
  411. }
  412. }
  413. //删除所有
  414. void CRenderManager::ClearImage()
  415. {
  416. map<LPCTSTR, tagImageInfo *>::iterator iter;
  417. tagImageInfo * pImageInfo;
  418. for (iter = m_ArrayImage.begin(); iter != m_ArrayImage.end(); iter++)
  419. {
  420. pImageInfo = iter->second;
  421. if (pImageInfo != NULL)
  422. {
  423. if (pImageInfo->pImage != NULL)
  424. {
  425. pImageInfo->pImage->DestroyImage();
  426. SafeDelete(pImageInfo->pImage);
  427. }
  428. SafeDelete(pImageInfo);
  429. }
  430. }
  431. m_ArrayImage.clear();
  432. }
  433. void CRenderManager::AddFont( LPCTSTR pStrFontName, int nSize, bool bBold, bool bUnderline, bool bItalic )
  434. {
  435. LOGFONT lf = { 0 };
  436. ::GetObject(::GetStockObject(DEFAULT_GUI_FONT), sizeof(LOGFONT), &lf);
  437. _tcsncpy_s(lf.lfFaceName, pStrFontName, LF_FACESIZE);
  438. lf.lfCharSet = DEFAULT_CHARSET;
  439. lf.lfHeight = -nSize;
  440. if( bBold ) lf.lfWeight += FW_BOLD;
  441. if( bUnderline ) lf.lfUnderline = TRUE;
  442. if( bItalic ) lf.lfItalic = TRUE;
  443. HFONT hFont = ::CreateFontIndirect(&lf);
  444. if( hFont != NULL )
  445. m_ArrayFont.push_back(hFont);
  446. }
  447. HFONT CRenderManager::GetFont( int nIndex )
  448. {
  449. if ( nIndex>(int)m_ArrayFont.size() ) return NULL;
  450. return m_ArrayFont.at(nIndex);
  451. }
  452. HFONT CRenderManager::GetEndFont()
  453. {
  454. return *(m_ArrayFont.end()-1);
  455. }
  456. void CRenderManager::GetRect( HWND hWnd,tagPositionData *pPositionData,CRect &rcPos )
  457. {
  458. CRect rcClient;
  459. GetClientRect(hWnd,&rcClient);
  460. //////////////////////////////位置////////////////////////////////////////////
  461. if (pPositionData->nFixedPostion[0] == en_LTop )
  462. {
  463. rcPos.left = pPositionData->ptPosition.x;
  464. rcPos.top = pPositionData->ptPosition.y;
  465. }
  466. else if (pPositionData->nFixedPostion[0] == en_RTop )
  467. {
  468. rcPos.left = rcClient.Width()-pPositionData->ptPosition.x;
  469. rcPos.top = pPositionData->ptPosition.y;
  470. }
  471. else if (pPositionData->nFixedPostion[0] == en_LBottom )
  472. {
  473. rcPos.left = pPositionData->ptPosition.x;
  474. rcPos.top = rcClient.Height()-pPositionData->ptPosition.y;
  475. }
  476. else if (pPositionData->nFixedPostion[0] == en_RBottom )
  477. {
  478. rcPos.left = rcClient.Width()-pPositionData->ptPosition.x;
  479. rcPos.top = rcClient.Height()-pPositionData->ptPosition.y;
  480. }
  481. ///////////////////////////////大小///////////////////////////////////////////
  482. if (pPositionData->nFixedPostion[1] == en_LTop )
  483. {
  484. rcPos.right = pPositionData->szSize.cx;
  485. rcPos.bottom = pPositionData->szSize.cy;
  486. }
  487. else if (pPositionData->nFixedPostion[1] == en_RTop )
  488. {
  489. rcPos.right = rcClient.Width()-pPositionData->szSize.cx;
  490. rcPos.bottom = pPositionData->szSize.cy;
  491. }
  492. else if (pPositionData->nFixedPostion[1] == en_LBottom )
  493. {
  494. rcPos.right = pPositionData->szSize.cx;
  495. rcPos.bottom = rcClient.Height()-pPositionData->szSize.cy;
  496. }
  497. else if (pPositionData->nFixedPostion[1] == en_RBottom )
  498. {
  499. rcPos.right = rcClient.Width()-pPositionData->szSize.cx;
  500. rcPos.bottom = rcClient.Height()-pPositionData->szSize.cy;
  501. }
  502. }