SendMessage(MainWnd) from another thread
-
I have an API program in which I have one thread other than the main thread. In the other thread, I wrote
MessageBox(globalMainWndHWND, ...)
, trying to get a message under my main window. The problem is that at this step the MessageBox function does not return! I thought that Windows might prevent threads from using objects created by other threads. I tried to pass the HWND as a parameter to the thread function (instead of using the global variable), but the same problem happened again.SendMessage
did the same thing. Could someone please tell me how I could solve this problem? Thank you very much.Hosam Aly Mahmoud
-
I have an API program in which I have one thread other than the main thread. In the other thread, I wrote
MessageBox(globalMainWndHWND, ...)
, trying to get a message under my main window. The problem is that at this step the MessageBox function does not return! I thought that Windows might prevent threads from using objects created by other threads. I tried to pass the HWND as a parameter to the thread function (instead of using the global variable), but the same problem happened again.SendMessage
did the same thing. Could someone please tell me how I could solve this problem? Thank you very much.Hosam Aly Mahmoud
If the secondary thread does not have its own message pump (i.e., worker thread), calling
MessageBox()
in it will effectively block the message pump in the primary thread.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
-
I have an API program in which I have one thread other than the main thread. In the other thread, I wrote
MessageBox(globalMainWndHWND, ...)
, trying to get a message under my main window. The problem is that at this step the MessageBox function does not return! I thought that Windows might prevent threads from using objects created by other threads. I tried to pass the HWND as a parameter to the thread function (instead of using the global variable), but the same problem happened again.SendMessage
did the same thing. Could someone please tell me how I could solve this problem? Thank you very much.Hosam Aly Mahmoud
Can I see if I can clarify the question? At this point in the secondary thread, you want to cause a message box to be displayed, but you want your secondary thread to continue running even though there's a message box up. To do this, you'll need to post a message to your primary thread (probably to the main window) to cause it to create the message box, using
PostMessage
. UnlikeSendMessage
,PostMessage
is non-blocking - it returns immediately after adding the message to the message queue of the thread that owns the window.SendMessage
blocks the sending thread until the receiving thread responds, by either returning from the window procedure or by callingReplyMessage
(desktop only; Windows CE does not offer this function). The return value ofSendMessage
is the return value of the window procedure, or the value passed toReplyMessage
. -
Can I see if I can clarify the question? At this point in the secondary thread, you want to cause a message box to be displayed, but you want your secondary thread to continue running even though there's a message box up. To do this, you'll need to post a message to your primary thread (probably to the main window) to cause it to create the message box, using
PostMessage
. UnlikeSendMessage
,PostMessage
is non-blocking - it returns immediately after adding the message to the message queue of the thread that owns the window.SendMessage
blocks the sending thread until the receiving thread responds, by either returning from the window procedure or by callingReplyMessage
(desktop only; Windows CE does not offer this function). The return value ofSendMessage
is the return value of the window procedure, or the value passed toReplyMessage
.Thanks for your help. I am sorry to say that your clarification missed a bit. I want to stop the secondary thread, and get out the message box. After the message box returns yes or no, the secondary thread will do work according to the user's choice. But thanks for your help anyway! :rose:
Hosam Aly Mahmoud
-
If the secondary thread does not have its own message pump (i.e., worker thread), calling
MessageBox()
in it will effectively block the message pump in the primary thread.
Five birds are sitting on a fence. Three of them decide to fly off. How many are left?
Thanks for your reply, but could you point out an alternative?
Hosam Aly Mahmoud