亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? my_directdraw.cpp

?? 一個斗地主的小程序。。。。。。。。。。多多指教
?? CPP
字號:

#include "stdafx.h"
#include "MainFrm.h"

#include "Game.h"
#include "My_DirectInput.h"
#include "my_directdraw.h"

#include "Draw_Cards_Engine.h"

#include "Playing_Cards.h"


#include <io.h>

CMyDirectDraw::CMyDirectDraw()
{
	lpdd         = NULL;   // dd object
	lpddclipper  = NULL;   // dd clipper

	bitmap.buffer = NULL; //記住!!!!!!初始化!!!!!永遠的傷
	start_clock_count = 0; // used for timing

	SCREEN_BPP = 32;

}


int CMyDirectDraw::Flip_Bitmap(UCHAR *image, int bytes_per_line, int height)
{
// 將數據讀入表面

	UCHAR *buffer; // used to perform the image processing
	int index;  

	if (!(buffer = (UCHAR *)new UCHAR[bytes_per_line*height]) )
		return(0);

	memcpy(buffer,image,bytes_per_line*height);

	for (index=0; index < height; index++)
	{
	    memcpy(&image[((height-1) - index)*bytes_per_line],
			   &buffer[index*bytes_per_line], bytes_per_line);
	}

// release the memory
	delete(buffer);

	return(1);

} // end Flip_Bitmap

//讀取位圖的方法:

int CMyDirectDraw::Load_Bitmap_File(BITMAP_FILE_PTR bitmap, char *filename)
{
//
	int file_handle;  // the file handle
       
	UCHAR   *temp_buffer = NULL; 
	OFSTRUCT file_data;     

// 打開文件如果它存在;
	if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
	   return(0);


	_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));


	if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
	{
		//如果不是位圖,則關閉文件,返回;
	  _lclose(file_handle);
	  return(0);
    } // end if

// 發現是位圖,繼續;

// 讀取文件頭;
	_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));

//如果是8位位圖,則返回;
	if (bitmap->bitmapinfoheader.biBitCount == 8)
	{
		AfxMessageBox("本游戲不能讀取8位位圖!");
		return 0;
	} // end if

	//從文件結尾反向搜位圖數據字節大小的長度;
	_lseek(file_handle,(int)(sizeof(BITMAPFILEHEADER)+
	   sizeof(BITMAPINFOHEADER)),SEEK_SET);

	int Image_Size = bitmap->bitmapfileheader.bfSize-
		(sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER));

	if (bitmap->bitmapinfoheader.biBitCount==8 || bitmap->bitmapinfoheader.biBitCount==16 || 
	    bitmap->bitmapinfoheader.biBitCount==24)
    {
//如果位圖存在,則先釋放;
	   if (bitmap->buffer)
	       free(bitmap->buffer);


	   if ( !(bitmap->buffer = (UCHAR *)new UCHAR [Image_Size]) )
	      {
 
			_lclose(file_handle);
			return(0);
	      } 
	   _lread(file_handle,bitmap->buffer,Image_Size);

	} 
	else
	{
   //見鬼了!
	   return(0);
    } 

	_lclose(file_handle);

// flip the bitmap
	Flip_Bitmap(bitmap->buffer, 
	            bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8), 
	            bitmap->bitmapinfoheader.biHeight);

	return(1);

} 

int CMyDirectDraw::Unload_Bitmap_File(BITMAP_FILE_PTR bitmap)
{
// this function releases all memory associated with "bitmap"
	if (bitmap->buffer)
	{
   // release memory
	   delete(bitmap->buffer);

	   bitmap->buffer = NULL;
    } 
	return(1);

} 

