Disabling Ctrl+C in a GUI

Hello everybody,
is there a way to disable Ctrl+C when no edit text or similar has focus, to prevent it crashing a GUI?
Thanks

 採用された回答

Walter Roberson
Walter Roberson 2012 年 1 月 3 日

0 投票

No, there is not. control-c cannot be disabled in MATLAB.

4 件のコメント

Michele
Michele 2012 年 1 月 3 日
Thank you for the answer Walter.
Do you think there is really no way to work around this? Perhaps accessing the figure's Java handle and overwriting some callbacks?
(by the way, I'm definitely not a Java expert, so I would hardly have any clue of how to do that).
Walter Roberson
Walter Roberson 2012 年 1 月 3 日
MathWorks has always said that control-C cannot be overridden. If there is a hack around that, I do not know what it is.
You might be able to use onCleanup() routines in order to clean up gracefully.
Walter Roberson
Walter Roberson 2012 年 1 月 3 日
http://www.mathworks.com/matlabcentral/newsreader/view_thread/246784
"No. In older releases, Ctrl-C could be caught by TRY/CATCH; that changed a while ago. [When Ctrl-C was caught, you could get into a situation where there was no way, short of terminating the MATLAB process, to end your code.]"
That thread is still not quite authoritative with regards to compiled executables,
Unfortunate that Windows uses control-c for "paste".
Michele
Michele 2012 年 1 月 5 日
Yes, quite unfortunate, I agree.
Once again thank you for your answers.

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

その他の回答 (1 件)

Sean de Wolski
Sean de Wolski 2012 年 1 月 3 日

0 投票

Although there's no way to disable it, you can keep stuff running even if it is called using a timer to execute your tasks.
Example:
t = timer('timerfcn','disp(''hello world'')','period',2,'taskstoexecute',10,'executionmode','fixedrate');
start(t)
It is going to display hello world 10x and if you click crtl+c in the middle the remaining hello worlds will still be displayed.
And what do you mean by GUI crashing?

1 件のコメント

Michele
Michele 2012 年 1 月 3 日
Thank you Sean.
My GUI is compiled as a Windows stand-alone application; when I press Ctrl+C without an edit text or similar having focus I get a message from Windows stating that the executable has stopped working and the program closes.

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

カテゴリ

ヘルプ センター および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by