[VC(Visual C++) ]- GPSDataSave程式
[VC(Visual C++) ]- GPSDataSave程式
本篇分享GPSDataSave程式串程式範例,有興趣的(C/P)同好,歡迎來http://filemarkets.com/file/jashliao/a9006d21/索取,因為我不會上傳檔案分享哈哈 ^ ^。
主要程式碼 |
001 // GPSDataSaveDlg.cpp : implementation file 002 // 003
004 #include "stdafx.h" 005 #include "GPSDataSave.h" 006 #include "GPSDataSaveDlg.h" 007 #include <stdio.h> 008 #ifdef _DEBUG 009 #definenew DEBUG_NEW 010 #undef THIS_FILE 011 staticchar THIS_FILE[] = __FILE__; 012 #endif 013 FILE *p;
014 CString strdata[30];
015 ///////////////////////////////////////////////////////////////////////////// 016 // CAboutDlg dialog used for App About 017
018 class CAboutDlg : public CDialog 019 {
020 public: 021 CAboutDlg();
022
023 // Dialog Data 024 //{{AFX_DATA(CAboutDlg) 025 enum { IDD = IDD_ABOUTBOX }; 026 //}}AFX_DATA 027
028 // ClassWizard generated virtual function overrides 029 //{{AFX_VIRTUAL(CAboutDlg) 030 protected: 031 virtualvoid DoDataExchange(CDataExchange* pDX); // DDX/DDV support 032 //}}AFX_VIRTUAL 033
034 // Implementation 035 protected: 036 //{{AFX_MSG(CAboutDlg) 037 //}}AFX_MSG 038 DECLARE_MESSAGE_MAP()
039 };
040
041 CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
042 {
043 //{{AFX_DATA_INIT(CAboutDlg) 044 //}}AFX_DATA_INIT 045 }
046
047 void CAboutDlg::DoDataExchange(CDataExchange* pDX) 048 {
049 CDialog::DoDataExchange(pDX);
050 //{{AFX_DATA_MAP(CAboutDlg) 051 //}}AFX_DATA_MAP 052 }
053
054 BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
055 //{{AFX_MSG_MAP(CAboutDlg) 056 // No message handlers 057 //}}AFX_MSG_MAP 058 END_MESSAGE_MAP()
059
060 ///////////////////////////////////////////////////////////////////////////// 061 // CGPSDataSaveDlg dialog 062
063 CGPSDataSaveDlg::CGPSDataSaveDlg(CWnd* pParent /*=NULL*/) 064 : CDialog(CGPSDataSaveDlg::IDD, pParent)
065 {
066 //{{AFX_DATA_INIT(CGPSDataSaveDlg) 067 // NOTE: the ClassWizard will add member initialization here 068 //}}AFX_DATA_INIT 069 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 070 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 071 }
072
073 void CGPSDataSaveDlg::DoDataExchange(CDataExchange* pDX) 074 {
075 CDialog::DoDataExchange(pDX);
076 //{{AFX_DATA_MAP(CGPSDataSaveDlg) 077 // NOTE: the ClassWizard will add DDX and DDV calls here 078 //}}AFX_DATA_MAP 079 }
080
081 BEGIN_MESSAGE_MAP(CGPSDataSaveDlg, CDialog)
082 //{{AFX_MSG_MAP(CGPSDataSaveDlg) 083 ON_WM_SYSCOMMAND()
084 ON_WM_PAINT()
085 ON_WM_QUERYDRAGICON()
086 ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
087 ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
088 ON_WM_TIMER()
089 //}}AFX_MSG_MAP 090 END_MESSAGE_MAP()
091
092 ///////////////////////////////////////////////////////////////////////////// 093 // CGPSDataSaveDlg message handlers 094
095 BOOL CGPSDataSaveDlg::OnInitDialog()
096 {
097 CDialog::OnInitDialog();
098
099 // Add "About..." menu item to system menu. 100
101 // IDM_ABOUTBOX must be in the system command range. 102 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
103 ASSERT(IDM_ABOUTBOX < 0xF000);
104
105 CMenu* pSysMenu = GetSystemMenu(FALSE);
106 if (pSysMenu != NULL) 107 {
108 CString strAboutMenu;
109 strAboutMenu.LoadString(IDS_ABOUTBOX);
110 if (!strAboutMenu.IsEmpty()) 111 {
112 pSysMenu->AppendMenu(MF_SEPARATOR);
113 pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
114 }
115 }
116
117 // Set the icon for this dialog. The framework does this automatically 118 // when the application's main window is not a dialog 119 SetIcon(m_hIcon, TRUE); // Set big icon 120 SetIcon(m_hIcon, FALSE); // Set small icon 121
122 // TODO: Add extra initialization here 123
124 return TRUE; // return TRUE unless you set the focus to a control 125 }
126
127 void CGPSDataSaveDlg::OnSysCommand(UINT nID, LPARAM lParam) 128 {
129 if ((nID & 0xFFF0) == IDM_ABOUTBOX) 130 {
131 CAboutDlg dlgAbout;
132 dlgAbout.DoModal();
133 }
134 else 135 {
136 CDialog::OnSysCommand(nID, lParam);
137 }
138 }
139
140 // If you add a minimize button to your dialog, you will need the code below 141 // to draw the icon. For MFC applications using the document/view model, 142 // this is automatically done for you by the framework. 143
144 void CGPSDataSaveDlg::OnPaint() 145 {
146 if (IsIconic()) 147 {
148 CPaintDC dc(this); // device context for painting 149
150 SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
151
152 // Center icon in client rectangle 153 int cxIcon = GetSystemMetrics(SM_CXICON); 154 int cyIcon = GetSystemMetrics(SM_CYICON); 155 CRect rect;
156 GetClientRect(&rect);
157 int x = (rect.Width() - cxIcon + 1) / 2; 158 int y = (rect.Height() - cyIcon + 1) / 2; 159
160 // Draw the icon 161 dc.DrawIcon(x, y, m_hIcon);
162 }
163 else 164 {
165 CDialog::OnPaint();
166 }
167 }
168
169 // The system calls this to obtain the cursor to display while the user drags 170 // the minimized window. 171 HCURSOR CGPSDataSaveDlg::OnQueryDragIcon()
172 {
173 return (HCURSOR) m_hIcon; 174 }
175
176 void CGPSDataSaveDlg::OnButton1() 177 {
178 // TODO: Add your control notification handler code here 179 p=fopen("data.txt","w");
180 RS.OpenCom(4,4800,8,0,1);
181 SetTimer(1,1000,NULL);
182 //n=StringRipFunction(data,14); 183
184 }
185 int CGPSDataSaveDlg::StringRipFunction(unsignedchar str[],long number) 186 {
187 int i=0,j=0; 188 for(j=0;j<30;j++) 189 strdata[j]="";
190 j=0;
191 for(i=0;i<number;i++) 192 {
193 if(str[i]!=13 && str[i]!=10) 194 {
195 strdata[j]+=str[i];
196 }
197 else 198 {
199 if(str[i]==13) 200 j++;
201 }
202 }
203 for(i=0;i<j;i++) 204 {
205 fprintf(p,"%s\n",strdata[i].GetBuffer(0));
206 }
207 return j; 208 }
209
210 void CGPSDataSaveDlg::OnButton2() 211 {
212 // TODO: Add your control notification handler code here 213 KillTimer(1);
214 RS.Close();
215 fclose(p);
216 }
217
218 void CGPSDataSaveDlg::OnTimer(UINT nIDEvent) 219 {
220 // TODO: Add your message handler code here and/or call default 221 unsignedchar data[1024]={'\0'}; 222 long n=0,n1=0; 223 RS.Read(data,&n);
224 n=StringRipFunction(data,n);
225 CDialog::OnTimer(nIDEvent);
226 }
|