Hello Everyone,
I am working on an application in which there is a dialog box. On one side of a dialog box there is a custom and on other side there is Tab Control. Am using the custom control for displaying a Bar graph which is updating continuously depending on the values am receiving via USB port. On one of the tabs(child dialog) of Tab control I have placed a slider control.
I have written the thread for Bar control in
OnInitDialog()
function of the main dialog box. As soon as I move the slider control on child window, the bar control stops updating. What should I do to start that thread again after I release the slider control?
I can't make any changes in the GUI now. How can I call the thread again from the child window?
Here is the code where am creating the thread and the thread function.
BOOL CMonitorMediaSensor::OnInitDialog()
{
CDialogEx::OnInitDialog();
SetBackgroundColor (g_DlgColor);
m_chart.SubclassDlgItem(IDC_CUSTOMSENSORBAR, this);
m_chart.PrepareColors(CNSChartCtrl::SimpleColors);
m_chart.AddValue(m_nSensorValue,"Sensor Value");
m_chart.m_nMode = 0;
m_SnapDlg = new CMediaSensorSnapDlg;
m_SnapDlg->Create(CMediaSensorSnapDlg::IDD, &m_SnapTabCtrl);
m_SnapTabCtrl.AddTab(m_SnapDlg, "Calibrate", 0);
m_SnapDlg->m_pSnapTabCtrl = &m_SnapTabCtrl;
m_SnapDlg->m_chart.m_nMode = 1;
m_SnapDlgMonitor = new CMediaSensorSnapDlg;
m_SnapDlgMonitor->Create(CMediaSensorSnapDlg::IDD, &m_SnapTabCtrl);
m_SnapTabCtrl.AddTab(m_SnapDlgMonitor, "Profiling", 1);
m_SnapDlgMonitor->m_pSnapTabCtrl = &m_SnapTabCtrl;
m_SnapDlgMonitor->m_chart.m_nMode = 0;
m_SensorGainDlg = new CSensorGain;
m_SensorGainDlg->Create(CSensorGain::IDD, &m_SnapTabCtrl);
m_SnapTabCtrl.AddTab(m_SensorGainDlg, "Sensor Gain", 2);
m_SnapDlgMonitor->m_pSnapTabCtrl = &m_SnapTabCtrl;
m_SnapTabCtrl.SetCurFocus (1);
g_portio->m_bCloseMediaSensorThread = FALSE;
m_bCloseSensorMonitorThread = FALSE;
m_MediaSensorData = new MEDIASENSORDATA;
m_MediaSensorData->pbCloseThread = &m_bCloseSensorMonitorThread;
m_MediaSensorData->pCS = &g_portio->m_CS;
m_hMediaSensor = AfxBeginThread (MonitorMediaSensorProc,
(void*)m_MediaSensorData,
THREAD_PRIORITY_NORMAL, 0, 0);
return TRUE; }
UINT MonitorMediaSensorProc (LPVOID pParam)
{
MEDIASENSORDATA* monData = (MEDIASENSORDATA*) pParam;
BOOL* pbCloseThread = monData->pbCloseThread;
CCriticalSection* pcs = monData->pCS;
CSingleLock lock(pcs);
char szQueryCommand[6];
szQueryCommand[0] = g_cSTX;
szQueryCommand[1] = 'K';
szQueryCommand[2] = 'L';
szQueryCommand[3] = g_cCR;
szQueryCommand[4] = 0x0A;
szQueryCommand[5] = '\0';
while (1)
{
if(lock.Lock ())
{
if(g_portio->m_bCloseMediaSensorThread || *pbCloseThread)
{
lock.Unlock ();
delete(monData);
monData = NULL;
return 0;
}
g_portio->SendData (szQueryCommand, 6);
lock.Unlock ();
}
Sleep (100);
}
return 0;
}