File Exchange

image thumbnail

ShowWindow

version 1.0.0.1 (2.47 KB) by Matthew Simoneau
Change the state of a window, like minimize and maximize.

1 Download

Updated 01 Sep 2016

View License

SHOWWINDOW(NAME,STATE) changes the state of the window with a certain NAME to the specified STATE. STATE must be one of the following:
'hide', 'shownormal', 'normal', 'showminimized', 'showmaximized',
'maximize', 'shownoactivate', 'show', 'minimize', 'showminnoactive',
'showna', 'restore', 'showdefault', 'forceminimize',
'max'

Examples:

>> showwindow('MATLAB','minimize')
>> showwindow('','minimize')
>> figure(4); showwindow('Figure No. 4','maximize'); text(.5,.5,'Simoneau')

Comments and Ratings (13)

Arda Aksu

yang ??

Mike Tracy

showwindow() works well under the MS windows 32 operating system. On the initial call there is a warning:

Warning: A loader file was supplied that was built with a previous version of MATLAB that will not be supported in future versions of MATLAB.
> In loadlibrary at 438
In showwindow at 67

On subsequent calls to showwindow() everything is fine since the dll library has already been loaded.

Under MS windows 64, the showwindow() function does not work. I did some digging. The loadlibrary() function called in showwindow() can be made to work but a compiler is required.

Jeffrey Thompson

Thanks so much. Exactly what I needed.

Peter Renner

Thanks for the function. It's pretty good.

Jarod Kelly

I haven't had any troubles, though I had to add a pause as well (mine is arbitrarly set as pause(.2)).

The need for the pause is a result of WHEN you are trying to invoke the function. For instance, I'm using it in a GUI that opens and closes other GUIs, so pausing that split second allows the machine to recognize the other figure as being available.

fan jun

what is the problem??

>> showwindow('','minimize')
??? method was not found

Error in ==> D:\Try\MATLAB6p5\toolbox\matlab\general\calllib.dll
Error in ==> D:\Try\MATLAB6p5\work\showwindow.m
On line 92 ==> h = calllib(mfilename,'FindWindowA',[],name);

>> figure(4);drawnow,showwindow('Figure 4','maximize');text(.5,.5,'Simoneau')
??? method was not found

Error in ==> D:\Try\MATLAB6p5\toolbox\matlab\general\calllib.dll
Error in ==> D:\Try\MATLAB6p5\work\showwindow.m
On line 92 ==> h = calllib(mfilename,'FindWindowA',[],name);

>>

Tim Farajian

Exactly the functionality I was looking for. In R14 and later, rather than using the example:

>> figure(4); showwindow('Figure No. 4','maximize'); text(.5,.5,'Simoneau')

Use:

>> figure(4);drawnow,showwindow('Figure 4','maximize');text(.5,.5,'Simoneau')

The "Figure No. 4" name is useful for Native MATLAB figures (used in R13SP1 and earlier) while "Figure 4" should be used for Java figures (used by default in R14 and later).

Also, there is often the need to use the DRAWNOW command between creating the figure and calling ShowWindow.

If you want to be able to obtain the name of the figure from the figure handle, use the following algorithm:

namestr = get(hFig,'name');
if strcmp(get(hFig,'numbertitle'),'on')
numt = ['Figure ' num2str(hFig)];
if ~isempty(namestr)
name = [numt ': ' namestr];
else
name = numt;
end
else
name = namestr;
end

This seems to work in all cases (for R14 and later) except when "NumberTitle" is "off" and the "Name" property is empty.

Thanks for the function Matt.

Samir Shah

In order to use this successfully in code, I had to put a pause(1) statement before this call. I don't know why, but otherwise it didn't work.

Prasanna Kolluru

This is working fine in Matlab Environment but its giving problem when compiling...
Warning: "c:\programs\matlab13\toolbox\matlab\general\private\plibisloaded.p" is a Mex or P-file being referenced from "c:\programs\matlab13\toolbox\matlab\general\libisloaded.m".
NOTE: A link error will be produced if a call to this function is made from stand-alone code.
Warning: No M-function source available for "general/private/plibisloaded", assuming
function [varargout] = general/private/plibisloaded(varargin)

NOTE: This will produce a link error in stand-alone code
unless you provide a hand-written definition for this function.
Warning: No M-function source available for "system", assuming
function [varargout] = system(varargin)

NOTE: This will produce a link error in stand-alone code
unless you provide a hand-written definition for this function.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\loadlibrary.m Line: 120 Column: 20
The "which" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\loadlibrary.m Line: 170 Column: 5
The "rehash" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\loadlibrary.m Line: 178 Column: 16
The "methods" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\loadlibrary.m Line: 194 Column: 10
The "which" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\perl.m Line: 35 Column: 17
The "which" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\perl.m Line: 60 Column: 22
The second output argument from the "dos" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\perl.m Line: 63 Column: 23
The second output argument from the "unix" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
Warning: File: c:\programs\matlab13\toolbox\matlab\general\perl.m Line: 66 Column: 24
The second output argument from the "unix" function is only available in MEX mode. A run-time error will occur if this code is executed in stand-alone mode.
libisloaded.obj .text: undefined reference to '_mlfNGeneral_private_plibisloaded'
loadlibrary.obj .text: undefined reference to '_mlfNSystem'

MBUILD.BAT: Error: Link of 'iodata.exe' failed.

??? Error using ==> mbuild
Unable to complete successfully

??? Error: An error occurred while shelling out to mbuild (error code = 1).
Unable to build executable (specify the -v option for more information).

Error in ==> C:\Programs\Matlab13\toolbox\compiler\mcc.dll

dhananjai kumar

K Klarqvist

Excellent tool. Does exactly what I wanted.

Minor improvement
I would like it to take a figure handle instead of the window title but it easy to work around that.

Greg Nichols

Works great! Thanks, Matthew.
Two things thar might be helpful:
After installing Generic DLL Calling, I found it necessary to say 'rehash toolboxcache' to get Matlab to update the search path.
This command will maximize tha figure that was drawn last:
showwindow(['Figure No. ' num2str(gcf)],'maximize');

Updates

1.0.0.1

Updated license

1.0.0.0

Fix M-lint warning.

Update installation instructions.

Update to match new API.

MATLAB Release Compatibility
Created with R13
Compatible with any release
Platform Compatibility
Windows macOS Linux
Acknowledgements

Inspired: closewindow