#include "stdAfx.h"
#include "mythreadfunction.h"
#include "dib.h"

UINT MyThreadFunction(LPVOID pParam)
{
	CDIBitmap *pDIB = (CDIBitmap *)pParam;

	int i,j;
	COLORREF c;

	pDIB->m_pBits = (BYTE*)malloc(pDIB->bmBitsSize);
	BYTE *pBits = pDIB->m_pBits; //!!!

	int x00 = pDIB->x0 + pDIB->width;
	int y00 = pDIB->y0 + pDIB->height;

	for(i=y00-1;i>=pDIB->y0;i--)
	{
		if(pDIB->copyStatus != 0)
		{
			pDIB->copyStatus = 2;//未完成屏幕复制
			return 0;
		}
		for(j=pDIB->x0;j<x00;j++)
		{
			Sleep(0);
			c = pDIB->pDC->GetPixel(j,i);
			*(pBits++) = GetBValue(c);
			*(pBits++) = GetGValue(c);
			*(pBits++) = GetRValue(c);
		}
		pBits += pDIB->remainBytes;
	}
	//初始化变量
	if(pDIB->isTwoBuffer)
	{
		pDIB->m_p2Bits = (BYTE*)malloc(pDIB->bmBitsSize);
		memcpy(pDIB->m_p2Bits,pDIB->m_pBits,pDIB->bmBitsSize);
	}
	pDIB->copyStatus = 1;//已完成屏幕复制
	return 0;
}