Solved

Nonblocking MessageBox

Posted on 2002-06-05
10
1,225 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

739 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