int CMyDirectDraw::Scan_Image_Bitmap(BITMAP_FILE_PTR bitmap,     // bitmap file to scan image data from
				                      LPDIRECTDRAWSURFACE7 lpdds, // surface to hold data
				                      int cx, int cy)             // cell to scan image from
{
//將位圖像素寫到表面去!
	DDSURFACEDESC2 ddsd;  //  direct draw surface description 
 
// set size of the structure
	ddsd.dwSize = sizeof(ddsd);

// lock the display surface
	lpdds->Lock(NULL,
	            &ddsd,
	            DDLOCK_WAIT | DDLOCK_SURFACEMEMORYPTR,
	            NULL);

	cx = cx*(ddsd.dwWidth+1) + 1;
	cy = cy*(ddsd.dwHeight+1) + 1;

	DWORD *dest_ptr;
	UCHAR blue,green,red;
	dest_ptr = (DWORD *)ddsd.lpSurface;

	for (DWORD index_y = 0; index_y < ddsd.dwHeight; index_y++)
	{
		for (DWORD index_x = 0; index_x < ddsd.dwWidth; index_x++)
		{
        // get BGR values;;;;
			int index = index_y*(bitmap->bitmapinfoheader.biWidth)*3 + index_x*3;

			blue  = bitmap->buffer[index + 0];
			green = bitmap->buffer[index + 1];
			red   = bitmap->buffer[index + 2];

        // 32位RGB數;
			DWORD pixel = _RGB32BIT(0,red,green,blue);

			dest_ptr[index_x + (index_y*ddsd.lPitch >> 2)] = pixel;
		} 
			
	} 

	// unlock the surface 
	lpdds->Unlock(NULL);

	return(1);
}

//填充表面的方法
int CMyDirectDraw::FillSurface(LPDIRECTDRAWSURFACE7 lpdds,int color)
{
	DDBLTFX ddbltfx;

//初始化ddbltfx結構;
	DDRAW_INIT_STRUCT(ddbltfx);

// 需要填空全屏的顏色值;
	ddbltfx.dwFillColor = color; 

// blt to surface
	lpdds->Blt(
			   NULL,       // ptr to dest rectangle
	           NULL,       // ptr to source surface, NA            
	           NULL,       // ptr to source rectangle, NA
	           DDBLT_COLORFILL | DDBLT_WAIT,   // fill and wait                   
		       &ddbltfx
			   );  // ptr to DDBLTFX structure


	return(1);
} // end FillSurface

//根據傳入參數建立相應的表面
LPDIRECTDRAWSURFACE7 CMyDirectDraw::CreateSurface(
										  int width,
										  int height,
										  int mem_flags,
										  int color = 0)
{
// this function creates an offscreen plain surface

	DDSURFACEDESC2 ddsd;         // working description
	LPDIRECTDRAWSURFACE7 lpdds;  // temporary surface
    
// set to access caps, width, and height
	memset(&ddsd,0,sizeof(ddsd));
	ddsd.dwSize  = sizeof(ddsd);
	ddsd.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;

// set dimensions of the new bitmap surface
	ddsd.dwWidth  =  width;
	ddsd.dwHeight =  height;

// set surface to offscreen plain
	ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN | mem_flags;

// create the surface
	if (FAILED(lpdd->CreateSurface(&ddsd,&lpdds,NULL)))
	   return(NULL);

// test if user wants a color key
	if (color >= 0)
    {
   // set color key to color 0
	   DDCOLORKEY color_key; // used to set color key
	   color_key.dwColorSpaceLowValue  = color;
	   color_key.dwColorSpaceHighValue = color;

   // now set the color key for source blitting
	   lpdds->SetColorKey(DDCKEY_SRCBLT, &color_key);
	}  // end if

// return surface
	return(lpdds);
} // end CreateSurface

