MultiSendDlg.cpp
上传用户:guangzhiyw
上传日期:2007-01-09
资源大小:495k
文件大小:5k
源码类别:

ICQ/即时通讯

开发平台:

Visual C++

  1. // MultiSendDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "client.h"
  5. #include "MultiSendDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CMultiSendDlg dialog
  13. CMultiSendDlg::CMultiSendDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CMultiSendDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CMultiSendDlg)
  17. m_radio = 0;
  18. //}}AFX_DATA_INIT
  19. hIcon=AfxGetApp()->LoadIcon(IDR_MESSAGE1);
  20. }
  21. void CMultiSendDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CMultiSendDlg)
  25. DDX_Control(pDX, IDC_EDITMSG, m_EditMsg);
  26. DDX_Control(pDX, IDC_EDITNAME, m_EditName);
  27. DDX_Control(pDX, IDC_EDITID, m_EditId);
  28. DDX_Radio(pDX, IDC_RADIO1, m_radio);
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(CMultiSendDlg, CDialog)
  32. //{{AFX_MSG_MAP(CMultiSendDlg)
  33. ON_BN_CLICKED(IDC_RADIO1, OnRadio1)
  34. ON_BN_CLICKED(IDC_RADIO2, OnRadio2)
  35. ON_WM_CLOSE()
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CMultiSendDlg message handlers
  40. BOOL CMultiSendDlg::OnInitDialog() 
  41. {
  42. CDialog::OnInitDialog();
  43. SetIcon(hIcon,TRUE);
  44. SetIcon(hIcon,FALSE);
  45. CMenu* pMenu=GetSystemMenu(FALSE);
  46. pMenu->EnableMenuItem(SC_RESTORE,MF_GRAYED|MF_DISABLED);
  47. pMenu->EnableMenuItem(SC_SIZE,MF_GRAYED|MF_DISABLED);
  48. pMenu->EnableMenuItem(SC_MAXIMIZE,MF_GRAYED|MF_DISABLED);
  49. m_EditMsg.LimitText(LimitMaxMsgLength);
  50. m_EditId.EnableWindow(FALSE);
  51. m_EditName.SetFocus();
  52. return FALSE; 
  53. }
  54. void CMultiSendDlg::OnOK() 
  55. {
  56. if(GetApp()->m_bOnlineState==0)
  57. {
  58. CString str;
  59. str.LoadString(IDS_NOT_LOGIN_SERVER);
  60. MessageBox(str);
  61. return;
  62. }
  63. if(m_EditMsg.GetWindowTextLength()<1)
  64. {
  65. CString str;
  66. str.LoadString(IDS_CANNOT_SEND_NULL);
  67. MessageBox(str);
  68. return;
  69. }
  70. UpdateData();
  71. CArray<DWORD,DWORD> arID;
  72. if(m_radio==0)
  73. {
  74. CArray<CString,CString> arStrName;
  75. char rtemp[100],sztemp[20];
  76. if(m_EditName.GetWindowTextLength()<1)
  77. {
  78. CString str;
  79. str.LoadString(IDS_FILL_ID_ERROR);
  80. MessageBox(str);
  81. m_EditName.SetFocus();
  82. return;
  83. }
  84. if(GetApp()->m_aUserInfo.GetSize()==1)
  85. return;
  86. m_EditName.GetWindowText(rtemp,99);
  87. for(int i=0,j=0;rtemp[i];i++)
  88. {
  89. if(rtemp[i]==',')
  90. {
  91. sztemp[j]='';
  92. arStrName.Add(sztemp);
  93. j=0;
  94. }
  95. else
  96. sztemp[j++]=rtemp[i];
  97. }
  98. sztemp[j]='';
  99. arStrName.Add(sztemp);
  100. for(int k=0;k<arStrName.GetSize();k++)
  101. {
  102. for(i=1;i<GetApp()->m_aUserInfo.GetSize();i++)
  103. {
  104. if(GetApp()->m_aUserInfo.GetAt(i)->Name==arStrName.GetAt(k))
  105. {
  106. arID.Add(GetApp()->m_aUserInfo.GetAt(i)->Id);
  107. break;
  108. }
  109. }
  110. }
  111. }
  112. else if(m_radio==1)
  113. {
  114. // user id
  115. char rtemp[100],sztemp[20];
  116. if(m_EditId.GetWindowTextLength()<1)
  117. {
  118. CString str;
  119. str.LoadString(IDS_FILL_ID_ERROR);
  120. MessageBox(str);
  121. m_EditId.SetFocus();
  122. return;
  123. }
  124. m_EditId.GetWindowText(rtemp,99);
  125. for(int i=0,j=0;rtemp[i];i++)
  126. {
  127. if(rtemp[i]==',')
  128. {
  129. sztemp[j]='';
  130. arID.Add(atol(sztemp));
  131. j=0;
  132. }
  133. else
  134. sztemp[j++]=rtemp[i];
  135. }
  136. sztemp[j]='';
  137. arID.Add(atol(sztemp));
  138. }
  139. else
  140. {
  141. return;
  142. }
  143. if(arID.GetSize()<1)
  144. return;
  145. CMsg2 msg;
  146. msg.index=MULTI_SEND_MSG;
  147. msg.MyId=GetApp()->m_uCurrentUserID;
  148. for(int i=0;i<arID.GetSize();i++)
  149. {
  150. msg.aFriendId.Add(arID.GetAt(i));
  151. }
  152. m_EditMsg.GetWindowText(msg.Msg);
  153. msg.Time=CTime::GetCurrentTime();
  154. msg.tarIP=GetApp()->m_uServerIP;
  155. msg.nPort=GetApp()->m_uServerPort;
  156. m_bCancel=FALSE;
  157. tryagain:
  158. if(GetApp()->m_Socket.SendData(&msg,m_bCancel))
  159. {
  160. m_EditMsg.SetWindowText("");
  161. m_EditName.SetWindowText("");
  162. m_EditId.SetWindowText("");
  163. m_EditMsg.SetReadOnly(FALSE);
  164. GetDlgItem(IDOK)->EnableWindow(TRUE);
  165. CDialog::OnOK();
  166. }
  167. else if(!m_bCancel)
  168. {
  169. if(AfxMessageBox(IDS_ASK_RETRY,MB_YESNO)==IDYES)
  170. {
  171. goto tryagain;
  172. }
  173. else
  174. {
  175. m_EditMsg.SetReadOnly(FALSE);
  176. GetDlgItem(IDOK)->EnableWindow();
  177. m_EditMsg.SetFocus();
  178. }
  179. }
  180. else
  181. {
  182. m_EditMsg.SetWindowText("");
  183. m_EditName.SetWindowText("");
  184. m_EditId.SetWindowText("");
  185. m_EditMsg.SetReadOnly(FALSE);
  186. GetDlgItem(IDOK)->EnableWindow(TRUE);
  187. }
  188. }
  189. void CMultiSendDlg::OnRadio1() 
  190. {
  191. m_EditId.EnableWindow(FALSE);
  192. m_EditName.EnableWindow(TRUE);
  193. }
  194. void CMultiSendDlg::OnRadio2() 
  195. {
  196. m_EditId.EnableWindow(TRUE);
  197. m_EditName.EnableWindow(FALSE);
  198. }
  199. void CMultiSendDlg::OnCancel() 
  200. {
  201. m_EditMsg.SetWindowText("");
  202. m_EditName.SetWindowText("");
  203. m_EditId.SetWindowText("");
  204. m_bCancel=TRUE;
  205. CDialog::OnCancel();
  206. }
  207. void CMultiSendDlg::OnClose() 
  208. {
  209. OnCancel();
  210. }
  211. BOOL CMultiSendDlg::PreTranslateMessage(MSG* pMsg) 
  212. {
  213. if(pMsg->message==WM_KEYDOWN)
  214. {
  215. if(pMsg->wParam==VK_RETURN&&GetKeyState(VK_CONTROL)&0x80)
  216. {
  217. OnOK();
  218. return 1;
  219. }
  220. }
  221. return CDialog::PreTranslateMessage(pMsg);
  222. }