15,979
社区成员
发帖
与我相关
我的任务
分享
bool CMainDlg::CreatPicture(const int ip_array_subscript, const int ipone, const int iptwo, const int ipthree, const int ipfour, const char *buf)
{
//using namespace std;
std::string ip_address;
char c1[20],c2[20],c3[20],c4[20];
RECT rec;
int return1, return2;
_itoa(ipone, c1, 10);
_itoa(iptwo, c2, 10);
_itoa(ipthree, c3, 10);
_itoa(ipfour, c4, 10);
ip_address += c1;
ip_address += ".";
ip_address += c2;
ip_address += ".";
ip_address += c3;
ip_address += ".";
ip_address += c4;
rec=GetPictureCoordinate(ip_array_subscript);
//GlobalAlloc是一个Windows API函数。该函数从全局堆中分配一定数目的字节数
//若函数调用成功,则返回一个新分配的内存对象的句柄。
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, 4096);
//锁定内存中指定的内存块,并返回一个地址值,令其指向内存块的起始处
void * pData = GlobalLock(hGlobal);
//内存拷贝
memcpy(pData, buf, 4096);
GlobalUnlock(hGlobal);
IStream * pStream = NULL;
//CreateStreamOnHGlobal函数从指定内存创建流对象。
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
CImage image;
if (SUCCEEDED(image.Load(pStream)))
{
//避免读到已有对象的内存
if (pPictureControl[ip_array_subscript].m_hWnd == 0)
{
//如果创建图片框失败,则返回0
return1 = pPictureControl[ip_array_subscript].Create(_T(""), WS_CHILD | WS_VISIBLE | SS_BITMAP, rec, this, ip_array_subscript);
if (return1 == 0)
{
array[ip_array_subscript] = ipone;
array[ip_array_subscript + 1] = iptwo;
array[ip_array_subscript + 2] = ipthree;
array[ip_array_subscript + 3] = ipfour;
pStream->Release();
GlobalFree(hGlobal);
image.Detach();
return 0;
}
}
else
{
return2 = (int)(pPictureControl[ip_array_subscript].SetBitmap(image));
}
//CStatic *pic = (CStatic *)GetDlgItem(IDC_PIC);
//pic->SetBitmap(image);
}
pStream->Release();
image.Detach();
}
GlobalFree(hGlobal);
if (return1 != 0 && return2 != NULL)
{
return 1;
}
}
bool CMainDlg::DrawPicture(const int ip_array_subscript, const int ipone, const int iptwo, const int ipthree, const int ipfour, const char *buf)
{
//using namespace std;
std::string ip_address;
int return1;
char c1[20], c2[20], c3[20], c4[20];
RECT rec;
_itoa(ipone, c1, 10);
_itoa(iptwo, c2, 10);
_itoa(ipthree, c3, 10);
_itoa(ipfour, c4, 10);
ip_address += c1;
ip_address += ".";
ip_address += c2;
ip_address += ".";
ip_address += c3;
ip_address += ".";
ip_address += c4;
rec = GetPictureCoordinate(ip_array_subscript);
//GlobalAlloc是一个Windows API函数。该函数从全局堆中分配一定数目的字节数
//若函数调用成功,则返回一个新分配的内存对象的句柄。
HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE, 4096);
//锁定内存中指定的内存块,并返回一个地址值,令其指向内存块的起始处
void * pData = GlobalLock(hGlobal);
//内存拷贝
memcpy(pData, buf, 4096);
GlobalUnlock(hGlobal);
IStream * pStream = NULL;
//CreateStreamOnHGlobal函数从指定内存创建流对象。
if (CreateStreamOnHGlobal(hGlobal, TRUE, &pStream) == S_OK)
{
CImage image;
if (SUCCEEDED(image.Load(pStream)))
{
if (pPictureControl[ip_array_subscript].m_hWnd != 0)
{
return1 = (int)(pPictureControl[ip_array_subscript].SetBitmap(image));
}
}
pStream->Release();
image.Detach();
}
GlobalFree(hGlobal);
if (return1!=NULL)
{
return 1;
}
return 0;
}