int CMyDirectDraw::DrawSurface(
					  LPDIRECTDRAWSURFACE7 source, // source surface to draw
                      int x, int y,                 // position to draw at
                      int width, int height,        // size of source surface
                      LPDIRECTDRAWSURFACE7 dest,    // surface to draw the surface on
                      int transparent = 1)          // transparency flag
{
// draw a bob at the x,y defined in the BOB
// on the destination surface defined in dest

	RECT dest_rect,   // the destination rectangle
		 source_rect; // the source rectangle                             

// fill in the destination rect
	dest_rect.left   = x;
	dest_rect.top    = y;
	dest_rect.right  = x+width;
	dest_rect.bottom = y+height;

// fill in the source rect
	source_rect.left    = 0;
	source_rect.top     = 0;
	source_rect.right   = width;
	source_rect.bottom  = height;

// test transparency flag

	if (transparent)
    {
   // enable color key blit
   // blt to destination surface
	   if (FAILED(dest->Blt(&dest_rect, source,
                     &source_rect,(DDBLT_WAIT | DDBLT_KEYSRC),
                     NULL)))
            return(0);

	} // end if
	else
    {
   // perform blit without color key
   // blt to destination surface
		if (FAILED(dest->Blt(&dest_rect, source,
                     &source_rect,(DDBLT_WAIT),
                     NULL)))
           return(0);

	} // end if

// return success
	return(1);

} // end DrawSurface
//創建剪切的方法:
LPDIRECTDRAWCLIPPER CMyDirectDraw::AttachClipper(
										 LPDIRECTDRAWSURFACE7 lpdds,
                                         int num_rects,
                                         LPRECT clip_list)

{
// this function creates a clipper from the sent clip list and attaches
// it to the sent surface

	int index;                         // looping var
	LPDIRECTDRAWCLIPPER lpddclipper;   // pointer to the newly created dd clipper
	LPRGNDATA region_data;             // pointer to the region data that contains
                                   // the header and clip list

// first create the direct draw clipper
	if (FAILED(lpdd->CreateClipper(0,&lpddclipper,NULL)))
	   return(NULL);

// now create the clip list from the sent data

// first allocate memory for region data
	region_data = (LPRGNDATA)malloc(sizeof(RGNDATAHEADER)+num_rects*sizeof(RECT));

// now copy the rects into region data
	memcpy(region_data->Buffer, clip_list, sizeof(RECT)*num_rects);

// set up fields of header
	region_data->rdh.dwSize          = sizeof(RGNDATAHEADER);
	region_data->rdh.iType           = RDH_RECTANGLES;
	region_data->rdh.nCount          = num_rects;
	region_data->rdh.nRgnSize        = num_rects*sizeof(RECT);

	region_data->rdh.rcBound.left    =  64000;
	region_data->rdh.rcBound.top     =  64000;
	region_data->rdh.rcBound.right   = -64000;
	region_data->rdh.rcBound.bottom  = -64000;

// find bounds of all clipping regions
	for (index=0; index<num_rects; index++)
    {
    // test if the next rectangle unioned with the current bound is larger
	    if (clip_list[index].left < region_data->rdh.rcBound.left)
	        region_data->rdh.rcBound.left = clip_list[index].left;

	    if (clip_list[index].right > region_data->rdh.rcBound.right)
	        region_data->rdh.rcBound.right = clip_list[index].right;

	    if (clip_list[index].top < region_data->rdh.rcBound.top)
	        region_data->rdh.rcBound.top = clip_list[index].top;

	    if (clip_list[index].bottom > region_data->rdh.rcBound.bottom)
	        region_data->rdh.rcBound.bottom = clip_list[index].bottom;

    } // end for index

// now we have computed the bounding rectangle region and set up the data
// now let's set the clipping list

	if (FAILED(lpddclipper->SetClipList(region_data, 0)))
    {
   // release memory and return error
		free(region_data);
		return(NULL);
	} // end if

// now attach the clipper to the surface
	if (FAILED(lpdds->SetClipper(lpddclipper)))
    {
   // release memory and return error
	   free(region_data);
	   return(NULL);
	} // end if

// all is well, so release memory and send back the pointer to the new clipper
	free(region_data);
	return(lpddclipper);

} 
//調試用;
int CMyDirectDraw::DebugText(char* text,int time)
{
	HDC xdc; // the working dc


	if (FAILED(lpddsprimary->GetDC(&xdc)))
	   return(0);

	SetBkMode(xdc, TRANSPARENT);

	TextOut(xdc,140,500,text,strlen(text));

	lpddsprimary->ReleaseDC(xdc);

	::Sleep(time);

	return 1;
}

