views:

465

answers:

3

My program has multiple threads. I am using messagebox to display information to the user. Is there anyway (or an alternative to message box) that I can have another thread update/change the message-box display text while the message box is still on the screen and visible by the user?

+5  A: 

If you are using a standard Win32 message box I don't believe there is any way of changing the text once the box is already shown (you enter a modal message pump).

I would suggest you create your own window that listens to messages/updates from your other threads. That way you are in control.

Filip
This is the correct answer. The classic message box isn't designed for this. You will need to build your own dialog box and APIs to support this. The good news is that this will not be too hard. Just use windows messages to PostThreadMessage() is your friend here.
Foredecker
Yes, you can change the MessageBox() text dynamically. Use SetWindowsHookEx() to install a CBT hook prior to calling MesageBox(). The hook will provide you with the dialog's HWND, which you can then use to gain access to all of the child windows of the dialog and do whatever you want to them.
Remy Lebeau - TeamB
@Remy - coll trick =)
Filip
A: 

I don't believe there's a direct way to do this, you probably could try to get the window handle but this is way too messy. Your best bet is to create your own dialog box so that you you have total control over it.

Waleed Eissa
+1  A: 

Using thread-specific hooks via GetCurrentThreadId() and SetWindowsHookEx(), you can hook the messages that MessageBox() receives internally, as well as gain access to the dialog's main window handle, which then gains you access to all of the child controls of the dialog. You can then customize the dialog and its control as needed. This technique is commonly used for implementing self-closing dialogs (before MessageBoxTimeout() was introduced), customize the text of the buttons, etc.

Remy Lebeau - TeamB