|
-
April 1st, 2012, 10:40 PM
#1
MFC help for building GUI in microsoft visual studio 2008
hi,
i am developing a GUI for my project through MFC using Microsoft visual studio 2008. down below is a part my code that i have written. the purpose of this code is to get GPS data (using marshallsoft GPS component) from serial port, display, and keep on updating the data. i am facing problem using While (1) loop to update GPS data continuously. implementing while loop (as shown in my code) causes the dialog box disappear, although mydialog.exe is shown running at background in the task manager.
any kind of help is appreciated.
thanks
//Variables CTextFile
int Code;
int LinesRX;
char Temp[256];
int decimal, precision = 12, sign;
//CString sDataBuffer(DataBuffer);
//LPCTSTR lpszDataBuffer = sDataBuffer;
CString str, Lat, Long, Alt, Azi, Dist;
CStringArray sensorval;
double Latgcs, Longcs, Altgcs, Compgcs;
double Distance, Azimuth, Angle;
double Latitude, Longitude, Altitude;
CTextFile Sensor;
BOOL res;
str=_T("E:\\sensorfile.txt");
Code = mgcAttach(MGC_KEY_CODE); // attach MGC component
if (mgcOpen(MGC_COM2)== 0)
SetDlgItemText(IDC_GPSPORT, (LPCTSTR) L"OK");
else
SetDlgItemText(IDC_GPSPORT, (LPCTSTR) L"Port Error");
res = Sensor.ReadTextFile(str, sensorval);
Latgcs = wcstod(sensorval[0], NULL);
SetDlgItemText(IDC_LATITUDE, sensorval[0]);
Longcs = wcstod(sensorval[1], NULL);
SetDlgItemText(IDC_LONGITUDE, sensorval[1]);
Altgcs = wcstod(sensorval[2], NULL);
SetDlgItemText(IDC_ALTITUDE, sensorval[2]);
Compgcs = wcstod(sensorval[3], NULL);
SetDlgItemText(IDC_NORTH, sensorval[3]);
while (1)
{
Code = mgcSetInteger(MGC_SET_SENTENCE_TYPE, MGC_SENTENCE_GPGGA);
mgcLockData(1);
Latitude = mgcLatitude();
Lat = _ecvt( Latitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACLAT, Lat);
Code = mgcGetData(GPGGA_LONGITUDE,(LPSTR)DataBuffer);
Longitude = atof (DataBuffer);
Long = _ecvt( Longitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACLONG, Long);
Code = mgcGetData(GPGGA_ALTITUDE,(LPSTR)DataBuffer);
Altitude = atof(DataBuffer);
Alt = _ecvt( Altitude, precision, &decimal, &sign );
SetDlgItemText(IDC_ACALT, Alt);
Distance = mgcGreatCircle(IDC_LATITUDE, IDC_LONGITUDE, IDC_ACLAT, IDC_ACLONG);
Dist = _ecvt( Distance, precision, &decimal, &sign );
SetDlgItemText(IDC_ACDIST, Dist);
Angle = mgcBearing (IDC_LATITUDE, IDC_LONGITUDE, IDC_ACLAT, IDC_ACLONG);
Azimuth = Angle / 60000.0;
Azi = _ecvt( Azimuth, precision, &decimal, &sign );
SetDlgItemText(IDC_ACBEAR, Azi);
mgcLockData(0);
}
return TRUE; // return TRUE unless you set the focus to a control
}
-
April 2nd, 2012, 01:11 AM
#2
Re: MFC help for building GUI in microsoft visual studio 2008
Mike is very good about including samples into his software...look in the "X:\mgc4c\APPS" for sample programs...I'd start with looking into "MFC_PGM.CPP"
Jim
ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII
"The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.
"Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.
-
April 2nd, 2012, 01:18 AM
#3
Re: MFC help for building GUI in microsoft visual studio 2008
You should create a worker thread and move your code to communicate with the serial port (GPS) to this thread. Note: only code tocommunicate with the serial port, not the statements to update GUI!
Then your worker thread has to periodically notify the main GUI thread about new received data (the easiest way to notify is to PostMessage some user defined message(s); then the main thread will update its GUI from the message handler(s) ofthis (these) user defined message(s)).
See Joe Newcomer's essay Using Worker Threads
Victor Nijegorodov
-
April 4th, 2012, 12:13 AM
#4
Re: MFC help for building GUI in microsoft visual studio 2008
thank you so much VictorN. that really helped. :-)
-
April 4th, 2012, 12:56 AM
#5
Re: MFC help for building GUI in microsoft visual studio 2008
You are welcome!
Victor Nijegorodov
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|