I am useing worker thread in Dialog base Application.In Dialog I have a Static Control and Button.I try to set some values in Static Control.I have got some GUI Error application and CtlColor color change auto.As well as Control move from fixed position.I am doing like this
Never never access GUI elements in another thread than the GUI thread. This is a recipe for disaster. One way to solve your problem is instead to access the static control directly in your thread, you simply send a user defined message to your dialog. In the handler of this message, you update your control. This way, this is the UI thread that still accesses the control. More info and examples here[^]
If you would have taken the time to look at the article I linked to, you could see that there's an example in the section "Worker threads and the GUI II: Don't touch the GUI".
It's been a while that you are posting questions about threads and you still miss some basic concepts. Don't you think it could be interesting for you to read some good article (like the one I linked to you) about the subject ? Otherwise, you'll come asking questions here again and again and never really learn how to do it the proper way.
By touch I mean manipulating any UI related element.
Eugen Podsypalnikov wrote:
it is working
Did you test it ? If it works, you are lucky. But it is any way an extremly bad practice. I suggest you read the section "Worker threads and the GUI II: Don't touch the GUI" in the article I mentioned earlier to have a bit more information.
newCCtrlDrawContext(new CClientDC(&m_cwndStatic), // first par
cStaticRect)); // second par
Try the following :
0. Repair the state of your project (see your starting post)
1. Place the new context class at the top of your cpp, after the include block
2. Modify your OnClick function
3. Modify your ThreadLoop function