Update Listcontrol
-
Hi everyone, my app should update a listcontrol inside a while statement, but the data are shown only at the end of the whole function, when the app gets the idle state. Furthermore, all the buttons can't be pressed until the end of the function. Can somenone explain me the way to work with it? Thanks Vilmer
-
Hi everyone, my app should update a listcontrol inside a while statement, but the data are shown only at the end of the whole function, when the app gets the idle state. Furthermore, all the buttons can't be pressed until the end of the function. Can somenone explain me the way to work with it? Thanks Vilmer
try putting a call to Sleep() for a few milliseconds in your while loop, or make the function static and use AfxBeginThread() to call the function. If I write code in my sleep, does that make me brilliant, or just a lazy programmer? My articles www.stillwaterexpress.com BlackDice - the programmer formerly known as bdiamond
-
Hi everyone, my app should update a listcontrol inside a while statement, but the data are shown only at the end of the whole function, when the app gets the idle state. Furthermore, all the buttons can't be pressed until the end of the function. Can somenone explain me the way to work with it? Thanks Vilmer
It sounds like you would benefit from a separate thread that updates the list control. This would allow the GUI to remain responsive to button clicks and repainting.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
-
It sounds like you would benefit from a separate thread that updates the list control. This would allow the GUI to remain responsive to button clicks and repainting.
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
Yeah, you hit the problem. But the items of the listcontrol are related to some data which change in the while loop. If I use threads, the data taken from any thread won't be correct, because the while statement continue its run, not taking care of the threads execution. My question is: is there any way to create a (or more) thread which can use dynamic data which depend on something outside the thread? I know that threads can refer to a pointer to parent, and they can use its member variables, but there's no way for me to make that data useful, because they change always.
-
Yeah, you hit the problem. But the items of the listcontrol are related to some data which change in the while loop. If I use threads, the data taken from any thread won't be correct, because the while statement continue its run, not taking care of the threads execution. My question is: is there any way to create a (or more) thread which can use dynamic data which depend on something outside the thread? I know that threads can refer to a pointer to parent, and they can use its member variables, but there's no way for me to make that data useful, because they change always.
I was thinking more of having the whole function with the while loop in it be executed through a thread. Then there's 3 choices I can think of: 1. send a pointer to your parent class's instance, and access its variables through this pointer. 2. send a pointer to your parent class's instance, then make the variables/values that will be changing static members of the parent class 3. make the variables/values global If I write code in my sleep, does that make me brilliant, or just a lazy programmer? My articles www.stillwaterexpress.com BlackDice - the programmer formerly known as bdiamond
-
I was thinking more of having the whole function with the while loop in it be executed through a thread. Then there's 3 choices I can think of: 1. send a pointer to your parent class's instance, and access its variables through this pointer. 2. send a pointer to your parent class's instance, then make the variables/values that will be changing static members of the parent class 3. make the variables/values global If I write code in my sleep, does that make me brilliant, or just a lazy programmer? My articles www.stillwaterexpress.com BlackDice - the programmer formerly known as bdiamond
I'll show you an example of how my code works: CListCtrl myLC; int Num; (as members of CMyClass) void CMyClass::OnButtonStart() { Num = 0; char* ptrItem; while (Num < 100) { itoa(Num,ptrItem,10); myLC.InsertItem(Num,ptrItem); Num++; } } If I use AfxBeginThread(MyThread,this) - where MyThread provides only the InsertItem statement - inside the while statement and then refer to a CMyClass instance, that instance show a value of Num which is already 100, beacause the while statement doesn't wait for the thread to finish its execution. :eek: Aaarrgggghhhh
-
I'll show you an example of how my code works: CListCtrl myLC; int Num; (as members of CMyClass) void CMyClass::OnButtonStart() { Num = 0; char* ptrItem; while (Num < 100) { itoa(Num,ptrItem,10); myLC.InsertItem(Num,ptrItem); Num++; } } If I use AfxBeginThread(MyThread,this) - where MyThread provides only the InsertItem statement - inside the while statement and then refer to a CMyClass instance, that instance show a value of Num which is already 100, beacause the while statement doesn't wait for the thread to finish its execution. :eek: Aaarrgggghhhh
I was thinking more along the lines of this:
void CMyClass::OnButtonStart() { AfxBeginThread(FillListView,this); } UINT ListView(* pClass) **//forgot how the function declaration has to be**:zzz: { CMyClass* pMyClass = (CMyClass*)pClass; pClass->Num = 0; char* ptrItem; while (pClass->Num < 100) { itoa(pClass->Num,ptrItem,10); pClass->myLC.InsertItem(Num,ptrItem); pClass->Num++; } return 0; }
the syntax may be a little off since I'm doing it out of my head, but I think you should be able to follow what I'm saying. I hope this helps in any way. If I write code in my sleep, does that make me brilliant, or just a lazy programmer? My articles www.stillwaterexpress.com BlackDice - the programmer formerly known as bdiamond