Click here to Skip to main content
15,925,181 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Is This Thread Safe Pin
Code-o-mat25-Dec-08 22:51
Code-o-mat25-Dec-08 22:51 
GeneralRe: Is This Thread Safe Pin
BobInNJ26-Dec-08 6:16
BobInNJ26-Dec-08 6:16 
GeneralRe: Is This Thread Safe Pin
Code-o-mat26-Dec-08 7:57
Code-o-mat26-Dec-08 7:57 
GeneralRe: Is This Thread Safe Pin
BobInNJ26-Dec-08 8:28
BobInNJ26-Dec-08 8:28 
GeneralRe: Is This Thread Safe Pin
Mark Salsbery26-Dec-08 10:20
Mark Salsbery26-Dec-08 10:20 
GeneralRe: Is This Thread Safe Pin
Code-o-mat26-Dec-08 10:56
Code-o-mat26-Dec-08 10:56 
GeneralRe: Is This Thread Safe Pin
Mark Salsbery26-Dec-08 11:27
Mark Salsbery26-Dec-08 11:27 
GeneralRe: Is This Thread Safe Pin
Code-o-mat26-Dec-08 10:38
Code-o-mat26-Dec-08 10:38 
Afaik CWnd::PostMessage doesn't do anything else but calls the API PostMessage specifying the handle of the window it represents, so there's not much difference between those two, however, if we stick to the general rule of not handing CWnd objects (pointers) over to different threads, i'd say, go for the api call. It's also somewhat safer since if your CWnd gets for some reason deleted then if a thread tries to call its CWnd::PostMessage it will give you the dreaded Access Voilation error. However, if you specify an invalid handle to the API PostMessage it will check that handle to see if a window with that handle exists and if not, then it will simply not post any message to it, thus, no crash. I have no idea about CWindow::PostMessage.
Alternatively you could use PostThreadMessage to post thread messages, these work almost the same way as window messages but they are not targeted at specific window procedures (their target hWnd will be NULL). If you use window messages, note, that in certain circumstances they can get lost. For example, when the user starts dragging a window in the GUI thread to move it around, a "custom" message loop starts up which filters out and throws away certain messages (i guess the reason for this is to avoid nasty situations like crashes, but ask Microsoft about that), so it could happen that while the user moves your window, the messages coming from your threads simply disappear in a black hole never to be seen again. However, this does not seem to happen with thread messages.

BobInNJ wrote:
I would also like to say that the codeproject has quickly become one of my favorite websites due to people like Code-o-mat.


Thanks, you are making me blush. Laugh | :laugh:

> The problem with computers is that they do what you tell them to do and not what you want them to do. <

Questioncannot delete CStringArray like this? [modified] Pin
kaviniswell25-Dec-08 15:58
kaviniswell25-Dec-08 15:58 
AnswerRe: cannot delete CStringArray like this? Pin
kaviniswell25-Dec-08 16:12
kaviniswell25-Dec-08 16:12 
AnswerRe: cannot delete CStringArray like this? Pin
BobInNJ25-Dec-08 16:38
BobInNJ25-Dec-08 16:38 
GeneralRe: cannot delete CStringArray like this? [modified] Pin
kaviniswell25-Dec-08 17:31
kaviniswell25-Dec-08 17:31 
GeneralRe: cannot delete CStringArray like this? Pin
kaviniswell25-Dec-08 17:45
kaviniswell25-Dec-08 17:45 
GeneralRe: cannot delete CStringArray like this? Pin
Richard Andrew x6426-Dec-08 0:40
professionalRichard Andrew x6426-Dec-08 0:40 
GeneralRe: cannot delete CStringArray like this? Pin
kaviniswell26-Dec-08 1:23
kaviniswell26-Dec-08 1:23 
Questionwindow in thread Pin
dene9997025-Dec-08 13:00
dene9997025-Dec-08 13:00 
AnswerRe: window in thread Pin
Richard Andrew x6425-Dec-08 13:28
professionalRichard Andrew x6425-Dec-08 13:28 
QuestionAdding a .wav file as a resource in visual studio 2008 express, Hi, I need some help with this Pin
Sadaiyappan25-Dec-08 5:57
Sadaiyappan25-Dec-08 5:57 
AnswerRe: Adding a .wav file as a resource in visual studio 2008 express, Hi, I need some help with this Pin
Richard Andrew x6425-Dec-08 8:10
professionalRichard Andrew x6425-Dec-08 8:10 
GeneralRe: Adding a .wav file as a resource in visual studio 2008 express, Hi, I need some help with this Pin
Sadaiyappan25-Dec-08 8:18
Sadaiyappan25-Dec-08 8:18 
GeneralRe: Adding a .wav file as a resource in visual studio 2008 express, Hi, I need some help with this Pin
Richard Andrew x6425-Dec-08 8:20
professionalRichard Andrew x6425-Dec-08 8:20 
QuestionCAtlRegExp Match Pin
dehseth25-Dec-08 2:41
dehseth25-Dec-08 2:41 
AnswerRe: CAtlRegExp Match Pin
Yuriy Levytskyy25-Dec-08 5:24
Yuriy Levytskyy25-Dec-08 5:24 
AnswerRe: CAtlRegExp Match Pin
Stuart Dootson25-Dec-08 22:33
professionalStuart Dootson25-Dec-08 22:33 
Questionflcose API is taking so much time to close the large file [modified] Pin
Vishal Kumar Soni25-Dec-08 0:37
Vishal Kumar Soni25-Dec-08 0:37 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.