Solved

Nonblocking MessageBox

Posted on 2002-06-05
10
1,161 Views
Last Modified: 2008-02-01
I would like to use a MessageBox in C++ Builder, that would not block the execution of the program even if the user does not respont to the MessageBox window.
Should be something like the Outlook "Incoming mail" notification MessageBox.
Thanks
Octi
0
Comment
Question by:octi
  • 5
  • 4
10 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 7056330
The messagebox in Builder is an interface to the windows API MessageBox() function.  That function will block the current thread.  Its design requires it to block the thread because the function needs to return information to the program  (i.e. which button was pressed.) and because the idea is that it presents information to the user and gets a response from the user that determines what the program should do ("okay to delete file?"  the program needs an answer to this before it can go on.)

If you don't want to block the thread then most likely you really shouldn't be using MessageBox.   You can simply use a window of another type--probably a type you create.

However, if you really do want to use it, you can, just start a new thread and call message box from that thread.

Are you familar with threads?

The problem with this approach would be getting infromation back from that thread that indicates what button the user pressed.  However, most likely you don't need this--otherwise you woudl want it to block the thread..  However, if you do need to get information back, let me know, it can be done.


Let me know if you have any questions.
0
 
LVL 22

Expert Comment

by:nietod
ID: 7056339
I should point out something.   You mention an "incoming mail" message window.   There is an important difference between that type of window and the MessageBox type of window.   the Messagebox window is closed by the user.  The incoming mail one is closed when the mail arrives.      That is a very important difference in how the windows function.  

If you need the window to close from sources other than the user clicking on a close button, then that is even further evidence that you really don't want to use MessageBox() for this.

What is this window for?
0
 

Author Comment

by:octi
ID: 7056476
Hi,

You are wrong about "Incoming mail" notification window. Actually the user closes it (only). If not, it remains on the desktop.

So there is no difference between API's MessageBox and Microsoft Outlook's notification message windows - from this point of view.

In the mean while you can access your calendar, private folders, can receive other emails, without responding to the message window.

I need this particular MessageBox to show a message that comes from the socket (asynchronously). After the message is shown, my program should work as before, even if the user does not respond to the message. (Like in Microsoft Outlook)

The message text length could vary, so I don't want to deal with sizing the Message Window that I would create my self-etc. since the MessageBox API already solves this.

I did not necessarily refer to Builders wrapped MessageBox function, (Application->MessageBox) but all kind of message dialogs, that could be called from C++ Builder.

If there is really no other method then separated thread, I will accept your answer, but this method may not worth using it.
Octi.
0
 
LVL 22

Accepted Solution

by:
nietod earned 50 total points
ID: 7056802
>> You are wrong about "Incoming mail" notification window.
I don't use outlook.   so I had no way of knowing.    However most other mail systems--and inmost other similar situations the program closes the window.  For good reason too!

>> In the mean while you can access your calendar, private folders, can
>> receive other emails, without responding to the message window.
That is a huge difference though.  

There are two possible solutions.  

You can start a seperate thread and use Messagebox or you can create a regular (non-modal) window for doing this.

>>  this method may not worth using it.
why not?
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7057105
MessageBox is handy because it sizes itself dynamically based on the text and it displays an icon and it provides a way to use different sets of buttons.

Alas, the standard MessageBox is always Modal.  But it is not particularly hard to make a regular dialog look a lot like a MessageBox and then use Create() rather than DoModal (or whatever Borland uses).  That way, you can put up as many of these 'simulated MessageBox' dialog boxes as you want -- without the headache of making a new thread for each one.

-- Dan
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:octi
ID: 7058613
I promised to accept your answer if there is no other solution then thread.
Still the method is not worth using it becase it's wrong thinking. (Use thread to show a modal dialog as non-modal - rather show a non-modal one)

About "incoming mail"...if you don't use outlook don't make "smart" comments.
Octi
0
 
LVL 22

Expert Comment

by:nietod
ID: 7058858
>> About "incoming mail"...if you don't use outlook don't make "smart" comments.
What?

Look most operations like that have a limited lifetime.  When the operation is done, the window closes.   Like when you copy files in explorer it shows you a dialog during the copy process.  You don't have to close this dialog--thank god--it closes automatically when the operation is done.  Most mail programs do this as well.   Lots of programs do this.   I can't imagine why outlook doesn't.    but you may want to consider it for your program.   Is there a good reason wjy your window should stay open after the operation completes?   If not, why make the user go to the effort of closing it?

>> Still the method is not worth using it becase it's wrong thinking.
How?

It provides the right behavior and has no real drawbacks--unless you plan on opening up many of these windows all at the same time.  its easy to implement and meets all of your needs.    I don't see the problem.

What are your reservatiosn agbout this?
0
 

Author Comment

by:octi
ID: 7058867
I already mentioned, that I will use the messagebox to display incoming messages from a communication endpoint (a socket).
It needs the user interaction, because the user should read the message, before the MessageBox closes.

In the mean while, the program should respond to other network or user events.

And yes, I plan to open more this kind of windows at the same time, because it's up to the communication endpoint how many messages will arrive.
0
 
LVL 22

Expert Comment

by:nietod
ID: 7058965
It doesn't sound like a :"notification" window to me, but more like the actual mail window.

How many of these windows do you think would be open at a time?   And what OS (OSs) is this for?

If it is for 95/98, its probably not a good to try if you expect to have more than 6 or 7 open at a time.   Under NT you aren't going to have much problem unless a lot of them are open.
0
 

Author Comment

by:octi
ID: 7058976
Actually this window contains both in the same time. It's a notification, but also contains the short text message coming from a user.
After the text was read the window can be closed by the user.
(Like net send ...service under NT)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now