James - it isn't clear where in your clickFcn you are trying to access the handles structure, unless you are assuming that it will be there due to the function signature of
function clickFcn(hObject, eventdata, handles)
In the above, handles will always be an empty matrix because you are not explicitly passing it when you assign the callback as
set(gcf, ...
'WindowButtonDownFcn', @clickFcn, ...
By default, there will only be two input parameters for clickFcn: hObject and eventdata. If you want to pass a third (or fourth or fifth) parameter, you would need to modify the above to
set(gcf, ...
'WindowButtonDownFcn', {@clickFcn, param3},..
where param3 is a variable that you have defined previously. However, if you were to try and pass handles in as the third parameter, it would only be a copy of handles at the time that you assigned the callback. So if handles changes over time (due to being updated in another callback) your clickFcn will not see these changes because it is using an out-dated copy of handles.
To get around this, you can use the guidata function to get the most recent handles structure. So we will leave the callback assignment as set(hObject, ...
'WindowButtonDownFcn', @clickFcn, ...
'WindowButtonUpFcn', @unclickFcn);
(Note that I changed gcf to hObject. These should be identical since you are doing the above in the _OpeningFcn of your GUI.) In the callback, we will use hObject to get handles
function clickFcn(hObject, eventdata)
handles = guidata(hObject);
Try the above and see what happens!
Best Answer