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

ICQ/即时通讯

开发平台:

Visual C++

  1. // SendToAllDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "client.h"
  5. #include "SendToAllDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CSendToAllDlg dialog
  13. CSendToAllDlg::CSendToAllDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CSendToAllDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CSendToAllDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. hIcon=AfxGetApp()->LoadIcon(IDR_MESSAGE1);
  20. }
  21. void CSendToAllDlg::DoDataExchange(CDataExchange* pDX)
  22. {
  23. CDialog::DoDataExchange(pDX);
  24. //{{AFX_DATA_MAP(CSendToAllDlg)
  25. DDX_Control(pDX, IDC_EDIT1, m_Edit);
  26. //}}AFX_DATA_MAP
  27. }
  28. BEGIN_MESSAGE_MAP(CSendToAllDlg, CDialog)
  29. //{{AFX_MSG_MAP(CSendToAllDlg)
  30. ON_WM_CLOSE()
  31. //}}AFX_MSG_MAP
  32. END_MESSAGE_MAP()
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CSendToAllDlg message handlers
  35. void CSendToAllDlg::OnOK() 
  36. {
  37. if(GetApp()->m_bOnlineState==0)
  38. {
  39. CString str;
  40. str.LoadString(IDS_NOT_LOGIN_SERVER);
  41. MessageBox(str);
  42. return;
  43. }
  44. if(GetApp()->m_aUserInfo.GetSize()==1)
  45. return;
  46. CMsg2 msg;
  47. msg.index=MULTI_SEND_MSG;
  48. msg.MyId=GetApp()->m_uCurrentUserID;
  49. for(int i=1;i<GetApp()->m_aUserInfo.GetSize();i++)
  50. {
  51. msg.aFriendId.Add(GetApp()->m_aUserInfo.GetAt(i)->Id);
  52. }
  53. m_Edit.GetWindowText(msg.Msg);
  54. msg.Time=CTime::GetCurrentTime();
  55. msg.tarIP=GetApp()->m_uServerIP;
  56. msg.nPort=GetApp()->m_uServerPort;
  57. m_bCancel=FALSE;
  58. tryagain:
  59. if(GetApp()->m_Socket.SendData(&msg,m_bCancel))
  60. {
  61. m_Edit.SetWindowText("");
  62. m_Edit.SetReadOnly(FALSE);
  63. GetDlgItem(IDOK)->EnableWindow(TRUE);
  64. CDialog::OnOK();
  65. }
  66. else if(!m_bCancel)
  67. {
  68. if(AfxMessageBox(IDS_ASK_RETRY,MB_YESNO)==IDYES)
  69. {
  70. goto tryagain;
  71. }
  72. else
  73. {
  74. m_Edit.SetReadOnly(FALSE);
  75. GetDlgItem(IDOK)->EnableWindow();
  76. m_Edit.SetFocus();
  77. }
  78. }
  79. else
  80. {
  81. m_Edit.SetWindowText("");
  82. m_Edit.SetReadOnly(FALSE);
  83. GetDlgItem(IDOK)->EnableWindow(TRUE);
  84. }
  85. }
  86. BOOL CSendToAllDlg::OnInitDialog() 
  87. {
  88. CDialog::OnInitDialog();
  89. SetIcon(hIcon,TRUE);
  90. SetIcon(hIcon,FALSE);
  91. CMenu* pMenu=GetSystemMenu(FALSE);
  92. pMenu->EnableMenuItem(SC_RESTORE,MF_GRAYED|MF_DISABLED);
  93. pMenu->EnableMenuItem(SC_SIZE,MF_GRAYED|MF_DISABLED);
  94. pMenu->EnableMenuItem(SC_MAXIMIZE,MF_GRAYED|MF_DISABLED);
  95. m_Edit.LimitText(LimitMaxMsgLength);
  96. m_Edit.SetFocus();
  97.  
  98. return FALSE;
  99. }
  100. void CSendToAllDlg::OnClose() 
  101. {
  102. OnCancel();
  103. }
  104. void CSendToAllDlg::OnCancel() 
  105. {
  106. m_Edit.SetWindowText("");
  107. m_bCancel=TRUE;
  108. CDialog::OnCancel();
  109. }
  110. BOOL CSendToAllDlg::PreTranslateMessage(MSG* pMsg) 
  111. {
  112. if(pMsg->message==WM_KEYDOWN)
  113. {
  114. if(pMsg->wParam==VK_RETURN&&(GetKeyState(VK_CONTROL)&0x80||GetKeyState(VK_RCONTROL)&0x80))
  115. {
  116. OnOK();
  117. return 1;
  118. }
  119. }
  120. return CDialog::PreTranslateMessage(pMsg);
  121. }