Code covered by the BSD License  

Highlights from
ShowWindow

4.25

4.2 | 12 ratings Rate this file 11 Downloads (last 30 days) File Size: 2.47 KB File ID: #3407

ShowWindow

by Matthew Simoneau

 

07 May 2003 (Updated 09 May 2007)

Change the state of a window, like minimize and maximize.

| Watch this File

File Information
Description

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

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Window Manipulation
This submission has inspired the following:
closewindow

MATLAB release MATLAB 6.5 (R13)
Other requirements This requires MATLAB's generic DLL interface, available in R13sp1 (MATLAB 6.5.1) and later. For R13, you must first follow these instructions: http://www.mathworks.com/support/solutions/data/33513.shtml
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (12)
17 Aug 2003 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');

23 Jan 2004 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.

26 Feb 2004 dhananjai kumar  
12 May 2004 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

20 Oct 2004 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.

12 May 2006 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.

07 Jun 2006 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);

>>

24 Jul 2006 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.

13 Dec 2006 Peter Renner

Thanks for the function. It's pretty good.

30 Aug 2007 Jeffrey Thompson

Thanks so much. Exactly what I needed.

11 Mar 2010 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.

29 Nov 2010 yang ??  
Please login to add a comment or rating.
Updates
16 Dec 2003

Update to match new API.

28 May 2004

Update installation instructions.

09 May 2007

Fix M-lint warning.

Tag Activity for this File
Tag Applied By Date/Time
gui tools Matthew Simoneau 22 Oct 2008 07:01:23
example Matthew Simoneau 22 Oct 2008 07:01:23
show Matthew Simoneau 22 Oct 2008 07:01:23
gui Matthew Simoneau 22 Oct 2008 07:01:23
window Matthew Simoneau 22 Oct 2008 07:01:23
state Matthew Simoneau 22 Oct 2008 07:01:24
minimize Matthew Simoneau 23 Oct 2008 22:09:32
maximize Matthew Simoneau 23 Oct 2008 22:09:36
restore Matthew Simoneau 23 Oct 2008 22:09:45
windows Matthew Simoneau 23 Oct 2008 22:09:51
manipulation Matthew Simoneau 23 Oct 2008 22:10:04
generic dll Matthew Simoneau 23 Oct 2008 22:10:29
generic dll interface Matthew Simoneau 23 Oct 2008 22:10:29
example ana martinez 28 May 2010 07:31:49

Contact us at files@mathworks.com