int CMyDirectDraw::TextGDI(
								char *text,
								int x,
								int y,
								COLORREF color,
								int size,
								char* type,
								LPDIRECTDRAWSURFACE7 lpdds)
{	
	HDC xdc; 
	if (FAILED(lpdds->GetDC(&xdc)))
	   return(0);

	LOGFONT my_font;
	memset(&my_font,0,sizeof(LOGFONT));

	my_font.lfCharSet = DEFAULT_CHARSET;
	my_font.lfHeight = size;
//	lstrcpyn(my_font.lfFaceName, type, _countof(my_font.lfFaceName));
	sprintf(my_font.lfFaceName,type);

	POINT pt;
	pt.y = ::GetDeviceCaps(xdc, LOGPIXELSY) * my_font.lfHeight;
	pt.y /= 720;    // 72 points/inch, 10 decipoints/point
	::DPtoLP(xdc, &pt, 1);
	POINT ptOrg = { 0, 0 };
	::DPtoLP(xdc, &ptOrg, 1);
	my_font.lfHeight = -abs(pt.y - ptOrg.y);


	HFONT hFont;
	hFont = ::CreateFontIndirect(&my_font);

//	dc.m_hDC  = xdc;
	//新字體對象及指針;
//	CFont my_font;
	//把新建字體選進描述中;
//	my_font.CreatePointFont(size,type,NULL);//創建自己的字體;
//	old_font = dc.SelectObject(&my_font);  //選擇新的字體;


	SelectObject(xdc,hFont);
	SetTextColor(xdc,color);
	SetBkMode(xdc,TRANSPARENT);
	TextOut(xdc,x,y,text,strlen(text));

	//恢復原設備描述符表的字體;
	DeleteObject(hFont);
	lpdds->ReleaseDC(xdc);

	return 1;
}
//初始化DD平臺;
int CMyDirectDraw::Init()
{
//	pCMainFrame = *)AfxGetMainWnd();

	if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
	{
		   return(0);
	}
// set cooperation to full screen
	if(FAILED(lpdd->SetCooperativeLevel(::pCMainFrame->m_hWnd, 
									 DDSCL_ALLOWMODEX | DDSCL_FULLSCREEN |
                                     DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT)) )  // 
	{
		   return(0);
	}

	if (FAILED(lpdd->SetDisplayMode(Screen_Width, Screen_Height, SCREEN_BPP,0,0)))
	{
		   return(0);
	}

	DDRAW_INIT_STRUCT(ddsd);  //清零的宏;

	// enable valid fields
	ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;

// set the backbuffer count field to 1, use 2 for triple buffering
	ddsd.dwBackBufferCount = 1;

// request a complex, flippable
	ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_COMPLEX | DDSCAPS_FLIP;

// 創建主表面;
	if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL)))
			return(0);

	ddsd.ddsCaps.dwCaps = DDSCAPS_BACKBUFFER;

	if (FAILED(lpddsprimary->GetAttachedSurface(&ddsd.ddsCaps, &lpddsback)))
		  return(0);

//設置后備緩沖區的剪裁區;
	RECT screen_rect= {0,0,Screen_Width,Screen_Height};
	lpddclipper = AttachClipper(lpddsback,1,&screen_rect);


	return 1;
} 

int CMyDirectDraw::BitmapToSurface(
						LPDIRECTDRAWSURFACE7 Dest_Surface,  //目的表面;
						int Dest_x,		//目的表面x座標;
						int Dest_y,		//目的表面y座標;
						char* filename,	//源位圖文件名;	
						int Bitmap_Width,	//位圖寬;
						int Bitmap_Height	//位圖長;
						)
{
	HBITMAP hbitmap;
	HDC hdc;   //接受當前設備環境句柄;
	HDC dhdc;
	CString str;

	hdc = ::CreateCompatibleDC(NULL);

	hbitmap = (HBITMAP)::LoadImage(NULL,filename,IMAGE_BITMAP,Bitmap_Width,Bitmap_Height,LR_LOADFROMFILE); 

	if(hbitmap==NULL)
	{
		str.Format("無法載入位圖%s",filename);
		AfxMessageBox(str);
		return 0;
	}

	::SelectObject(hdc,hbitmap);

	Dest_Surface->GetDC( &dhdc );
	::BitBlt( dhdc , Dest_x , Dest_y ,Bitmap_Width,Bitmap_Height, hdc , 0 , 0 , SRCCOPY );
	Dest_Surface->ReleaseDC(dhdc);

	return 1;
}

