D
da kann ich nickhappy zustimmen,
Du Musst in deinem Thread mit PostThreadMessage eine Nachricht an den Dlg senden. Dazu musst du im Dlg noch dir die WindowProc Funktion zulegen und im App dafür sorgen das die Messages aus deinem Thread auch zum WindowProc kommen.
Wenn du Speicher im WorkerThread allozierst und Pointer an den Dlg gibts und er sie dann auch wieder löschen sollte musst du aufpassen das der Dlg nicht grad blockt (zB MessageBox) dann würde die Message allerdings nicht ankommen und Memory Leak angeben.
APP:
BOOL CmyApp::PreTranslateMessage(MSG* pMsg)
{
// Is it the Message you want?
// You can use a switch statement but because this is
// only looking for one message, you can use the if/else
if (pMsg->message == ID_LASTCONTROL +1) // da dir was definieren <--
{
// Call the function to handle this message
this->m_pMainWnd->SendMessage(pMsg->message, pMsg->wParam, pMsg->lParam);
// Tell MFC no more processing is needed
return TRUE;
}
else
// Call MFC to have it continue processing the message
return CWinThread::PreTranslateMessage(pMsg);
}
DLG:
LRESULT CmyDlg::WindowProc(UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == ID_LASTCONTROL + 1) {
switch (wParam) {
case UPDATE_XXX:
if(lParam != NULL) {
GetDescendantWindow(IDC_METADATA)->SetWindowText((TCHAR*)lParam);
delete [] (TCHAR*)lParam;
}
break;
case UPDATE_METABUFFER:
if(lParam != NULL) {
GetDescendantWindow(IDC_METADATABUFFER)->SetWindowText((TCHAR*)lParam);
delete [] (TCHAR*)lParam;
}
break;
case UPDATE_BUFFERPER:
((CProgressCtrl*)GetDescendantWindow(IDC_PROGRESS1))->SetRange(0, 100);
((CProgressCtrl*)GetDescendantWindow(IDC_PROGRESS1))->SetPos((unsigned) lParam);
break;
}
return TRUE;
} else {
return CDialog::WindowProc(message, wParam, lParam);
}
}
Thread:
unsigned WINAPI CmyThread::dowork(void* mythread) {
CmyThread* thisthread = (CmyThread*)mythread;
WPARAM paramw = MAKEWPARAM(0,0);
LPARAM paraml = MAKELPARAM(0,0);
while(!thisthread->doexit()) {
{
// Weiterer Thread von mir für Datenhaltung
CAuLck lock(thisthread->sthreadlock);
CSocketThread* thissocket = (*thisthread->sthread);
if(thissocket != NULL) {
BOOL success = FALSE;
// Radio
TCHAR *rname = NULL, *rgenre = NULL;
if(thissocket->GetServerInfo(&rgenre, &rname)) {
if(rname != NULL) {
success = PostThreadMessage(thisthread->uithreadid, thisthread->msgstart+1, (WPARAM)UPDATE_NAME, (LPARAM) rname);
if(!success)
delete [] rname;
}
if(rgenre != NULL) {
success = PostThreadMessage(thisthread->uithreadid, thisthread->msgstart+1, (WPARAM)UPDATE_GENRE, (LPARAM) rgenre);
if(!success)
delete [] rgenre;
}
} else {
if(rgenre != NULL)
delete [] rgenre;
if(rname != NULL)
delete [] rname;
}
// Metadaten
TCHAR *mtitle = NULL;
if(thissocket->GetMetaData(&mtitle)) {
if(mtitle != NULL) {
success = PostThreadMessage(thisthread->uithreadid, thisthread->msgstart+1, (WPARAM)UPDATE_META, (LPARAM) mtitle);
if(!success)
delete [] mtitle;
}
} else {
if(mtitle != NULL)
delete [] mtitle;
}
// buffer
unsigned per = 0;
if(thissocket->GetBufferPerce(per)) {
PostThreadMessage(thisthread->uithreadid, thisthread->msgstart+1, (WPARAM)UPDATE_BUFFERPER, (LPARAM) per);
}
}
}
Sleep(250);
}
return 0;
};