Create non-visible message dialog box

조회 수: 5 (최근 30일)
Andrés Aguilar
Andrés Aguilar . 2023년 1월 31일
편집: Andrés Aguilar . 2023년 2월 2일
I am coding part of a project (old enough to be based on GUIDE) and I need to present the user with some message dialog boxes.
These dialogs use custom icons and change depending on a sensor readout which is updated continuously inside a while loop until the user presses OK in one of the dialogs.
I already tried two aproaches:
1- Creating a single dialog, store the figure object and then updating its properties to change the icon, the string and some others.
2 -Creating different dialogs, storing them and then changing their visibility rather than updating some properties.
Neither of these satisfied me completely because in aproach #1, when updating properties (specially the icon) the result (particularly in deployed mode) takes rather long to update and results confusing to users and aesthetically sub-optimal.
Approach #2 instead is faster in changing from one dialog to another (with icon and strings already setup) as the sensor readout changes but when I create every dialog (four of them) they come into focus and are displayed briefly (longer if isdeployed is true) before setting Visible = 'off' (in the very next line) to all but one and then setting Visible = 'on to the corresponding dialog as the readout of the sensor changes. This is better but still not optimal.
So, my question is:
Is there an elegant way of creating a message dialog box that has is Visible property set to 'off'? I noticed the msgbox.m file sets this property to 'on' on line 390. It would be nice to have the ability to specify this property during creation.
By elegant, I mean pure matlab, because this project is going to be run in deployed mode and developed and maintained by different people so using third party solutions is not the best option for me.
I really appreciate your time and help!

답변 (1개)

Bora Eryilmaz
Bora Eryilmaz 2023년 1월 31일
편집: Bora Eryilmaz 님. 2023년 1월 31일
One option is to not create all four dialog at once. Just create the dialog that needs to be visible at the time and store its handle for later use. This way, you will eventually create all four dialogs, but they will be first created when needed and become visible at the time. You could implement a logic like this:
function test()
persistent dlg1
persistent dlg2
persistent dlg3
persistent dlg4;
dialog_number = 1; % Put your logic here to decide which dialog is needed
switch dialog_number
case 1
if isempty(dlg1)
% Create the dialog 1 here
dlg1 = ...
dlg1.Visible = 'on'
case 2
% Repeat for dlg2
case 3
% Repeat for dlg3
case 4
% Repeat for dlg4
  댓글 수: 1
Andrés Aguilar
Andrés Aguilar 2023년 2월 2일
Bora, thank you very much for your answer. This would indeed be better as it would only take longer the first time the dialogs need to be shown.
I forgot to explain that this would go inside a while loop, it would look something like this:
while true
dialog_number = MyLogic(args);
switch dialog_number
case 1
case 2
if ~isempty(dlg1)
dlg1.Visible = 'off'
if isempty(dlg2)
% Create the dialog 2 here
dlg2 = msgbox('Hello World')
if ~isempty(dlg3)
dlg3.Visible = 'off'
if ~isempty(dlg4)
dlg4.Visible = 'off'
case 3
case 4

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


Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기




Community Treasure Hunt

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

Start Hunting!

Translated by