SendNotedlg.cpp
上传用户:hahaxixi
上传日期:2022-04-15
资源大小:1939k
文件大小:5k
源码类别:

手机短信编程

开发平台:

Visual C++

  1. // SendNotedlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "NoteManage.h"
  5. #include "SendNotedlg.h"
  6. #include "Bookdlg.h"
  7. #include "Notedlg.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSendNotedlg dialog
  15. CSendNotedlg::CSendNotedlg(CWnd* pParent /*=NULL*/)
  16. : CDialog(CSendNotedlg::IDD, pParent)
  17. {
  18. //{{AFX_DATA_INIT(CSendNotedlg)
  19. m_Note = _T("");
  20. //}}AFX_DATA_INIT
  21. }
  22. void CSendNotedlg::DoDataExchange(CDataExchange* pDX)
  23. {
  24. CDialog::DoDataExchange(pDX);
  25. //{{AFX_DATA_MAP(CSendNotedlg)
  26. DDX_Control(pDX, IDC_BUTSEND, m_ButSend);
  27. DDX_Control(pDX, IDC_BUTNOTE, m_ButNote);
  28. DDX_Control(pDX, IDC_BUTCLEAR, m_ButClear);
  29. DDX_Control(pDX, IDC_BUTBOOK, m_ButBook);
  30. DDX_Control(pDX, IDC_BUTDEL, m_ButDel);
  31. DDX_Control(pDX, IDC_LIST1, m_Grid);
  32. DDX_Text(pDX, IDC_EDIT1, m_Note);
  33. //}}AFX_DATA_MAP
  34. }
  35. BEGIN_MESSAGE_MAP(CSendNotedlg, CDialog)
  36. //{{AFX_MSG_MAP(CSendNotedlg)
  37. ON_BN_CLICKED(IDC_BUTBOOK, OnButbook)
  38. ON_BN_CLICKED(IDC_BUTDEL, OnButdel)
  39. ON_BN_CLICKED(IDC_BUTCLEAR, OnButclear)
  40. ON_BN_CLICKED(IDC_BUTNOTE, OnButnote)
  41. ON_BN_CLICKED(IDC_BUTSEND, OnButsend)
  42. ON_WM_DESTROY()
  43. //}}AFX_MSG_MAP
  44. END_MESSAGE_MAP()
  45. /////////////////////////////////////////////////////////////////////////////
  46. // CSendNotedlg message handlers
  47. BOOL CSendNotedlg::OnInitDialog() 
  48. {
  49. CDialog::OnInitDialog();
  50. // TODO: Add extra initialization here
  51. //设置列表视图的扩展风格
  52. m_Grid.SetExtendedStyle(LVS_EX_FLATSB
  53. |LVS_EX_FULLROWSELECT
  54. |LVS_EX_HEADERDRAGDROP
  55. |LVS_EX_ONECLICKACTIVATE
  56. |LVS_EX_GRIDLINES);
  57. m_Grid.InsertColumn(0,"编号",LVCFMT_LEFT,80,0); //设置表头
  58. m_Grid.InsertColumn(1,"姓名",LVCFMT_LEFT,80,1); 
  59. m_Grid.InsertColumn(2,"电话",LVCFMT_LEFT,150,2);
  60. m_ButBook.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  61. MAKEINTRESOURCE(IDB_BUTBOOK1))); //设置位图
  62. m_ButBook.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTBOOK2)),
  63. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTBOOK1)));
  64. m_ButDel.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  65. MAKEINTRESOURCE(IDB_BUTDEL1))); //设置位图
  66. m_ButDel.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTDEL2)),
  67. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTDEL1)));
  68. m_ButClear.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  69. MAKEINTRESOURCE(IDB_BUTCLEAR1))); //设置位图
  70. m_ButClear.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTCLEAR2)),
  71. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTCLEAR1)));
  72. m_ButNote.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  73. MAKEINTRESOURCE(IDB_BUTNOTE1))); //设置位图
  74. m_ButNote.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTNOTE2)),
  75. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTNOTE1)));
  76. m_ButSend.SetBitmap(LoadBitmap(AfxGetInstanceHandle(),
  77. MAKEINTRESOURCE(IDB_BUTSEND1))); //设置位图
  78. m_ButSend.SetHBitmap(LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTSEND2)),
  79. LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_BUTSEND1)));
  80. return TRUE;  // return TRUE unless you set the focus to a control
  81.               // EXCEPTION: OCX Property Pages should return FALSE
  82. }
  83. void CSendNotedlg::OnButbook() 
  84. {
  85. // TODO: Add your control notification handler code here
  86. CBookdlg dlg;
  87. dlg.DoModal();
  88. int num = dlg.m_Num;
  89. for(int i=0;i<num;i++)
  90. {
  91. m_Grid.InsertItem(i,"");
  92. m_Grid.SetItemText(i,0,dlg.m_ID[i]);
  93. m_Grid.SetItemText(i,1,dlg.m_Name[i]);
  94. m_Grid.SetItemText(i,2,dlg.m_Phone[i]);
  95. }
  96. }
  97. void CSendNotedlg::OnButdel() 
  98. {
  99. // TODO: Add your control notification handler code here
  100. int pos = m_Grid.GetSelectionMark();
  101. m_Grid.DeleteItem(pos);
  102. }
  103. void CSendNotedlg::OnButclear() 
  104. {
  105. // TODO: Add your control notification handler code here
  106. m_Grid.DeleteAllItems();
  107. }
  108. void CSendNotedlg::OnButnote() 
  109. {
  110. // TODO: Add your control notification handler code here
  111. UpdateData(TRUE);
  112. CNotedlg dlg;
  113. dlg.DoModal();
  114. m_Note += dlg.m_Note;
  115. UpdateData(FALSE);
  116. }
  117. void CSendNotedlg::OnButsend() 
  118. {
  119. // TODO: Add your control notification handler code here
  120. UpdateData(TRUE);
  121. CString port,baud,merid,accredit;
  122. char buf[128];
  123. GetPrivateProfileString("短信猫设置","端口号","default",buf,128,"./stage.ini");
  124. port.Format("%s",buf);
  125. GetPrivateProfileString("短信猫设置","波特率","default",buf,128,"./stage.ini");
  126. baud.Format("%s",buf);
  127. GetPrivateProfileString("短信猫设置","机器号码","default",buf,128,"./stage.ini");
  128. merid.Format("%s",buf);
  129. GetPrivateProfileString("短信猫设置","授权号码","default",buf,128,"./stage.ini");
  130. accredit.Format("%s",buf);
  131. if(GSMModemInitNew((char*)(LPCTSTR)port,(char*)(LPCTSTR)baud,
  132. NULL,NULL,FALSE,(char*)(LPCTSTR)accredit)==FALSE)
  133. {
  134. MessageBox((char*)GSMModemGetErrorMsg());
  135. return;
  136. }
  137. CString str="其中:";
  138. int num = 0;
  139. for(int i=0;i<m_Grid.GetItemCount();i++)
  140. {
  141. CString phone = m_Grid.GetItemText(i,2);
  142. if(GSMModemSMSsend(NULL,8,(char*)(LPCTSTR)m_Note,m_Note.GetLength(),
  143. (char*)(LPCTSTR)phone,FALSE))
  144. {
  145. num++;
  146. }
  147. else
  148. {
  149. str += m_Grid.GetItemText(i,1);
  150. str += ",";
  151. }
  152. }
  153. if(num == i)
  154. {
  155. MessageBox("发送成功");
  156. }
  157. else if(num>0 && num<i)
  158. {
  159. str += "发送失败";
  160. MessageBox(str);
  161. }
  162. else
  163. {
  164. MessageBox("发送失败");
  165. }
  166. }
  167. void CSendNotedlg::OnOK()
  168. {
  169. }
  170. void CSendNotedlg::OnDestroy() 
  171. {
  172. GSMModemRelease();
  173. CDialog::OnDestroy();
  174. }