Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone..

In WIN32, I have created the Messagebox like this:

MessageBox(NULL,"Initilizing the Software","Initilization",MB_OK);

And my question is: how do i close this Messagebox after few seconds automatically, without pressing OK button..

Please suggest me..

Thanks in advance..
Posted

you can get this thing work as you expect. But it is going to be very weird method to show progress. You have to create a separte thread to handle the message box closing stuffs. Because a message box is of a modal dialog. Once invoked, without closing you can not execute next line of code. So first you have to write a thread function. In that Write the code to get the message box window handle as below and then close it
C++
UINT ThreadFun(LPVOID lpvParam)
{
    Sleep( 4000 );// Waiting untill the message box gets invoked(you can use an effective synch method also)
    HWND hWnd = FindWindow( 0, "Initilization"/*Window Title*/ );
    Sleep( 4000 );// Wait for some second
    CloseWidnow( hWnd );
}
void ShowMsg()
{
    :
    AfxBeginThread( ThreadFun, 0 );
    MessageBox(NULL,"Initilizing the Software","Initilization",MB_OK);
    :
}


But this code will for sure crash unless you handle the synchronizantion effeciently.

Now coming to a real solution to your issue, better you use a modless dialog which shows the progress message
http://www.winprog.org/tutorial/modeless_dialogs.html[^]
and send the message WM_CLOSE to this dialog after some time or once your s/w initialization is done
 
Share this answer
 
Comments
Guru_C++ 20-Apr-12 5:21am    
Sorry... Dint got :(:(
Don't use a MessageBox for this but utilise the ProgressBar[^] control for a more professional approach. You can embed it into a modal or modeless dialog or use it stand alone.
 
Share this answer
 
Comments
Guru_C++ 20-Apr-12 6:00am    
As per as ur suggestion.. i used Progress bar like this..
HWND hProgressBar = NULL;

hProgressBar = CreateWindow(PROGRESS_CLASS, NULL, WS_CHILD | WS_VISIBLE,10, 20, 150, 20, hWnd, (HMENU)10001, hInstance, NULL);

But this code Does not make use of Visual styles like marquee mode..
Please can u tell me how to use progress bar in marquee mode ..

SendMessage(hProgressBar, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
SetTimer(hWnd, 1, 1000, NULL);

SendMessage(hProgressBar, PBM_SETPOS, (WPARAM)100, 0);
Richard MacCutchan 20-Apr-12 6:06am    
Go to the link I provided above, it contains full details of all the messages and notifications on how to use this control, including marquee mode.
Guru_C++ 20-Apr-12 6:34am    
Am not getting how to use marquee style in progress bar :(
Richard MacCutchan 20-Apr-12 6:46am    
Did you look at the link I gave you? Try again here.
Guru_C++ 20-Apr-12 7:15am    
Yes i tried that link.. Only progress bar is displaying.. No marquees..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900