www.gusucode.com > VC++高仿迅雷7漂亮界面开源源码-源码程序 > VC++高仿迅雷7漂亮界面开源源码-源码程序/code/LEinGUI/MFC_GRAPHICS.cpp
#include "stdafx.h" #include "MFC_GRAPHICS.h" // Download by http://www.NewXing.com CMFC_GRAPHICS::CMFC_GRAPHICS() { m_hbitmap = NULL; } CMFC_GRAPHICS::~CMFC_GRAPHICS() { } void CMFC_GRAPHICS::Create(int width, int height, CWnd* pwnd, CDC* pDC, int gslotindex) { HDC hWindowDC; _BMPINFO BitmapInfo; m_width = width; m_height = height; BitmapInfo.bmiHeader.biWidth = width; BitmapInfo.bmiHeader.biHeight = 0 - height; BitmapInfo.bmiHeader.biBitCount = 32; BitmapInfo.bmiHeader.biSize = sizeof( BITMAPINFOHEADER ); BitmapInfo.bmiHeader.biPlanes = 1; BitmapInfo.bmiHeader.biCompression = BI_RGB; BitmapInfo.bmiHeader.biSizeImage = 0; BitmapInfo.bmiHeader.biClrImportant = 0; BitmapInfo.bmiHeader.biClrUsed = 0; BitmapInfo.bmiHeader.biXPelsPerMeter = 0; BitmapInfo.bmiHeader.biYPelsPerMeter = 0; hWindowDC = GetDC( pwnd->GetSafeHwnd() ); m_hbitmap = CreateDIBSection( hWindowDC, (BITMAPINFO*)&BitmapInfo, DIB_RGB_COLORS, (void**)&m_pvb, NULL, 0 ); ::ReleaseDC(pwnd->GetSafeHwnd(), hWindowDC); CBitmap bmp; bmp.Attach(m_hbitmap); BITMAP bitp; bmp.GetBitmap(&bitp); m_draw = CLAYUI_CreateGraphics(m_pvb, width, height, 4, bitp.bmWidthBytes, gslotindex); bmp.Detach(); bmp.DeleteObject(); m_memdc.CreateCompatibleDC(pDC); m_oldbmp = (HBITMAP)m_memdc.SelectObject(m_hbitmap); m_xpitch = 4; m_ypitch = bitp.bmWidthBytes; CLAYUI_HLG_SetHDC(m_draw, m_memdc.m_hDC); } void CMFC_GRAPHICS::OnLButtonDown(int x, int y) { CLAYUI_HL_ONLButtonDown(m_draw, x, y, 0); } void CMFC_GRAPHICS::OnMouseMove(int x, int y) { CLAYUI_HL_ONMouseMove(m_draw, x, y, 0); } void CMFC_GRAPHICS::OnLButtonUP(int x, int y) { CLAYUI_HL_ONLButtonUp(m_draw, x, y, 0); } void CMFC_GRAPHICS::OnRButtonDown(int x, int y) { CLAYUI_HL_ONRButtonDown(m_draw, x, y, 0); } void CMFC_GRAPHICS::OnRButtonUP(int x, int y) { CLAYUI_HL_ONRButtonUp(m_draw, x, y, 0); } void CMFC_GRAPHICS::Draw() { CLAYUI_HLG_Draw(m_draw); } void CMFC_GRAPHICS::Reset() { CLAYUI_ResetGraphics(m_draw); } void CMFC_GRAPHICS::SetClearColor(short r, short g, short b, short a) { CLAYUI_HLG_SetClearColor(m_draw, r, g, b, a); } void CMFC_GRAPHICS::AttachToRootFrame(CLAYUI_BFRAME *rootframe) { CLAYUI_HLG_AttachToRootBFrame(rootframe, m_draw); } void CMFC_GRAPHICS::GetDirtyRect(int &x, int &y, int &width, int &height) { CLAYUI_HL_GetDirtyRect(m_draw, x, y, width, height); } void CMFC_GRAPHICS::Release(void) { CLAYUI_ReleaseGraphics(m_draw); if(m_oldbmp) { m_memdc.SelectObject(m_oldbmp); m_memdc.DeleteDC(); } if(m_hbitmap) DeleteObject(m_hbitmap); }