How can I pass the handles structure to 'WindowButtonUpFcn' associated callback?

4 ビュー (過去 30 日間)
MRR
MRR 2012 年 8 月 13 日
コメント済み: Walter Roberson 2018 年 4 月 23 日
Hi,
I am currently developing a Guide. Within callbacks functions created by the Guide itself I have no problem to get the handles inside them, i.e.:
function listbox1_Callback(hObject, eventdata, handles)
% here I have access to handles structure, I can modify anything and can save %the
% modifications by doing "guidata(hObject, handles)"
However, I have associated a set of functions for mouse operations:
set(gcf,'WindowButtonMotionFcn',@mouse_mov);
set(gcf,'WindowButtonDownFcn',@mouse_down);
set(gcf,'WindowButtonUpFcn',@mouse_up);
How could I pass to them the handles structure automatically?. For example, this does not work (and however works in any callback created by Guide, i.e, any function associated with a Guide object).
function mouse_up(hObject,eventdata,handles)
%I dont get handles here structure here
My temporal and poor solution is to save the handles structure by doing set(0,'userdata',handles) and handles = get(0,'UserData') within the aforementioned functions, but I would simply like to use guidata(hObject, handles) as I do for all the callback functions associated with each guide object.
Regards,
-M

採用された回答

Walter Roberson
Walter Roberson 2012 年 8 月 13 日
function mouse_up(hObject,eventdata)
handles = guidata( ancestor(hObject, 'figure') );
  3 件のコメント
mehran daemian
mehran daemian 2018 年 4 月 22 日
Hello. I used your solution by it returns zero , I think problem is 'figure'. I want to get handles struct in an external function like close request function and can not! Do you have a solution?
Walter Roberson
Walter Roberson 2018 年 4 月 23 日

It turns out that guidata() automatically chases ancestor(), so you can just do

function mouse_up(hObject, eventdat)
  handles = guidata(hObject);

This will be empty in any CreateFcn that is run before the OpenFcn is run (that is, it will be empty for all CreateFcn for objects created out of the .fig file because you pre-created them in GUIDE.)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by