views:

202

answers:

8

I want to pop up a window to show that a program is busy with a particular time consuming task. But I don't want any buttons on it. I just want to pop it up, do the task, then remove it. I'm not sure what such a window is called and so don't know what to search for in MSDN etc. Is there some ready made API for this kind of thing or do I need to cook my own?

EDIT: In answer to some comments...

I'm not using MFC.

The program is for my own use - the answer does not have to look pretty.

The reason I don't just rely on the hourglass is that the hourglass only shows when the cursor is on top of the applications small window, and I work on a system with four very large monitors and the cursor is often not on the window in question.. If I don't see an hourglass then my program looks like its crashed. Its quite disturbing. I work on this program continuously as my job, and have done so for many years. The operation that takes a long time is performed only occasionally, I may go months without using it. So if it locks up doing this task I'm worried that I will have forgotten that its just busy and assume there's some bug and go on a wild goose chase trying to fix a problem that does not exist.

+1  A: 

i think you are looking for Splash screen

Ashish
A: 

Actually, since it's such a trivial window, you're probably best of creating it yourself. You probably can get away with handling just WM_PAINT and nothing else.

MSalters
+1  A: 

Take a look at CreateWindowEx function. You can use WS_POPUP as dwStyle to create a popup window. Look here for a list of window styles.

Donotalo
+2  A: 

why???

The accepted windows idiom is to use the hourglass cursor.

an even better solution is to do this long running task on a different thread and let the user continue on doing other things (this may not be applicable in your case though)

You could create a progress bar to show the user that something is happening, but these pretty much always have a cancel button. Users like being able to cancel long running tasks.

As others have posted, there's the CreateWindowEx function. However, I think you should think some more about your design before doing this

Glen
Good question. The thing is the hourglass only shows when the cursor is on top of the applications small window, and I work on a system with four very large monitors and the cursor is often not on the window in question.. If I don't see an hourglass then my program looks like its crashed. Its quite disturbing.
Mick
See edit to original post.
Mick
+4  A: 

This is actually a more profound question than simply dialogs. If you are engaging in work which may take a long time, then you don't want it on the main thread. On Windows versions prior to Vista, the Window won't paint - you end up with "white window" syndrome, which is very ugly. Far better to create a worker (non-ui) thread and have it post a message back to the main window when it's done. Obviously you have to have some sort of timeout in case it never finishes. If you do it this way, then the "dialog" problem becomes an issue of simply putting up a window and pulling it down again when the thread sends you its "done" message. You can try looking at the MSDN documentation for "modeless dialog", a dialog which can you can create and destroy at will (remember to disable the main window). There are some nits with implementing this in MFC, but you don't say whether you're using that or not.

Bob Moore
A: 

Why waste resources showing a new window when you've got the user's poor machine tied up doing other stuff? - doesn't make sense.

Stick to more standard UI conventions, and your users will thank you (well, they won't, but they may not complain).

Galwegian
Even best computers might require large amount of time for some tasks thous the machine does not have to be "poor" just because the task takes much time. Also you mention "standard UI conventions" however you point to none.
Adam Badura
A: 

if you are developing with Visual Studio, you can add a dialog resource to your project. the dialog will only contain the text you specified in your question and no button. don't forget to assign a meaningful ID to the dialog box. if you are not using Visual Studio, you can still write the dialog box template (after all, it is just a text file) and compile it using the resource compiler which you can find everywhere on the net.

now in your code, use the CreateDialog() function to create your dialog, then ShowWindow(). you will have to setup a message loop for the dialog to be repainted. there is a good set of example in the MSDN.

i will add that you need a modeless dialog: calling DialogBox() to create and display a modal dialog will block until the dialog is dismissed by a user action, since you have no button on your dialog it will never be dismissed, so the call will block indefinitely.

unfortunately, this means writing your own message loop and while you are processing window messages, you will not be running your long computation. so basically, i fear you need to create the dialog box in a new thread in order to get the behaviour you describe.

Adrien Plisson
A: 

The traditional method is to display a progress indicator, whether it be a propeller or an hourglass. A propeller can be displayed on the console:

"|"
"\b/"
"\b-"
"\b\\"

Repeat as long as there is no response to the user. As long as computers have been hanging, people have wanted progress indicators to show that the computer is alive and processing.

Another is the heart beat:

"*"
"\b "
"\b*"
Thomas Matthews