Click to See Complete Forum and Search --> : Is this safe to do in thread


sjcguy
January 10th, 2005, 04:34 PM
Hi,
Reading from the FAQ about accessing UI from the worker thread. I'd like to follow the recommendation but my thread function is going to call many other functions and they also need to put out status message on the screen ( CListCtrl).
So my question is: can I declare this as global?

HWND *phObjectHandle;

and then do whenever I create a thread
HWND *phObjectHandle = new HWND;

*phObjectHandle = GetSafeHwnd();

and delete it when I terminate the thread?
thanks.
Also ther question which one is better practice?

1. Create global buffer and whenever I want to print something on the screen. print to the buffer and send message to the main dialog
2. do a new CString and then pass with ::PostMessage and delete it in the main thread.
thanks.

Andreas Masur
January 10th, 2005, 04:42 PM
Well...the problem is pretty simple...as soon as one of the function called by the thread function access any 'CWnd' class, you will have an assertion due to the reasons outlined in the FAQ.

Thus...you should operate with messages...let the functions which need to update any control, post a message in order to update the control.

I do not understand how the global handle should help though.

As for printing to the screen....I would prefer the second solution...