Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

MFC help for building GUI in microsoft visual studio 2008

Status
Not open for further replies.

jawadali477

Member level 1
Member level 1
Joined
Dec 23, 2010
Messages
41
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,588
hi,
i am developing a GUI for my project through MFC using Microsoft visual studio 2008. down below is a part of 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 continuous loop (While loop) to update GPS data. 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

Code:
//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

}
 
Last edited by a moderator:

By default applications' Graphical User Interfaces run on single thread. This applies also to MFC applications. The GUI (windows, dialogs, etc.) are ran from a single GUI thread.
Inside this thread works the windows message pump. If you block it with a while() loop the window won't refresh (redraw) and will freeze.
What you need here is a parallel thread to parse/update the data from the GPS.
Take a look at the AfxBeginThread() function on MSDN.
If you have never worked with threads I advise you to take a look at multithread programming under windows.
 
thank you very much p.luc.:) it really helped.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top