how to show a message box then close it automatically

Posted on 2010-01-04
Last Modified: 2012-05-08
How can i show then close a messagebox without using the OK button?
Question by:cmdolcet
    LVL 12

    Expert Comment

    Just as an alternative, you could design your own form and have it pop up with your message...make it look however you want it too...
    LVL 51

    Expert Comment

    as suggested above, create a form with a label
    add a timer, on timer event put me.close

    create a function like showMessage(msg as string, t as integer)

    this function will create the form, set the label to msg, activate the timer set the interval to t*1000
    LVL 8

    Accepted Solution

    Use following line :
            CreateObject("WScript.Shell").Popup("Place message here", 3, "Message Title")

    3 indicates the number of seconds of visibility of a message. After 3 seconds, message will be disappear.
    LVL 11

    Expert Comment

    I creating a form and show as suggested by rgn2121, is the best possible way.
    LVL 39

    Expert Comment

    if your OS is windows XP or over you can use API's from user32.dll.

    here is a class developed in c# based on these API calls.
    Get the .CS file create a dll file and reference it in your application and call the MessageBoxEx.Show method.
    LVL 9

    Expert Comment

    You may do the same as follows, enumerate the windows after you call the messagebox function something like

    //first display your messagebox with some title that i name WindowTitle
    EnumThreadWindows(GetCurrentThreadId(), EnumThreadWndProc, (LPARAM)WindowTitle);
    The EnumThreadWindows is defined in below code window.

    Hope it helps :)

    // Define EnumThreadWndProc()
    BOOL CALLBACK EnumThreadWndProc(HWND hwnd, LPARAM lParam)
    char WndName[50]; //to hold the title of message box, assuming title is withing 50 characters.
    char* Title = (char*)lParam; 
    // Get the title name of the messagebox window 
    GetWindowText(hwnd, WndName, 50); 
    // Find the message box dynamically within the code
    if(strcmp(WndName, Title) == 0)
    // Do whatever you want to the MessageBox
     //got the messagebox, now sleep for the time you like
     Sleep(1000); //1 sec sleep
    //Now close the message box
     PostMessage(hwnd, WM_CLOSE, 0, 0); 
    // Return FALSE to end search further.
    return FALSE;
    // Should return TRUE to continue
    return TRUE;

    Open in new window

    LVL 69

    Expert Comment

    by:Éric Moreau

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
    A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now