这是一段显示表情代码,m_SendEdit是发送框,m_ShowEdit为显示框。单机可以实现。
void CAbcDlg::OnSend()
{
CString csText;
m_SendEdit.GetWindowText(csText);
//如果窗口中包含只包含图像,则文本为" ",在用户接收时不显示文本,只显示对方的编号\时间等信息
if (!csText.IsEmpty())
{
CString csUsrInfo;
CString csTime;
CTime ctNow = CTime::GetCurrentTime();
csTime = ctNow.Format("%H:%M:%S");
csUsrInfo += csTime; m_ShowEdit.SetSel(-1,-1);
CHARFORMAT cf;
memset(&cf, 0, sizeof(CHARFORMAT));
BOOL m_bSelect = (m_ShowEdit.GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (m_bSelect)
{
m_ShowEdit.GetSelectionCharFormat(cf);
}
else
{
m_ShowEdit.GetDefaultCharFormat(cf);
}
//判断是否选择了内容 cf.dwMask = CFM_COLOR;
cf.dwEffects = CFE_BOLD;
cf.crTextColor = RGB(0,0,255);
if (m_bSelect)
m_ShowEdit.SetSelectionCharFormat(cf);
else
m_ShowEdit.SetWordCharFormat(cf); m_ShowEdit.ReplaceSel(csUsrInfo); m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.GetDefaultCharFormat(cf);
m_ShowEdit.SetSelectionCharFormat(cf); m_ShowEdit.ReplaceSel("\n");
m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.ReplaceSel(csText);
//如果包含图像信息,将图像添加到显示窗口中
IRichEditOle * pRichOle = m_SendEdit.GetIRichEditOle();
LONG lNum = 0;
if (pRichOle != NULL)
{
lNum = pRichOle->GetObjectCount();
IRichEditOle *pShowEditOle = m_ShowEdit.GetIRichEditOle();
IOleClientSite *lpOleClientSite = NULL;
if (lNum != 0)
{
m_ShowEdit.SetSel(-1,-1);
}
for(LONG i=0; i<lNum; i++)
{ if (pShowEditOle!= NULL)
{
pShowEditOle->GetClientSite(&lpOleClientSite);
} REOBJECT reObject;
ZeroMemory(&reObject,sizeof(REOBJECT)); //初始化一对象
reObject.cbStruct = sizeof(REOBJECT); pRichOle->GetObject(i,&reObject,REO_GETOBJ_ALL_INTERFACES);
if (lpOleClientSite != NULL)
{
reObject.polesite = lpOleClientSite ;
reObject.cp = REO_CP_SELECTION; //REO_IOB_SELECTION;
reObject.dwFlags = reObject.dwFlags|REO_BLANK;
GIFLib::ICGifPtr lpAnimator = NULL;
reObject.poleobj->QueryInterface(GIFLib::IID_ICGif,(void**)&lpAnimator);
if (lpAnimator != NULL)
{
//获取对象关联的文件名称
char chFullName[MAX_PATH] = {0};
strcpy(chFullName,(char*)lpAnimator->GetFileName());
m_csFullName = chFullName;
CString csTmp = ExtractFilePath(m_csFullName);
}
reObject.poleobj->SetClientSite(NULL);
reObject.poleobj->SetClientSite(lpOleClientSite);
pShowEditOle->InsertObject(&reObject); m_ShowEdit.RedrawWindow(); //刷新窗体
OleSetContainedObject(reObject.poleobj,TRUE);
lpOleClientSite->SaveObject();
reObject.pstg->Release();
reObject.poleobj->Release();
}
}
pRichOle->Release();
if (pShowEditOle != NULL)
pShowEditOle->Release();
if (lpOleClientSite != NULL)
lpOleClientSite->Release();
pRichOle = NULL;
if (lNum != 0)
{
m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.ReplaceSel("\n");
}
}
if (lNum == 0) //没有图像插入
{
m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.ReplaceSel("\n");
}
m_SendEdit.SetWindowText("");
m_SendEdit.Clear();
}
}
CString CAbcDlg::ExtractFilePath(CString csFullPath)
{
int pos = csFullPath.ReverseFind('\\');
int nLen = strlen(m_csFullName.GetBuffer(0));
CString csTmp = csFullPath.Right(nLen-pos-1);
return csTmp;
}
现在我想在网络上实现。把这段代码一分为二,m_SendEdit内容发送网络中去,然后让m_ShowEdit接收并显示网络传来的数据。不知怎么实现?谢谢!!
void CAbcDlg::OnSend()
{
CString csText;
m_SendEdit.GetWindowText(csText);
//如果窗口中包含只包含图像,则文本为" ",在用户接收时不显示文本,只显示对方的编号\时间等信息
if (!csText.IsEmpty())
{
CString csUsrInfo;
CString csTime;
CTime ctNow = CTime::GetCurrentTime();
csTime = ctNow.Format("%H:%M:%S");
csUsrInfo += csTime; m_ShowEdit.SetSel(-1,-1);
CHARFORMAT cf;
memset(&cf, 0, sizeof(CHARFORMAT));
BOOL m_bSelect = (m_ShowEdit.GetSelectionType() != SEL_EMPTY) ? TRUE : FALSE;
if (m_bSelect)
{
m_ShowEdit.GetSelectionCharFormat(cf);
}
else
{
m_ShowEdit.GetDefaultCharFormat(cf);
}
//判断是否选择了内容 cf.dwMask = CFM_COLOR;
cf.dwEffects = CFE_BOLD;
cf.crTextColor = RGB(0,0,255);
if (m_bSelect)
m_ShowEdit.SetSelectionCharFormat(cf);
else
m_ShowEdit.SetWordCharFormat(cf); m_ShowEdit.ReplaceSel(csUsrInfo); m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.GetDefaultCharFormat(cf);
m_ShowEdit.SetSelectionCharFormat(cf); m_ShowEdit.ReplaceSel("\n");
m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.ReplaceSel(csText);
//如果包含图像信息,将图像添加到显示窗口中
IRichEditOle * pRichOle = m_SendEdit.GetIRichEditOle();
LONG lNum = 0;
if (pRichOle != NULL)
{
lNum = pRichOle->GetObjectCount();
IRichEditOle *pShowEditOle = m_ShowEdit.GetIRichEditOle();
IOleClientSite *lpOleClientSite = NULL;
if (lNum != 0)
{
m_ShowEdit.SetSel(-1,-1);
}
for(LONG i=0; i<lNum; i++)
{ if (pShowEditOle!= NULL)
{
pShowEditOle->GetClientSite(&lpOleClientSite);
} REOBJECT reObject;
ZeroMemory(&reObject,sizeof(REOBJECT)); //初始化一对象
reObject.cbStruct = sizeof(REOBJECT); pRichOle->GetObject(i,&reObject,REO_GETOBJ_ALL_INTERFACES);
if (lpOleClientSite != NULL)
{
reObject.polesite = lpOleClientSite ;
reObject.cp = REO_CP_SELECTION; //REO_IOB_SELECTION;
reObject.dwFlags = reObject.dwFlags|REO_BLANK;
GIFLib::ICGifPtr lpAnimator = NULL;
reObject.poleobj->QueryInterface(GIFLib::IID_ICGif,(void**)&lpAnimator);
if (lpAnimator != NULL)
{
//获取对象关联的文件名称
char chFullName[MAX_PATH] = {0};
strcpy(chFullName,(char*)lpAnimator->GetFileName());
m_csFullName = chFullName;
CString csTmp = ExtractFilePath(m_csFullName);
}
reObject.poleobj->SetClientSite(NULL);
reObject.poleobj->SetClientSite(lpOleClientSite);
pShowEditOle->InsertObject(&reObject); m_ShowEdit.RedrawWindow(); //刷新窗体
OleSetContainedObject(reObject.poleobj,TRUE);
lpOleClientSite->SaveObject();
reObject.pstg->Release();
reObject.poleobj->Release();
}
}
pRichOle->Release();
if (pShowEditOle != NULL)
pShowEditOle->Release();
if (lpOleClientSite != NULL)
lpOleClientSite->Release();
pRichOle = NULL;
if (lNum != 0)
{
m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.ReplaceSel("\n");
}
}
if (lNum == 0) //没有图像插入
{
m_ShowEdit.SetSel(-1,-1);
m_ShowEdit.ReplaceSel("\n");
}
m_SendEdit.SetWindowText("");
m_SendEdit.Clear();
}
}
CString CAbcDlg::ExtractFilePath(CString csFullPath)
{
int pos = csFullPath.ReverseFind('\\');
int nLen = strlen(m_csFullName.GetBuffer(0));
CString csTmp = csFullPath.Right(nLen-pos-1);
return csTmp;
}
现在我想在网络上实现。把这段代码一分为二,m_SendEdit内容发送网络中去,然后让m_ShowEdit接收并显示网络传来的数据。不知怎么实现?谢谢!!
1、 首先回答1楼的问题,GIF 显示不闪。
2、2楼方法还不错,能不能提供这方面的代码?谢谢!如果可以的话,请发送到[email protected]