HyperEngineer
Programmer
I want to start a thread then write back to the main dialog to show the progress. It gets lost on the SetWindowText() function. Don't know where it goes. Here is the code:
This is in the header file:
This is the button that starts the other thread:
This is the function call in _beginthreadex();
I single step through this code and it goes off into forever land when it tries to execute the SetWindowTextA() function.
It looks like it has good handle values but it won't come back from that call.
What am I doing wrong?
thanks,
HyperEngineer
If it ain't broke, it probably needs improvement.
This is in the header file:
Code:
static unsigned int __stdcall TestProgressTimer(void* arglist);
This is the button that starts the other thread:
Code:
void CAnvilDlg::OnBnClickedStart()
{
HANDLE hTestTimerThread;
unsigned int threadID;
// Start the test timer thread.
hTestTimerThread = (HANDLE)_beginthreadex(NULL, 0, TestProgressTimer,(void*) this, 0, &threadID);
WaitForSingleObject(hTestTimerThread, INFINITE);
CWnd* hEditBox = (CRichEditCtrl*)GetDlgItem(IDC_ACTIVITY);
hEditBox->SetWindowTextA("Timer Returned");
}
This is the function call in _beginthreadex();
Code:
unsigned int __stdcall CAnvilDlg::TestProgressTimer(void* arglist)
{
unsigned int counter = 0;
unsigned long lstart;
CAnvilDlg* MainDlg = (CAnvilDlg*) arglist;
CWnd* hTimeLabel;
char strCount[32];
lstart = GetTickCount();
while (counter < 10)
{
if (GetTickCount() > (lstart + 1000))
{
counter++;
sprintf_s(strCount, sizeof(strCount), "%d", counter);
hTimeLabel = MainDlg->GetDlgItem(IDC_ACTIVITY);
hTimeLabel->SetWindowTextA(strCount);
lstart = GetTickCount();
}
}
_endthreadex(0);
return 0;
}
I single step through this code and it goes off into forever land when it tries to execute the SetWindowTextA() function.
It looks like it has good handle values but it won't come back from that call.
What am I doing wrong?
thanks,
HyperEngineer
If it ain't broke, it probably needs improvement.