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);