void CScreenCapSysV2Dlg::OnConnect() 
{
// TODO: Add your control notification handler code here
if(m_socket.Create()){
m_socket.Connect("127.0.0.1",5037);

UpdateData(false);
CString command  = "host:transport-usb";
CString adbresult = ConvertAdbCommand(command);
m_socket.Send(adbresult,strlen(adbresult));
char RecvCon[4];
int  RecvSz = m_socket.Receive(RecvCon,sizeof RecvCon,0);
RecvCon[RecvSz]=NULL;


int countBuf=0;
BfInfo *bf = new BfInfo;
command = "framebuffer:";
CString adbresult1 = ConvertAdbCommand(command);
m_socket.Send(adbresult1,strlen(adbresult1));
memset(RecvCon,0,sizeof RecvCon);
RecvSz = m_socket.Receive(RecvCon,sizeof RecvCon,0);
        countBuf = m_socket.Receive(bf,sizeof *bf,0);
CString bftoString;
bftoString.Format("width : %d alpha_length: %d",bf->size,bf->alpha_length);


AfxMessageBox(bftoString);
BITMAPFILEHEADER bitmapFileHeader;

bitmapFileHeader.bfSize = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER)+(DWORD)((bf->width*32+31)/32)*4*bf->height;
bitmapFileHeader.bfType = (WORD)0x4D42;
        bitmapFileHeader.bfReserved1 = 0;
bitmapFileHeader.bfReserved2 = 0;
        bitmapFileHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER)+(DWORD)sizeof(BITMAPINFOHEADER);

        BITMAPINFOHEADER bitmapInfoHeader;

bitmapInfoHeader.biHeight = (LONG)bf->height;
bitmapInfoHeader.biWidth = (LONG)bf->width;
bitmapInfoHeader.biSize = (DWORD)sizeof(BITMAPINFOHEADER);
bitmapInfoHeader.biPlanes = 1;
bitmapInfoHeader.biCompression = BI_RGB;
bitmapInfoHeader.biSizeImage = 0;
bitmapInfoHeader.biClrUsed = 0;
bitmapInfoHeader.biBitCount = (WORD)bf->bpp;
bitmapInfoHeader.biClrImportant = 0;
bitmapInfoHeader.biXPelsPerMeter = 0;
bitmapInfoHeader.biYPelsPerMeter = 0;



char* MBuf = (char*)malloc(bitmapFileHeader.bfSize);
memset(MBuf,0,bitmapFileHeader.bfSize);
memcpy(MBuf,&bitmapFileHeader,sizeof(BITMAPFILEHEADER));
memcpy(MBuf+sizeof(BITMAPFILEHEADER),&bitmapInfoHeader,sizeof(BITMAPINFOHEADER));
char* bmDataStart = MBuf+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER);
char* bmDataEnd = MBuf+sizeof(BITMAPFILEHEADER)+sizeof(BITMAPINFOHEADER)+bf->size;
char BmTempBuf[640];
int currentRECV = 0;
while(currentRECV<bf->size)
{
int retCount = m_socket.Receive(BmTempBuf,sizeof BmTempBuf,0);
if(retCount<0)break;
memcpy(bmDataStart+currentRECV,BmTempBuf,retCount);
currentRECV+=retCount;

char rowBuf[1080*4];
int rowNumConst = sizeof rowBuf;
int rowCount = 0;
for (rowCount=rowNumConst;rowCount<=bf->height/2*rowNumConst;rowCount+=rowNumConst)
{
memcpy(rowBuf,bmDataStart+rowCount-rowNumConst,rowNumConst);
memcpy(bmDataStart+rowCount-rowNumConst,bmDataEnd-rowCount,rowNumConst);
memcpy(bmDataEnd-rowCount,rowBuf,rowNumConst);
}

       /* CWnd *hwnd1 = GetDlgItem(IDC_STATIC1);
HDC hdc1 = hwnd1->GetDC()->m_hDC;
RECT rect;
hwnd1->GetClientRect(&rect);

int nRet = StretchDIBits(hdc1,
0,0,
rect.right-rect.left,rect.bottom-rect.top,
0,0,
bf->width,bf->height,(LPBYTE)bmDataStart
,
(LPBITMAPINFO)&bitmapInfoHeader,DIB_RGB_COLORS,SRCCOPY);  */

FILE* fp=fopen("G:\my.bmp","wb");

fwrite(MBuf,bitmapFileHeader.bfSize,1,fp);

m_socket.Close();
free(MBuf);
MBuf = NULL;
delete bf; 
bf=NULL;
fclose(fp);
        fp = NULL;
}
}