close a message box thru coding

조회 수: 119 (최근 30일)
Elysi Cochin
Elysi Cochin 2012년 11월 8일
댓글: Nick Patterson 2023년 3월 9일
how to close a message box displayed thru coding?... In my pjt to process an image it is taking time... so i displayed a message box saying "please wait'... now when the output is being displayed i wanted to close that message box automatically and then display the image.... what shud i do?

채택된 답변

Daniel Shub
Daniel Shub 2012년 11월 8일
You could do something like
h = msgbox('please wait');
n = 0;
while rand > 1e-9; n = n+1; end;
delete(h);
Where the while loop is whatever processing that you want to do that takes a long time.

추가 답변 (2개)

Image Analyst
Image Analyst 2012년 11월 8일
I'd suggest a method that is robust enough to handle if the user clicked the OK button on your message box without throwing an exception:
handleToMessageBox = msgbox('Please wait...');
% Do stuff that takes a long time.....
if exist('handleToMessageBox', 'var')
delete(handleToMessageBox);
clear('handleToMessageBox');
end
Otherwise if the user clicked the OK button, as users tend to do, then when it hits your delete() function, the handle is already gone and it will throw an error (I tried it). My way avoids that error by not trying to delete the handle if it doesn't exist anymore.
  댓글 수: 2
Daniel Shub
Daniel Shub 2012년 11월 8일
Even better might be waitbar
Elysi Cochin
Elysi Cochin 2012년 11월 19일
thanks all

댓글을 달려면 로그인하십시오.


Xingwang Yong
Xingwang Yong 2022년 11월 9일
m = findall(0,'type','figure','tag','Msgbox_ ');
delete(m);
  댓글 수: 1
Nick Patterson
Nick Patterson 2023년 3월 9일
This works way better for my needs. I have non-modal message boxes that I need to display to the user, and I don't want them to close unless the user acknowledges them.
However, for my unit tests, I want to close them all programmatically. I just needed to slighly modify the above solution to work for me, where I find all figures, and then delete those whos tag contains "Msgbox" (which is necessary since there are multiple tags, but they all start with "Msgbox_").
% Close all msgbox instance
hv_figure_all = findall(0, 'Type', 'Figure');
delete( hv_figure_all( arrayfun(@(h) contains(h.Tag, 'Msgbox'), hv_figure_all) ) )

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Dialog Boxes에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by