问题描述
大家好..
在WIN32中,我创建了这样的消息框:
MessageBox(NULL,初始化软件",初始化",MB_OK);
我的问题是:如何在几秒钟后自动关闭此消息框,而无需按确定"按钮..
请给我建议.
在此先谢谢您..
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..
推荐答案
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);
:
}
但是,除非您有效地处理同步问题,否则这段代码肯定会崩溃.
现在可以真正解决您的问题,最好使用无模态对话框显示进度消息
http://www.winprog.org/tutorial/modeless_dialogs.html [ ^ ]
并在一段时间或您的软件初始化完成后将消息WM_CLOSE发送到此对话框
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
这篇关于要在几秒钟后自动关闭消息框,或者如何将计时器添加到消息框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!