from example windows message handler by Ingo
windows message handler

test_getmessage(command)
%--------------------------------------------------------------------------------------------------------------
% Function:         Windows message handling example 
%
% Typ:              M-Function MATLAB
%
% Input:            command         :   'cmInit'
%                                       'cmClose'
%
% Output:          ---  
%
% Example with char:
%
%  mex_setmessage('TestMessage','test_getmessage(''Message'');',3);
%
% Example with struct:
%
%  test_struct=struct('Function','test_getmessage','Command','Message');
%  mex_setmessage('TestMessage',test_struct,3);
%
% Change:           written                                                 Revision:   01.06.2005  I.Drews
%---------------------------------------------------------------------------#----------------------------------

function test_getmessage(command)

 global MESS_HND

 if nargin==0
    command='cmInit';
    fig_title='TestMessage';
 end

 switch command
    case 'cmInit'
        if ~isempty(MESS_HND)
            error('This example does not allow multilpe program instances');
        end
        MESS_HND=InitGui(fig_title);                                        % init figure
        if mex_getmessage(fig_title)~=0                                     % init message handler
            disp 'Message Init Fehler'    
        end
    case 'cmClose'                                                          % close example
        clear global MESS_HND;
    case 'Message'                                                          % catch the message
        disp 'Message is there'    
 end

function MESS_HND=InitGui(fig_title)                                        % GUI init
    
 MESS_HND.hFig = figure('BackingStore','off', ...
                        'Name',fig_title,...
                        'NumberTitle','off',...
                        'resize','off',...
                        'Color',[0.8 0.8 0.8], ...
                        'MenuBar','none', ...
                        'Position',[120 250 160 70], ...
                        'Tag','Fig',...
                        'DeleteFcn','test_getmessage(''cmClose'');');
 drawnow;                                                                   % !! to find Figure
 

Contact us at files@mathworks.com