CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Simple way to make a timeout message box

    Is there a simple way to display a message box that just kills itself after a certain amount of time (not using MFC)? It would also be nice if the message box were modeless.

    THe only reason I am doing this is that windows demands a 2-second wait for the serial port handle to be released (on some machines it happens faster than that, but 2 seconds is in the docs so to be safe one better do the wait). 2 seconds is a long enouhg time to be irritating so I'd like to inform the user without the user having to do anything.

    Probably have to create a modeless dialog box or class window with a static window containing the message with a self destructing timer, right?

    Brian

  2. #2
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Simple way to make a timeout message box

    You may use SetTimer to create a timer with an elapse of 1000 milliseconds. You can specify that your modeless dialog will receive WM_TIMER if the second elapses. Then you may count the seconds, and close the dialog after 30 seconds elapse.

    But you have to design this messagebox on your own, because I do not think that you can display the windows messagebox modeless.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  3. #3
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Simple way to make a timeout message box

    That's what I was afraid of. Have to make my own window, callback, timer, and in the callback a handler for the timer to destroy the window. I have an owner draw message box which I guess I might as well modify to handle this type of thing. No easy way out!

    Brian

  4. #4
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Simple way to make a timeout message box

    I can't find any way to create a modeless messagebox.

    But you might view these:
    http://www.codeguru.com/Cpp/misc/mis...icle.php/c249/
    http://www.codeguru.com/Cpp/misc/mis...icle.php/c203/

    Last edited by NoHero; December 6th, 2004 at 09:56 AM.
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  5. #5
    Join Date
    Dec 2002
    Location
    Candia, NH
    Posts
    374

    Re: Simple way to make a timeout message box

    Thanks NoHero,

    I'll take a look at their approach....but I think I will ditch the thread.

    Brian

  6. #6
    Join Date
    Mar 2004
    Location
    (Upper-) Austria
    Posts
    2,899

    Re: Simple way to make a timeout message box

    found a work around?
    I am not offering technical guidiance via email or IM
    Come on share your photo with us! CG members photo album!
    Use the Code Tags!

  7. #7
    Join Date
    Feb 2025
    Posts
    2

    Re: Simple way to make a timeout message box

    Quote Originally Posted by NoHero View Post
    found a work around?
    This is like 21 years later, but I finally came across another person's API solution - works like a dream:

    https://stackoverflow.com/questions/...another-thread

  8. #8
    Join Date
    Feb 2025
    Posts
    2

    Re: Simple way to make a timeout message box

    I should add that the above links to this:
    https://www.codeproject.com/KB/cpp/M...oxTimeout.aspx

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured