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

ICQ/即时通讯

开发平台:

Visual C++

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