Editor's Note: This file was a File Exchange Pick of the Week
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)
John Anderson (2021). Figure Window Always on Top (https://www.mathworks.com/matlabcentral/fileexchange/8642-figure-window-always-on-top), MATLAB Central File Exchange. Retrieved .
Inspired: WinOnTop
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Create scripts with code, output, and formatted text in a single executable document.
I've just uploaded another submission to do the same job, but based on java calls. (See "Acknowledgements" section above.)
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);
> }
> }
A better way is to use Actual Title Buttons in Windows!
http://www.actualtools.com/titlebuttons/download/
works for all windows and is free... :)
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
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.
Very useful, thanks a lot.
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'
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]);
Very usefull
John, this is wonderful.
Thank you!