Simple Problem - Message Box Function

15 ビュー (過去 30 日間)
Josh
Josh 2011 年 5 月 4 日
I have no experience with GUI programing in Matlab. I've written a very simple callback function to display some text when a message box is closed. The text never shows, so I think the callback function is not being called. Can you please take a look and tell me what I'm doing wrong?
Cheers, Josh
function messageBox
h1=msgbox('Message Display','','none','non-modal');
set(h1,'CloseRequestFcn',@closeMsg);
function closeMsg(src,eventdata)
disp('working')
end
waitfor(h1)
end

採用された回答

Matt Fig
Matt Fig 2011 年 5 月 4 日
function messageBox
h1=msgbox('Message Display','','none','non-modal');
set(h1,'Deletefcn',@closeMsg);
function closeMsg(src,eventdata)
disp('working')
end
end
If you look at the code for MSGBOX, you will see that pressing the button calls DELETE, which does not use the closerequestfcn. You can see this in the doc for CLOSE (but not in the doc for DELETE?).
  3 件のコメント
Matt Tearle
Matt Tearle 2011 年 5 月 4 日
BTW, notice that if you click the "x" close button on the window (top right corner), your code actually works. *That* is calling the CloseRequestFcn callback.
Matt Fig
Matt Fig 2011 年 5 月 4 日
*That* is calling the CloseRequestFcn callback.
Not quite like the OP is imagining, I would guess.
(Try it out...)

サインインしてコメントする。

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2011 年 5 月 4 日
You're modifying the closerequestfcn not the callback function for when it's pushed. If you click on the x like you're trying to exit the message box and then click on the okay button it will display 'working'.
  3 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 4 日
But not if you click the X in the corner! If you click the X in the corner it does call the closerequestfcn and once the waitfor() is taken care of by deleting (by clicking the okay button) it will execute the closerequestfcn.
Matt Fig
Matt Fig 2011 年 5 月 4 日
True enough, see my comment above on my answer. BTW, I was commenting (on your answer) on your previously posted code, not on your newer explanation, which is perfectly fine.

サインインしてコメントする。


Josh
Josh 2011 年 5 月 5 日
I now understand.
Thank you all for your thorough answers.

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by