我尽量说的明白点哈,发现新版的CSDN自己是中农。要节约用分。转正题即时通讯中直接弹出对话框显示文字消息。有点飞鸽的感觉。问题在于我有一个列表listbox 当我::SendMessage(MainForm->m_hWnd,WM_LISTDLBTNDOWN,(WPARAM)pItem,0);这条消息和我双击列表打开一个窗口是同一个操作。是当接收到消息时弹出一个新的对话框,其中wparam里面是一个结构体,也就是存一些帐号,窗口指针什么的。问题在于当我发送完毕这条消息,在代码下面紧跟着写了一段这样的东西。int line_strart=pwnd->m_RichRead.GetLineCount(); //获取显示消息前的行数文本为空的时候,line_strart这时为1.但是当我把文字插进去的时候。假如插入12个文字,之后第二次GetLineCount则会是12. WHY??搞的一下午头都大了!!!下次再接受到文本前获取,又为正确值!!!后来我发现,由于我是直接弹出窗口后立刻插入文字。所以好像是什么东西没初始化完,那么这是微软的一个BUG??把每一个字符都当作一行么??于是我做了个实验。我先把要发送文字的那个人的窗口打开,不让他弹出后显示。 然后发送端发文字直接显示在窗口。这样便显示为正确值。看来真的有点原因总结一下。用消息响应函数弹出窗口。下接文本插入获取行数为字符个数。第二次接收文本则正常。 提前打开要发送者对话框,直接接收,文本正常,行数正常。
救命啊!!!!!
救命啊!!!!!
CString m_sendUser=(LPTSTR)lParam;
CString m_ReadMessage;
CString m_SendedMessage; bool nameinlist=false;
for (vector<stTalkWindows>::iterator item=v_TalkWindows.begin();item!=v_TalkWindows.end();item++)
{
if ((*item).username==m_sendUser)
{
nameinlist=TRUE;
break;
}
} if (nameinlist==false)
{
for (int i=0;i<m_SkinUserList->GetCount();i++)
{
CExtItem* pItem = static_cast<CExtItem *>(m_SkinUserList->GetItemDataPtr(i));
if (pItem->m_szItemName==m_sendUser)
{
::SendMessage(MainForm->m_hWnd,WM_LISTDLBTNDOWN,(WPARAM)pItem,0);
break;
} } } for (vector<stTalkWindows>::iterator item=v_TalkWindows.begin();item!=v_TalkWindows.end();item++)
{
if ((*item).username==m_sendUser) {
CKOMI2008_TalkForm *pwnd=(CKOMI2008_TalkForm*)(*item).TalkWnd; CString Richstr,FormatStr2,FormatStr;
int line_strart;
line_strart=pwnd->m_RichRead.GetLineCount(); //获取发送前的行数
CTime timer=CTime::GetCurrentTime(); //获取当前时间
int h=timer.GetHour();
int m=timer.GetMinute();
int s=timer.GetSecond();
int n2_index=m_message.Find(_T("<@S@E@T@>")); T_User tuser =MsgCore.GetUserDetail(m_sendUser);
FormatStr.Format(_T("%s %d:%d:%d\n%s"),tuser.UserName,h,m,s,m_message.Left(n2_index)); //格式化消息
CString TimeFormat;
TimeFormat.Format(_T("%s %d:%d:%d"),tuser.UserName,h,m,s);
pwnd->m_RichRead.GetWindowText(m_SendedMessage); //获取接收区消息
if (m_SendedMessage==_T(""))
{ //直接显示输入文本
pwnd->m_RichRead.SetSel(-1, -1);
long m1,m2;
pwnd->m_RichRead.GetSel(m1,m1);
pwnd->m_RichRead.ReplaceSel(TimeFormat); pwnd->m_RichRead.GetSel(m2,m2);
pwnd->m_RichRead.SetSel(m1,m2);
}
else
{
m_ReadMessage.Format(_T("\n%s"),TimeFormat); //显示追加文本
pwnd->m_RichRead.SetSel(-1, -1);
long m1,m2;
pwnd->m_RichRead.GetSel(m1,m1);
pwnd->m_RichRead.ReplaceSel(m_ReadMessage); pwnd->m_RichRead.GetSel(m2,m2);
pwnd->m_RichRead.SetSel(m1,m2);
} int mmmmmm=pwnd->m_RichRead.GetLineCount();
CHARFORMAT2 ft_format2;
ZeroMemory(&ft_format2,sizeof(CHARFORMAT2));
ft_format2.cbSize = sizeof (CHARFORMAT2);
ft_format2.dwMask = CFM_ITALIC|CFM_BOLD|CFM_FACE|CFM_UNDERLINE|CFM_SIZE |CFM_CHARSET|CFM_COLOR;
ft_format2.bCharSet = GB2312_CHARSET;
ft_format2.yHeight=180;
_tcscpy(ft_format2.szFaceName,_T("宋体"));
ft_format2.crTextColor=RGB(0,0,255); pwnd->m_RichRead.SetSelectionCharFormat(ft_format2);
int all_index=0;
FINDTEXTEX ft;
ft.chrg.cpMin = 0;
ft.chrg.cpMax = -1;
ft.lpstrText =TimeFormat;
all_index=pwnd->m_RichRead.FindText(FR_DOWN,&ft)+TimeFormat.GetLength()+1;
pwnd->m_RichRead.GetWindowText(m_SendedMessage);
::PostMessage(pwnd->m_RichRead.m_hWnd,WM_VSCROLL,SB_BOTTOM,0);
////////////////////////////////////////////////////////////////////////////////////////////////////////// int n_index=m_message.Find(_T("<@S@E@T@>")); if (n_index!=-1)
{
CString s_setting=m_message.Right(m_message.GetLength()-n_index-9); int n3_index=s_setting.Find(_T("[/font]")); if (n3_index!=-1)
{
s_setting.Delete(0,7);
CString fontindex[7];
int font_index=0; while (s_setting.Left(1)!=_T("[")&&!s_setting.IsEmpty())
{
fontindex[font_index]+=s_setting.Left(1);
s_setting.Delete(0,1);
if (s_setting.Left(1)==_T(","))
{
font_index++;
s_setting.Delete(0,1);
} } CHARFORMAT2 ft_format;
ZeroMemory(&ft_format,sizeof(CHARFORMAT2));
ft_format.cbSize = sizeof (CHARFORMAT2);
ft_format.dwMask = CFM_ITALIC|CFM_BOLD|CFM_FACE|CFM_UNDERLINE|CFM_SIZE |CFM_CHARSET|CFM_COLOR;
CString s_fontformat;
if (fontindex[4]==_T("1"))
{
ft_format.dwEffects |=CFE_BOLD;
}
if(fontindex[4]==_T("-1"))
{
ft_format.dwEffects&=~CFE_BOLD;
}
if (fontindex[5]==_T("1"))
{
ft_format.dwEffects |=CFM_ITALIC;
}
if(fontindex[5]==_T("-1"))
{
ft_format.dwEffects&=~CFM_ITALIC;
}
if (fontindex[6]==_T("1"))
{
ft_format.dwEffects |=CFM_UNDERLINE;
}
if(fontindex[6]==_T("-1"))
{
ft_format.dwEffects&=~CFM_UNDERLINE;
} ft_format.bCharSet = GB2312_CHARSET;
int fontint1=_ttoi(fontindex[1]);
int fontint2=_ttoi(fontindex[2]);
DWORD fontint3=_ttoi(fontindex[3]);
_tcscpy(ft_format.szFaceName,fontindex[0]);
ft_format.wWeight=fontint1;
ft_format.yHeight=fontint2;
ft_format.crTextColor=fontint3; m_ReadMessage.Format(_T("\n%s"),m_message.Left(n2_index)); //显示追加文本
pwnd->m_RichRead.SetSel(-1,-1);
long m1,m2;
pwnd->m_RichRead.GetSel(m1,m1);
pwnd->m_RichRead.ReplaceSel(m_ReadMessage); pwnd->m_RichRead.GetSel(m2,m2);
pwnd->m_RichRead.SetSel(m1,m2);
pwnd->m_RichRead.SetSelectionCharFormat(ft_format); }
else
{ CHARFORMAT2 cf;
cf.cbSize = sizeof (CHARFORMAT2);
cf.dwMask = CFM_FACE | CFM_SIZE |CFM_BOLD|CFM_CHARSET|CFM_COLOR;
cf.dwEffects = ~CFE_BOLD;
cf.yHeight = 180;
cf.bCharSet = GB2312_CHARSET; _tcscpy(cf.szFaceName,_T("宋体"));
cf.crTextColor=RGB(0,0,0); m_ReadMessage.Format(_T("\n%s"),m_message.Left(n2_index)); //显示追加文本
pwnd->m_RichRead.SetSel(-1,-1);
long m1,m2;
pwnd->m_RichRead.GetSel(m1,m1);
pwnd->m_RichRead.ReplaceSel(m_ReadMessage); pwnd->m_RichRead.GetSel(m2,m2);
pwnd->m_RichRead.SetSel(m1,m2); pwnd->m_RichRead.SetSelectionCharFormat(cf);
} ////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (s_setting.Left(7)==_T("[/face]"))
{
int n2_index=0;
while (n2_index!=-1)
{
s_setting.Delete(0,7);
CString faceindex[5];
int face_index=0;
while (s_setting.Left(1)!=_T("[")&&!s_setting.IsEmpty())
{ faceindex[face_index]+=s_setting.Left(1);
s_setting.Delete(0,1);
if (s_setting.Left(1)==_T(","))
{
face_index++;
s_setting.Delete(0,1);
}
}
CString pathstr;
pathstr.Format(_T("systemface\\%s.gif"),faceindex[1]); int n_id=_ttoi(faceindex[0].GetBuffer());
pwnd->m_RichRead.SetSel(all_index+n_id-1,all_index+n_id);
pwnd->m_RichRead.ReplaceSel(_T(""));
pwnd->m_RichRead.InsertFace(pathstr); n2_index=s_setting.Find(_T("[/face]"));
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////// if (line_strart!=1)
{
line_strart++;
} int char_strart;
int line_end=pwnd->m_RichRead.GetLineCount(); while(pwnd->m_RichRead.LineIndex(line_strart)!=-1)
{
char_strart=pwnd->m_RichRead.LineIndex(line_strart);
pwnd->m_RichRead.SetSel(char_strart,char_strart);
pwnd->m_RichRead.ReplaceSel(_T(" ")); line_strart++;
}
} ///////////////////////////////////////////////////////////////////////////////////////////////////// pwnd->FlashWindowEx(FLASHW_ALL,3,0); break;
} }
return 0;
}
{
BOOL nameinlist=false; CExtItem* pItem=(CExtItem*)wParam;
CString myname;
GetWindowText(myname); if (pItem->m_szItemName==myname) //双击自己不显示对话框
{
nameinlist=TRUE;
} for (vector<stTalkWindows>::iterator item=v_TalkWindows.begin();item!=v_TalkWindows.end();item++)
{ if ((*item).username==pItem->m_szItemName)
{
nameinlist=TRUE; //如果双击列表用户已打开在桌面,那么不弹出窗口 break;
}
} if (!nameinlist) //如果不在列表中,弹出新窗口
{
CKOMI2008_TalkForm *m_TalkFrom=new CKOMI2008_TalkForm();
m_TalkFrom->Create(IDD_KOMI2008_TALKFORM,GetDesktopWindow());
m_TalkFrom->SetWindowText(pItem->m_szItemName);
T_User tuser = MsgCore.GetUserDetail(pItem->m_szItemName);
m_TalkFrom->MyName=tuser.UserName;
m_TalkFrom->ShowWindow(SW_SHOW);
m_TalkFrom->MoveWindow(0,0,500,480);
m_TalkFrom->CenterWindow();
m_TalkFrom->FlashWindowEx(FLASHW_ALL,3,0);
::PostMessage(m_TalkFrom->m_hWnd,WM_SETFOCUS,0,0);
stTalkWindows talkwindows;
talkwindows.username=pItem->m_szItemName;
talkwindows.TalkWnd=m_TalkFrom;
v_TalkWindows.push_back((stTalkWindows&)talkwindows);
}
return 0;
}
{
for (int i=0;i<m_SkinUserList->GetCount();i++)
{
CExtItem* pItem = static_cast<CExtItem *>(m_SkinUserList->GetItemDataPtr(i));
if (pItem->m_szItemName==m_sendUser)
{
::SendMessage(MainForm->m_hWnd,WM_LISTDLBTNDOWN,(WPARAM)pItem,0);
break;
} } } for (vector<stTalkWindows>::iterator item=v_TalkWindows.begin();item!=v_TalkWindows.end();item++)
{
if ((*item).username==m_sendUser) {
CKOMI2008_TalkForm *pwnd=(CKOMI2008_TalkForm*)(*item).TalkWnd; CString Richstr,FormatStr2,FormatStr;
int line_strart;
line_strart=pwnd->m_RichRead.GetLineCount(); //获取发送前的行数
CTime timer=CTime::GetCurrentTime(); //获取当前时间
int h=timer.GetHour();
int m=timer.GetMinute();
int s=timer.GetSecond();
int n2_index=m_message.Find(_T("<@S@E@T@>")); T_User tuser =MsgCore.GetUserDetail(m_sendUser);
FormatStr.Format(_T("%s %d:%d:%d\n%s"),tuser.UserName,h,m,s,m_message.Left(n2_index)); //格式化消息
CString TimeFormat;
TimeFormat.Format(_T("%s %d:%d:%d"),tuser.UserName,h,m,s);
pwnd->m_RichRead.GetWindowText(m_SendedMessage); //获取接收区消息
if (m_SendedMessage==_T(""))
{ //直接显示输入文本
pwnd->m_RichRead.SetSel(-1, -1);
long m1,m2;
pwnd->m_RichRead.GetSel(m1,m1);
pwnd->m_RichRead.ReplaceSel(TimeFormat); pwnd->m_RichRead.GetSel(m2,m2);
pwnd->m_RichRead.SetSel(m1,m2);
}
else
{
m_ReadMessage.Format(_T("\n%s"),TimeFormat); //显示追加文本
pwnd->m_RichRead.SetSel(-1, -1);
long m1,m2;
pwnd->m_RichRead.GetSel(m1,m1);
pwnd->m_RichRead.ReplaceSel(m_ReadMessage); pwnd->m_RichRead.GetSel(m2,m2);
pwnd->m_RichRead.SetSel(m1,m2);
} int mmmmmm=pwnd->m_RichRead.GetLineCount();
上来几个人。散分贴了。。