Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top