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

手机短信编程

开发平台:

Visual C++

  1. // NoteManageDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "NoteManage.h"
  5. #include "NoteManageDlg.h"
  6. #include "PhoneBookdlg.h"
  7. #include "OftenNotedlg.h"
  8. #include "SendNotedlg.h"
  9. #include "RecvNotedlg.h"
  10. #include "Userdlg.h"
  11. #include "Login.h"
  12. #include "NoteSet.h"
  13. #include "NewNotedlg.h"
  14. #ifdef _DEBUG
  15. #define new DEBUG_NEW
  16. #undef THIS_FILE
  17. static char THIS_FILE[] = __FILE__;
  18. #endif
  19. /////////////////////////////////////////////////////////////////////////////
  20. // CAboutDlg dialog used for App About
  21. class CAboutDlg : public CDialog
  22. {
  23. public:
  24. CAboutDlg();
  25. // Dialog Data
  26. //{{AFX_DATA(CAboutDlg)
  27. enum { IDD = IDD_ABOUTBOX };
  28. //}}AFX_DATA
  29. // ClassWizard generated virtual function overrides
  30. //{{AFX_VIRTUAL(CAboutDlg)
  31. protected:
  32. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  33. //}}AFX_VIRTUAL
  34. // Implementation
  35. protected:
  36. //{{AFX_MSG(CAboutDlg)
  37. //}}AFX_MSG
  38. DECLARE_MESSAGE_MAP()
  39. };
  40. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  41. {
  42. //{{AFX_DATA_INIT(CAboutDlg)
  43. //}}AFX_DATA_INIT
  44. }
  45. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  46. {
  47. CDialog::DoDataExchange(pDX);
  48. //{{AFX_DATA_MAP(CAboutDlg)
  49. //}}AFX_DATA_MAP
  50. }
  51. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  52. //{{AFX_MSG_MAP(CAboutDlg)
  53. // No message handlers
  54. //}}AFX_MSG_MAP
  55. END_MESSAGE_MAP()
  56. /////////////////////////////////////////////////////////////////////////////
  57. // CNoteManageDlg dialog
  58. CNoteManageDlg::CNoteManageDlg(CWnd* pParent /*=NULL*/)
  59. : CDialog(CNoteManageDlg::IDD, pParent)
  60. {
  61. //{{AFX_DATA_INIT(CNoteManageDlg)
  62. // NOTE: the ClassWizard will add member initialization here
  63. //}}AFX_DATA_INIT
  64. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  65. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  66. }
  67. void CNoteManageDlg::DoDataExchange(CDataExchange* pDX)
  68. {
  69. CDialog::DoDataExchange(pDX);
  70. //{{AFX_DATA_MAP(CNoteManageDlg)
  71. // NOTE: the ClassWizard will add DDX and DDV calls here
  72. //}}AFX_DATA_MAP
  73. }
  74. BEGIN_MESSAGE_MAP(CNoteManageDlg, CDialog)
  75. //{{AFX_MSG_MAP(CNoteManageDlg)
  76. ON_WM_SYSCOMMAND()
  77. ON_WM_PAINT()
  78. ON_WM_QUERYDRAGICON()
  79. ON_COMMAND(1001,OnPhoneBook)
  80. ON_COMMAND(1002,OnOftenNote)
  81. ON_COMMAND(1004,OnSendNote)
  82. ON_COMMAND(1005,OnRecvNote)
  83. ON_COMMAND(1007,OnNoteSet)
  84. ON_COMMAND(1008,OnUser)
  85. ON_WM_TIMER()
  86. //}}AFX_MSG_MAP
  87. END_MESSAGE_MAP()
  88. /////////////////////////////////////////////////////////////////////////////
  89. // CNoteManageDlg message handlers
  90. BOOL CNoteManageDlg::OnInitDialog()
  91. {
  92. CDialog::OnInitDialog();
  93. // Add "About..." menu item to system menu.
  94. // IDM_ABOUTBOX must be in the system command range.
  95. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  96. ASSERT(IDM_ABOUTBOX < 0xF000);
  97. CMenu* pSysMenu = GetSystemMenu(FALSE);
  98. if (pSysMenu != NULL)
  99. {
  100. CString strAboutMenu;
  101. strAboutMenu.LoadString(IDS_ABOUTBOX);
  102. if (!strAboutMenu.IsEmpty())
  103. {
  104. pSysMenu->AppendMenu(MF_SEPARATOR);
  105. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  106. }
  107. }
  108. // Set the icon for this dialog.  The framework does this automatically
  109. //  when the application's main window is not a dialog
  110. SetIcon(m_hIcon, TRUE); // Set big icon
  111. SetIcon(m_hIcon, FALSE); // Set small icon
  112. // TODO: Add extra initialization here
  113. CLogin dlg;
  114. if(dlg.DoModal() != IDOK)
  115. {
  116. CDialog::OnCancel();
  117. }
  118. //创建图像列表
  119. m_ImageList.Create(32,32,ILC_COLOR24|ILC_MASK,1,1);
  120. //向图像列表中添加图标
  121. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICONBOOK));
  122. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICONNOTE));
  123. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICONSEND));
  124. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICONRECV));
  125. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICONSET));
  126. m_ImageList.Add(AfxGetApp()->LoadIcon(IDI_ICONUSER));
  127. UINT array[8];
  128. for(int i=0;i<8;i++)
  129. {
  130. if(i==2 || i==5)
  131. array[i] = ID_SEPARATOR; //第3、6个按钮为分隔条
  132. else
  133. array[i] = i+1001; //为工具栏按钮设置索引
  134. }
  135. m_ToolBar.Create(this);
  136. m_ToolBar.SetButtons(array,8);
  137. //关联图像列表
  138. m_ToolBar.GetToolBarCtrl().SetImageList(&m_ImageList);
  139. m_ToolBar.SetSizes(CSize(50,60),CSize(32,32)); //设置按钮和图标的大小
  140. m_ToolBar.SetButtonText(0,"电话簿管理");
  141. m_ToolBar.SetButtonText(1,"常用语管理");
  142. m_ToolBar.SetButtonText(3,"短信息发送");
  143. m_ToolBar.SetButtonText(4,"短信息接收");
  144. m_ToolBar.SetButtonText(6,"短信猫设置");
  145. m_ToolBar.SetButtonText(7,"操作员管理");
  146. RepositionBars(AFX_IDW_CONTROLBAR_FIRST,AFX_IDW_CONTROLBAR_LAST,0);
  147. CString port,baud,merid,accredit,isnum;
  148. char buf[129];
  149. GetPrivateProfileString("短信猫设置","端口号","default",buf,128,"./stage.ini");
  150. port.Format("%s",buf);
  151. GetPrivateProfileString("短信猫设置","波特率","default",buf,128,"./stage.ini");
  152. baud.Format("%s",buf);
  153. GetPrivateProfileString("短信猫设置","机器号码","default",buf,128,"./stage.ini");
  154. merid.Format("%s",buf);
  155. GetPrivateProfileString("短信猫设置","授权号码","default",buf,128,"./stage.ini");
  156. accredit.Format("%s",buf);
  157. GetPrivateProfileString("短信猫设置","是否设置","default",buf,128,"./stage.ini");
  158. isnum.Format("%s",buf);
  159. if(isnum == "1")
  160. {
  161. if(GSMModemInitNew((char*)(LPCTSTR)port,(char*)(LPCTSTR)baud,
  162. NULL,NULL,FALSE,(char*)(LPCTSTR)accredit)==FALSE)
  163. {
  164. MessageBox((char*)GSMModemGetErrorMsg());
  165. return TRUE; 
  166. }
  167. }
  168. SetTimer(1,1000,NULL);
  169. return TRUE;  // return TRUE  unless you set the focus to a control
  170. }
  171. void CNoteManageDlg::OnSysCommand(UINT nID, LPARAM lParam)
  172. {
  173. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  174. {
  175. CAboutDlg dlgAbout;
  176. dlgAbout.DoModal();
  177. }
  178. else
  179. {
  180. CDialog::OnSysCommand(nID, lParam);
  181. }
  182. }
  183. // If you add a minimize button to your dialog, you will need the code below
  184. //  to draw the icon.  For MFC applications using the document/view model,
  185. //  this is automatically done for you by the framework.
  186. void CNoteManageDlg::OnPaint() 
  187. {
  188. if (IsIconic())
  189. {
  190. CPaintDC dc(this); // device context for painting
  191. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  192. // Center icon in client rectangle
  193. int cxIcon = GetSystemMetrics(SM_CXICON);
  194. int cyIcon = GetSystemMetrics(SM_CYICON);
  195. CRect rect;
  196. GetClientRect(&rect);
  197. int x = (rect.Width() - cxIcon + 1) / 2;
  198. int y = (rect.Height() - cyIcon + 1) / 2;
  199. // Draw the icon
  200. dc.DrawIcon(x, y, m_hIcon);
  201. }
  202. else
  203. {
  204. CDialog::OnPaint();
  205. }
  206. }
  207. // The system calls this to obtain the cursor to display while the user drags
  208. //  the minimized window.
  209. HCURSOR CNoteManageDlg::OnQueryDragIcon()
  210. {
  211. return (HCURSOR) m_hIcon;
  212. }
  213. void CNoteManageDlg::OnPhoneBook()
  214. {
  215. CPhoneBookdlg dlg;
  216. dlg.DoModal();
  217. }
  218. void CNoteManageDlg::OnOftenNote()
  219. {
  220. COftenNotedlg dlg;
  221. dlg.DoModal();
  222. }
  223. void CNoteManageDlg::OnSendNote()
  224. {
  225. CSendNotedlg dlg;
  226. dlg.DoModal();
  227. }
  228. void CNoteManageDlg::OnRecvNote()
  229. {
  230. CRecvNotedlg dlg;
  231. dlg.DoModal();
  232. }
  233. void CNoteManageDlg::OnNoteSet()
  234. {
  235. CNoteSet dlg;
  236. dlg.DoModal();
  237. }
  238. void CNoteManageDlg::OnUser()
  239. {
  240. CUserdlg dlg;
  241. dlg.DoModal();
  242. }
  243. void CNoteManageDlg::OnOK()
  244. {
  245. }
  246. void CNoteManageDlg::OnTimer(UINT nIDEvent) 
  247. {
  248. // TODO: Add your message handler code here and/or call default
  249. char* reData;
  250. char number[30],msgContent[512]; //电话号码,短信内容
  251. //获取接收的所有数据
  252. reData = (char*)GSMModemSMSReadAll(0);
  253. if (reData != NULL)
  254. {
  255. //获取所有短信内容的总长度
  256. int allDataLen = strlen(reData);
  257. int num = 0,content = 0;
  258. int once = 0 ; //接收完一个电话号码和一条短信
  259. for(int i=0;i<allDataLen;i++)
  260. {
  261. if(reData[i] == '|')
  262. {
  263. once+=1;
  264. }
  265. if(once == 0)
  266. {
  267. number[num] = reData[i];
  268. num++;
  269. }
  270. else if(once==1 && reData[i]!='|')
  271. {
  272. msgContent[content] = reData[i];
  273. content++;
  274. }
  275. if(once==3 && reData[i-1]=='|')
  276. {
  277. CNewNotedlg dlg;
  278. number[num]         = '';
  279. msgContent[content] = '';
  280. MessageBox(msgContent);
  281. CString strPhone,strNote;
  282. strPhone.Format("%s",number);
  283. strNote.Format("%s",msgContent);
  284. dlg.m_Phone = strPhone.Right(11);
  285. dlg.m_Note  = strNote;
  286. dlg.DoModal();
  287. break;
  288. }
  289. }
  290. }
  291. CDialog::OnTimer(nIDEvent);
  292. }