Multiple Processes: Threads, Messages, Etc
-
Hey, Could any one please tell me any idea on how can i solve this problem. I made a list box in which files can be added and can also be zipped. However, all of this is done in a while loop so the dialog isn't receivng any messages, kind of freezing until the loop is done. I would like to be able to click Cancel but it's not working. I tried inserting this in the middle of the loop: CWinApp* pApp = AfxGetApp(); MSG msg; while ( PeekMessage ( &msg, NULL, 0, 0, PM_NOREMOVE )) pApp->PumpMessage(); but it makes it a lot slower and while the files are being zipped this won't work. I created a worker thread but the problem is that i need to call functions like: next = m_files.GetNextItem(next-1 ,LVNI_SELECTED ); which are non static so the compiler will give me an error. It won't work either with GUI thread. Any suggesions on how to fix this? Thanks alot. Regards, Eric
-
Hey, Could any one please tell me any idea on how can i solve this problem. I made a list box in which files can be added and can also be zipped. However, all of this is done in a while loop so the dialog isn't receivng any messages, kind of freezing until the loop is done. I would like to be able to click Cancel but it's not working. I tried inserting this in the middle of the loop: CWinApp* pApp = AfxGetApp(); MSG msg; while ( PeekMessage ( &msg, NULL, 0, 0, PM_NOREMOVE )) pApp->PumpMessage(); but it makes it a lot slower and while the files are being zipped this won't work. I created a worker thread but the problem is that i need to call functions like: next = m_files.GetNextItem(next-1 ,LVNI_SELECTED ); which are non static so the compiler will give me an error. It won't work either with GUI thread. Any suggesions on how to fix this? Thanks alot. Regards, Eric
Pass the HWND of the list control to your worker thread. You can then use the straight APIs to access the list (sending messages is safe between threads in the same process), or make a local CListCtrl variable and attach it to the window handle, if you prefer using CListCtrl methods.
UINT ThreadProc(void* pv)
{
CListCtrl list;list.Attach ( (HWND) pv );
// ...// Don't forget to detach or the CListCtrl destructor will destroy
// the control.
list.Detach();return retcode;
}--Mike-- http://home.inreach.com/mdunn/ Trillian: What are you supposed to do with a manically depressed robot? Marvin: You think you've got problems. What are you supposed to do if you are a manically depressed robot?
-
Pass the HWND of the list control to your worker thread. You can then use the straight APIs to access the list (sending messages is safe between threads in the same process), or make a local CListCtrl variable and attach it to the window handle, if you prefer using CListCtrl methods.
UINT ThreadProc(void* pv)
{
CListCtrl list;list.Attach ( (HWND) pv );
// ...// Don't forget to detach or the CListCtrl destructor will destroy
// the control.
list.Detach();return retcode;
}--Mike-- http://home.inreach.com/mdunn/ Trillian: What are you supposed to do with a manically depressed robot? Marvin: You think you've got problems. What are you supposed to do if you are a manically depressed robot?
Hey Michael, thanks a lot for replying. I'll try that. Thanks again.