CMyDirectDraw::~CMyDirectDraw()
{
// now the primary surface
//	if (lpddsprimary)
 //   {
//		lpddsprimary->Release();
//		lpddsprimary = NULL;
//	} // end if
//后備緩沖
//	if(lpddsback)
//	{
//		lpddsback->Release();
//		lpddsback = NULL;
//	}
//離屏表面;
//	if(lpddsbackground)
//	{
//		lpddsbackground->Release();
//		lpddsbackground = NULL;
//	}	
// now blow away the IDirectDraw4 interface
	if (lpdd)
    {
		lpdd->Release();
		lpdd = NULL;
    } // end if
} 


?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国内精品第一页| 日韩美女天天操| 欧美成人精品福利| 一区二区三区欧美在线观看| 免费视频最近日韩| 91久久精品国产91性色tv| 久久久国产精品午夜一区ai换脸| 亚洲成精国产精品女| 成人免费的视频| 国产亚洲午夜高清国产拍精品| 午夜精品福利在线| 日本高清不卡视频| 中文字幕亚洲一区二区va在线| 精品一区二区三区的国产在线播放| 欧美亚洲图片小说| 亚洲猫色日本管| 成人av免费在线观看| 久久久一区二区三区| 美女视频黄久久| 欧美精品日韩精品| 亚洲成人久久影院| 欧美精品三级在线观看| 亚洲成人免费影院| 欧美一区二区三区日韩| 天天操天天色综合| 91精品国产欧美一区二区| 亚洲成人黄色小说| 777xxx欧美| 日本成人在线网站| 欧美一级欧美三级| 久久99久久久久| 久久亚洲综合av| 风间由美一区二区三区在线观看 | 久久众筹精品私拍模特| 青青草伊人久久| 日韩精品一区二区三区中文精品 | 欧美亚洲高清一区| 一区二区三区四区中文字幕| 不卡的电视剧免费网站有什么| 国产无人区一区二区三区| 国产不卡免费视频| 国产精品大尺度| 在线观看网站黄不卡| 午夜精品影院在线观看| 日韩片之四级片| 韩国视频一区二区| 国产精品成人在线观看| 日韩免费电影一区| 国产精品一区二区久久不卡| 日本一区二区三区久久久久久久久不 | 国产精品国产三级国产aⅴ原创 | 国产精品亚洲第一区在线暖暖韩国| 久久久亚洲精品石原莉奈| 岛国一区二区在线观看| 亚洲一区二区三区国产| 欧美电影免费观看高清完整版在| 久久99蜜桃精品| 中文字幕中文在线不卡住| 欧美午夜一区二区三区免费大片| 奇米色777欧美一区二区| 久久色在线视频| 色综合天天综合给合国产| 视频一区欧美精品| 国产精品天干天干在线综合| 欧美日韩一区二区三区四区 | 亚洲第一激情av| 久久久亚洲精品一区二区三区| 色综合一区二区| 美女mm1313爽爽久久久蜜臀| 国产精品久久久久久久浪潮网站 | 成人av在线影院| 日本欧洲一区二区| 国产欧美一区视频| 欧美一区中文字幕| 91浏览器入口在线观看| 韩国视频一区二区| 午夜精品久久一牛影视| 国产精品私人自拍| 欧美一区二区精美| 色婷婷av一区二区三区软件| 国产美女视频91| 日韩av在线免费观看不卡| 国产精品灌醉下药二区| 精品久久久久久无| 69av一区二区三区| 色噜噜偷拍精品综合在线| 国产精品亚洲成人| 另类小说图片综合网| 亚洲第一久久影院| 一区二区三区成人| 国产精品传媒入口麻豆| 国产日韩av一区二区| 精品久久久网站| 日韩一区二区三区四区 | 色系网站成人免费| 国产精品99久久久久| 免费欧美在线视频| 午夜在线成人av| 亚洲精品免费在线观看| 国产精品色在线观看| 久久久国产精华| xnxx国产精品| 欧美不卡一二三| 91精品久久久久久久久99蜜臂| 欧美三级中文字幕在线观看| 色婷婷av一区二区三区大白胸| 国产一区二区精品久久99| 精品在线免费观看| 蜜桃视频一区二区三区在线观看| 同产精品九九九| 午夜视频在线观看一区| 天堂午夜影视日韩欧美一区二区| 亚洲一区二区三区四区五区黄| 亚洲欧美日韩精品久久久久| 成人免费在线视频| 亚洲日本中文字幕区| 亚洲欧美日韩一区| 亚洲国产一区在线观看| 亚洲va欧美va天堂v国产综合| 亚洲地区一二三色| 全国精品久久少妇| 久久精品二区亚洲w码| 国产老肥熟一区二区三区| 国产成人精品aa毛片| 91在线精品一区二区| 91福利在线导航| 欧美一区二区三区不卡| 精品久久一区二区三区| 亚洲国产精品二十页| 亚洲欧美一区二区三区孕妇| 亚洲一区二区在线免费观看视频 | 亚洲人成影院在线观看| 亚洲美女偷拍久久| 日本强好片久久久久久aaa| 久久99精品久久久久婷婷| 国产成人在线视频网站| 91免费国产在线| 欧美精品久久久久久久多人混战 | 亚洲精品亚洲人成人网| 亚洲不卡一区二区三区| 国产美女娇喘av呻吟久久 | 精东粉嫩av免费一区二区三区| 国产在线精品一区在线观看麻豆| 不卡一卡二卡三乱码免费网站| 色先锋资源久久综合| 日韩欧美激情一区| 亚洲视频一区二区在线观看| 五月婷婷欧美视频| 国产一区高清在线| 在线观看国产91| 久久奇米777| 亚洲国产精品久久一线不卡| 久久国产精品第一页| www.日本不卡| 91精品国产手机| 国产精品国产三级国产aⅴ无密码| 午夜精品久久久久久久99水蜜桃 | 欧美日韩国产一区二区三区地区| 精品久久99ma| 一区二区三国产精华液| 国产精品资源在线观看| 欧美性受xxxx黑人xyx| 国产精品色眯眯| 久久av资源站| 欧美妇女性影城| 亚洲免费伊人电影| 国产成人免费视频网站| 制服丝袜av成人在线看| 亚洲欧美经典视频| 国产老女人精品毛片久久| 91精品久久久久久蜜臀| 有码一区二区三区| 国产**成人网毛片九色| 7777精品伊人久久久大香线蕉最新版 | 欧美韩国日本一区| 久久er99精品| 91精品国产色综合久久| 亚洲精品美腿丝袜| 成人丝袜高跟foot| 久久夜色精品国产噜噜av| 爽好久久久欧美精品| 欧美日韩美女一区二区| 亚洲欧美视频一区| 91蜜桃视频在线| 国产精品欧美一级免费| 国产大陆a不卡| 26uuu精品一区二区在线观看| 午夜精品一区在线观看| 欧美日韩五月天| 一区二区三区日韩欧美精品| 91免费精品国自产拍在线不卡| 日韩手机在线导航| 国产精品美女久久久久久2018| 精品一区二区三区蜜桃| 日韩欧美一区在线| 日日欢夜夜爽一区| 欧美一区二区三区性视频| 三级久久三级久久| 正在播放亚洲一区| 蜜桃视频一区二区|