标题:设置工具栏出问题?
只看楼主
此在与世界
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-6-28
 问题点数:0 回复次数:4 
设置工具栏出问题?

X1=imread('打开.bmp');
X2=imread('保存.bmp');
X3=imread('打印.bmp');
X4=imread('放大.bmp');
X5=imread('undo.bmp');
X6=imread('redo.bmp');
% 建立工具栏
uipushtool('Separator','on','TooltipString','打开','ClickedCallback',...
@open_Callback,'CData',X1);
uipushtool('Separator','on','TooltipString','保存','ClickedCallback',...
@save_Callback,'CData',X2);
uipushtool('Separator','on','TooltipString','打印','ClickedCallback',...
'printdlg','CData',X3);
uipushtool('Separator','on','TooltipString','放大','ClickedCallback',...
@image_zoom_Callback,'CData',X4);
uipushtool('Separator','on','TooltipString','撤消','ClickedCallback',...
@remove_Callback,'CData',X5);
uipushtool('Separator','on','TooltipString','恢复','ClickedCallback',...
@resume_Callback,'CData',X6);

创建工具栏成功,但是只有open能正常使用,其它的都提示

?? Input argument "handles" is undefined.

??? Error while evaluating uipushtool ClickedCallback.

这是为什么,请指教,open_Callback里也用到handles!

搜索更多相关主题的帖子: 工具栏 bmp imread Separator Callback 
2007-10-20 09:22
zhangenter
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:390
专家分:0
注 册:2006-6-5
得分:0 

open_Callback回调函数里应该是没有用到handles变量,只是函数定义里有handles输入参数吧,
如果不是的话最好多贴点代码上来


OldHandle = findobj( \'Name\', \'悲伤\' ) ;if ~isempty(OldHandle),delete(OldHandle) ;end for Time = \'现在\':\'每一天\':\'永远\',set( gco, \'心情\', \'快乐\');end % 这段代码为你天天快乐而存在
2007-10-27 15:06
此在与世界
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-6-28
得分:0 

function varargout = Myprogram1(varargin)
% MYPROGRAM1 M-file for Myprogram1.fig
% MYPROGRAM1, by itself, creates a new MYPROGRAM1 or raises the existing
% singleton*.
%
% H = MYPROGRAM1 returns the handle to a new MYPROGRAM1 or the handle to
% the existing singleton*.
%
% MYPROGRAM1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MYPROGRAM1.M with the given input arguments.
%
% MYPROGRAM1('Property','Value',...) creates a new MYPROGRAM1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Myprogram1_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Myprogram1_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help Myprogram1

% Last Modified by GUIDE v2.5 17-Oct-2007 09:50:07

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Myprogram1_OpeningFcn, ...
'gui_OutputFcn', @Myprogram1_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before Myprogram1 is made visible.
function Myprogram1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Myprogram1 (see VARARGIN)

% Choose default command line output for Myprogram1
handles.output = hObject;

% 读取工具栏图象数据
X1=imread('打开.bmp');
X2=imread('保存.bmp');
X3=imread('打印.bmp');
X4=imread('放大.bmp');
X5=imread('undo.bmp');
X6=imread('redo.bmp');
% 建立工具栏
htb=uitoolbar;
uipushtool(htb,'Separator','on','TooltipString','打开','ClickedCallback',...
@open_Callback,'CData',X1);
uipushtool(htb,'Separator','on','TooltipString','保存','ClickedCallback',...
@save_Callback,'CData',X2);
uipushtool(htb,'Separator','on','TooltipString','打印','ClickedCallback',...
'printdlg','CData',X3);
uipushtool(htb,'Separator','on','TooltipString','放大','ClickedCallback',...
@image_zoom_Callback,'CData',X4);
uipushtool(htb,'Separator','on','TooltipString','撤消','ClickedCallback',...
@remove_Callback,'CData',X5);
uipushtool(htb,'Separator','on','TooltipString','恢复','ClickedCallback',...
@resume_Callback,'CData',X6);
h=findobj(hObject,'type','figure');
% 设置发布的GUI的属性
set(h,'resize','on');
set(h,'CloseRequestFcn','quest');
set(h,'handlevisibility','off');
set(h,'HitTest','off');

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Myprogram1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.

function varargout = Myprogram1_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;

% --------------------------------------------------------------------
% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname]=uigetfile({'*.jpg','image file(*.jpg)';'*.bmp','image file(*.bmp)';...
'*.tif','image file(*.tif)';'*.hdf','image file(*.hdf)';...
'*.png','image file(*.hdf)';'*.xwd','image file(*.xwd)'},...
'Open Image File');
if(isequal([filename,pathname],[0,0]))
return;
end
cd(pathname);
data=imread(filename);
hfigure=figure;
imshow(data);
set(hfigure,'resize','on','MenuBar','none');
handles.data=data;
handles.hfigure=hfigure;
guidata(hObject,handles);

% --------------------------------------------------------------------
% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject handle to save (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename,pathname]=uiputfile({'*.jpg','image file(*.jpg)';'*.bmp','image file(*.bmp)';...
'*.tif','image file(*.tif)';'*.hdf','image file(*.hdf)';...
'*.png','image file(*.hdf)';'*.xwd','image file(*.xwd)'},...
'Save');
cd(pathname)
if isequal([filename,pathname],[0,0])
return;
end
if ~isfield(handles,'data')
return;
end
data=handles.data;
imwrite(data,filename);

2007-10-27 19:50
zhangenter
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:390
专家分:0
注 册:2006-6-5
得分:0 

handles你根本没传,当然会出错,open回调函数里没出错是因为它里面没用到handles里的值,只有给handles里的域赋值,所以不会出问题,比如
function save_Callback(hObject, eventdata, handles)你想正常使用,需要再回调函数的第一行加上这样一句
handles = guidata(hObject);就可以了


OldHandle = findobj( \'Name\', \'悲伤\' ) ;if ~isempty(OldHandle),delete(OldHandle) ;end for Time = \'现在\':\'每一天\':\'永远\',set( gco, \'心情\', \'快乐\');end % 这段代码为你天天快乐而存在
2007-10-29 21:57
此在与世界
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2007-6-28
得分:0 
终于好了,我最近折腾来折腾去,还是一塌糊涂啊。实在太感谢了!
2007-10-31 08:52



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-179214-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.352511 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved