FaceList.cpp
资源名称:1731.rar [点击查看]
上传用户:swkcbjrc
上传日期:2016-04-02
资源大小:45277k
文件大小:6k
源码类别:
游戏
开发平台:
Visual C++
- // FaceList.cpp: implementation of the CFaceList class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "gamehigh.h"
- #include "FaceList.h"
- #include "basefunction.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CFaceList::CFaceList()
- {
- }
- CFaceList::~CFaceList()
- {
- if(m_ImgList1.GetSafeHandle() &&
- 0 != m_ImgList1.GetImageCount())
- {
- m_ImgList1.DeleteImageList();
- }
- if(m_ImgList2.GetSafeHandle() &&
- 0 != m_ImgList2.GetImageCount())
- {
- m_ImgList2.DeleteImageList();
- }
- if(m_ImgList3.GetSafeHandle() &&
- 0 != m_ImgList3.GetImageCount())
- {
- m_ImgList3.DeleteImageList();
- }
- if(m_ImgBkList.GetSafeHandle() &&
- 0 != m_ImgBkList.GetImageCount())
- {
- m_ImgBkList.DeleteImageList();
- }
- }
- BOOL CFaceList::Init()
- {
- char CurPath[MAX_PATH];
- memset(CurPath, 0, sizeof(char) * MAX_PATH);
- GetCurrentPath(CurPath);
- COLORREF clrTransparent =RGB(0, 128, 128);
- strcat(CurPath, "Faces\");
- m_ImgList1.Create(LARGEICON_SIZE, LARGEICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
- m_ImgList1.SetBkColor(clrTransparent);
- for(int i=0; i<IMG_COUNT; i++)
- {
- char buffer[20];
- memset(buffer, 0, sizeof(char) * 20);
- wsprintf(buffer, "%d-1.bmp", i + 1);
- CString file ="";
- file =CurPath;
- file +=buffer;
- HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
- IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if(hBmp)
- {
- CBitmap* pBitmap =NULL;
- pBitmap =pBitmap->FromHandle(hBmp);
- if(pBitmap && pBitmap->GetSafeHandle())
- {
- int nret =m_ImgList1.Add(pBitmap, clrTransparent);
- }
- pBitmap->DeleteObject();
- hBmp =NULL;
- }
- }
- m_ImgList2.Create(LARGEICON_SIZE, LARGEICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
- m_ImgList2.SetBkColor(clrTransparent);
- for(i=0; i<IMG_COUNT; i++)
- {
- char buffer[20];
- memset(buffer, 0, sizeof(char) * 20);
- wsprintf(buffer, "%d-2.bmp", i + 1);
- CString file ="";
- file =CurPath;
- file +=buffer;
- HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
- IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if(hBmp)
- {
- CBitmap* pBitmap =NULL;
- pBitmap =pBitmap->FromHandle(hBmp);
- if(pBitmap && pBitmap->GetSafeHandle())
- {
- int nret =m_ImgList2.Add(pBitmap, clrTransparent);
- }
- pBitmap->DeleteObject();
- hBmp =NULL;
- }
- }
- m_ImgList3.Create(LARGEICON_SIZE, LARGEICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
- m_ImgList3.SetBkColor(clrTransparent);
- for(i=0; i<IMG_COUNT; i++)
- {
- char buffer[20];
- memset(buffer, 0, sizeof(char) * 20);
- wsprintf(buffer, "%d-3.bmp", i + 1);
- CString file ="";
- file =CurPath;
- file +=buffer;
- HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
- IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if(hBmp)
- {
- CBitmap* pBitmap =NULL;
- pBitmap =pBitmap->FromHandle(hBmp);
- if(pBitmap && pBitmap->GetSafeHandle())
- {
- int nret =m_ImgList3.Add(pBitmap, clrTransparent);
- }
- pBitmap->DeleteObject();
- hBmp =NULL;
- }
- }
- //背景图片
- memset(CurPath, 0, sizeof(char) * MAX_PATH);
- GetCurrentPath(CurPath);
- clrTransparent =RGB(255, 0, 0);
- strcat(CurPath, "TabBack\");
- m_ImgBkList.Create(BKICON_SIZE, BKICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, BKIMG_COUNT);
- m_ImgBkList.SetBkColor(clrTransparent);
- for(i=0; i<BKIMG_COUNT; i++)
- {
- char buffer[20];
- memset(buffer, 0, sizeof(char) * 20);
- wsprintf(buffer, "%d.bmp", i + 1);
- CString file ="";
- file =CurPath;
- file +=buffer;
- HBITMAP hBmp =(HBITMAP)::LoadImage(::AfxGetInstanceHandle(), file,
- IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if(hBmp)
- {
- CBitmap* pBitmap =NULL;
- pBitmap =pBitmap->FromHandle(hBmp);
- if(pBitmap && pBitmap->GetSafeHandle())
- {
- int nret =m_ImgBkList.Add(pBitmap, clrTransparent);
- }
- pBitmap->DeleteObject();
- hBmp =NULL;
- }
- }
- //16 * 16的图像
- m_ImgList4.Create(SMALLICON_SIZE, SMALLICON_SIZE, ILC_COLORDDB | ILC_MASK , 0, MAX_FACE);
- m_ImgList4.SetBkColor(clrTransparent);
- for(i=0; i<IMG_COUNT; i++)
- {
- HICON hIcon =m_ImgList1.ExtractIcon(i);
- SAFE_CHECKPOINTER(hIcon)
- {
- CBitmap* pBmp =MakeIcon2Bmp(hIcon,
- SMALLICON_SIZE, SMALLICON_SIZE, clrTransparent);
- if(NULL != pBmp &&
- NULL != pBmp->GetSafeHandle())
- {
- m_ImgList4.Add(pBmp, clrTransparent);
- pBmp->DeleteObject();
- delete pBmp;
- pBmp =NULL;
- }
- ::DestroyIcon(hIcon);
- hIcon =NULL;
- }
- }
- return TRUE;
- }
- CImageList* CFaceList::GetImageList1()
- {
- return &m_ImgList1;
- }
- CImageList* CFaceList::GetImageList2()
- {
- return &m_ImgList2;
- }
- CImageList* CFaceList::GetImageList3()
- {
- return &m_ImgList3;
- }
- CImageList* CFaceList::GetImageList4()
- {
- return &m_ImgList4;
- }
- CImageList* CFaceList::GetBkImgList()
- {
- return &m_ImgBkList;
- }
- CBitmap* CFaceList::MakeIcon2Bmp(HICON hIcon, int ncx, int ncy, COLORREF clrBk)
- {
- ASSERT(hIcon);
- if(NULL == hIcon)
- return NULL;
- CBitmap *newBitmap = new CBitmap;
- int ncolordepth =24;
- HWND hWnd =::GetDesktopWindow();
- if(::IsWindow(hWnd))
- {
- HDC hDC =::GetDC(hWnd);
- if(NULL != hDC)
- {
- ncolordepth =::GetDeviceCaps(hDC, BITSPIXEL);
- }
- ::ReleaseDC(hWnd, hDC);
- }
- newBitmap->CreateBitmap(ncx, ncy, 1, ncolordepth, NULL);
- CBrush m_Brush;
- m_Brush.CreateSolidBrush(clrBk);
- CDC memDC;
- memDC.CreateCompatibleDC(NULL);
- RECT rect;
- memset(&rect, 0, sizeof(RECT));
- rect.right =ncx;
- rect.bottom =ncy;
- memDC.FillRect(&rect, &m_Brush);
- m_Brush.DeleteObject();
- CBitmap *oldBitmap = memDC.SelectObject(newBitmap);
- ::DrawIconEx(memDC.GetSafeHdc(), 0, 0, hIcon, ncx, ncy, 0, 0, DI_NORMAL);
- memDC.SelectObject(oldBitmap);
- return newBitmap;
- }