4.0

4.0 | 8 ratings Rate this file 20 Downloads (last 30 days) File Size: 3.83 KB File ID: #8642

Figure Window Always on Top

by John Anderson

 

04 Oct 2005 (Updated 14 Dec 2005)

Avoid obscuring figure windows by ensuring they always remain on top.

Editor's Notes:

This file was a File Exchange Pick of the Week

| Watch this File

File Information
Description

My first attempt at a mex file making a simple call to the "SetWindowPos" function in the user32 library. This allows users to keep MATLAB figures on top, floating above all other windows even when focus is not on the target window.

Example ...

figure(1);
winontop('figure 1');

Tested on MATLAB Version 7.0.4.365 (R14) Service Pack 2 running under Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 2)

MATLAB release MATLAB 7.1.0 (R14SP3)
Other requirements note : this version is compiled under matlab 7.1.0 producing a mexw32 file, see http://www.mathworks.com/access/helpdesk/help/techdoc/rn/r14sp3_external_upgrade.html
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (9)
07 Oct 2005 Robert Bemis

John, this is wonderful.
Thank you!

20 Oct 2005 Bogdan Nuna

Very usefull

11 Dec 2005 Ryan Ollos

Very nice. The only thing that seems a bit confusing is the arguement 'figure 1', and i'm not sure why it was not made to just be an integer. The following apparently works:
hf = figure;
winontop(['figure' hf]);

17 Mar 2006 Russell Wyeth

Very useful. Could be even better if it could handle non-standard figure names. I was trying to use it with a custom gui with the figure name 'review', and it didn't work until I changed the name to 'Figure 1'

09 Jun 2006 Valentin Kuklin

Very useful, thanks a lot.

21 Nov 2007 Andrea Tagliasacchi

Would be nice to see a multiplatform version.
As a matter of fact, they should include a stay on top command as figure property directly.

26 May 2010 Joseph Burgel

Tried the example given above in:
MATLAB Version 7.5.0.342 (R2007b) windows XP and got:
figure(1);
winontop('figure 1');
??? Error using ==> winontop
First input argument must be a figure handle

14 Sep 2010 Jesse

A better way is to use Actual Title Buttons in Windows!

http://www.actualtools.com/titlebuttons/download/

works for all windows and is free... :)

07 Mar 2011 Eckhard Lehmann

Great way to make windows always visible! I wish this was built into core MATLAB and available on other platforms too.

I've created a small patch to the file that allows to use other window names than "Figure X", i.e. for GUIDE windows or named figures. The original Author might want to incorporate it into his version:

14c14,15
< char *windowName, n = 1;
---
> char *windowName, *ntSwitch, n = 1;
> mxArray *windowNameProp, *numberTitleProp; /* for getting the window name */
26,27d26
< windowName = mxCalloc(1, sizeof(figureHandle)+8);
< sprintf(windowName, "Figure %d", figureHandle);
30c29
< if( mexGet(figureHandle, "Visible") == NULL )
---
> if( mexGet(figureHandle, "Visible") == NULL ) {
32a32,48
> }
>
> windowNameProp = mexGet(figureHandle, "Name");
> windowName = mxArrayToString(windowNameProp);
>
> numberTitleProp = mexGet(figureHandle, "NumberTitle");
> ntSwitch = mxArrayToString(numberTitleProp);
> if (strcmp(ntSwitch, "on") == 0) {
> if (strlen(windowName) == 0) {
> windowName = mxCalloc(1, sizeof(figureHandle)+8);
> sprintf(windowName, "Figure %d", figureHandle);
> } else {
> char *wBuf = windowName;
> windowName = mxCalloc(1, sizeof(figureHandle)+10+strlen(windowName));
> sprintf(windowName, "Figure %d: %s", figureHandle, wBuf);
> }
> }

Please login to add a comment or rating.
Updates
14 Dec 2005

A couple of improvements have been made thanks to Ryan J Ollos. You are now able to toggle the winontop state and the position of the window is left unchanged during operation (rather annoying feature of previous version)

Tag Activity for this File
Tag Applied By Date/Time
annotation John Anderson 22 Oct 2008 08:01:52
customization John Anderson 22 Oct 2008 08:01:52
window on top John Anderson 22 Oct 2008 08:01:52
mex John Anderson 22 Oct 2008 08:01:52
floating John Anderson 22 Oct 2008 08:01:52
graphics John Anderson 22 Oct 2008 08:01:52
plot John Anderson 22 Oct 2008 08:01:52
plot annotation John Anderson 22 Oct 2008 08:01:52
always on top Robert Bemis 24 Mar 2009 13:34:13
always on top Sheng 24 Sep 2010 20:44:26
always on top Markus Leuthold 01 Dec 2010 05:44:28
always on top Eckhard Lehmann 25 Oct 2011 03:27:34
always on top David 28 Nov 2011 08:53:40

Contact us at files@mathworks.com