WINDOWAPI - Set window properties using the Windows API
There are a lot of functions in the FEX to set the figure properties, e.g. maximized, minimized, always-on-top, level of transparency (using Java).
This submission adds some new features:
1. Maximize a window with or without visible taskbar or menu bar.
2. Set transparency level of figure and stencil-color: pixels of a this color are 100% transparent.
3. Placing figures on multi-monitor setups.
4. Clip region: draw only pixles inside a specified rectangle (e.g. splash screen).
5. Lock cursor: Especially for games it can be useful to keep the mouse cursor in a specified rectangle.
WindowAPI(FigH, Command)
INPUT:
FigH: Matlab's figure handle or Windows HWND
Command:
TopMost: Window is topmost even if the focus is lost
NoTopMost: Disable the topmost state
Front: Move window on toptemporarily
Minimize: Minimize the window
Restore: Restore to former size
Maximize: Full screen, taskbar and menubar visible
XMax, YMax: Maximize figure horizontally or vertically only
Position: Set inner figure position to 'work' (taskbar visible), 'full' (taskbar hidden),
or [X,Y,Width,Height].
Monitor index can be specified also
OuterPosition: As Position, but with figure border and titlebar
Flash: Short flashing
Alpha: Set the figure's transparency between 0.0 and 1.0.
4th input [R,G,B]: Pixels with this color are 100% transparent in addition
Opaque: Release memory needed for alpha blending
Clip: Draw only pixels inside a rectangle
ToScreen: Move figure completely to nearest monitor
SetFocus: Gain keyboard focus to figure (figure(FigH) is buggy)
LockCursor: Limit the cursor motion to a rectangle
SetFocus: Activate figure
Enable: Enable or disable all GUI elements
Hide, Show: Hide the window without changing its Os handle
Button: Set visibility of Max, Min, Close buttons in the window border
Reply = WindowAPI(FigureHandle, Command)
GetStatus: Replies 'maximized', 'minimized' or 'restored'.
GetHWnd: Reply the Windows handle of the figure.
Position/OuterPosition: If used with 2 inputs, the position relative to current monitor and the monitor index is replied.
Monitor: Get index and position of monitor.
NOTES:
This function calls Windows-API functions => No Linux, no MacOS - sorry.
The function is written in C and must be compiled before using by the mex command. See WindowAPI.c for instructions.
The automatic compilation creates a Mex function for the running Matlab version.
Do not run a Mex compiled for <= R2014b in a higher Matlab version and vice-versa.
EXAMPLES:
Maximize the current figure:
WindowAPI(gcf, 'maximize')
A semi-transparent figure with through-looking background:
FigH = figure('Color', ones(1,3));
plot(1:10);
WindowAPI(FigH, 'Alpha', 0.5, [255,255,255]);
Draw a button without surrounding figure ("splash button"):
FigH = figure;
ButtonH = uicontrol('Style', 'PushButton', 'String', 'Bye', ...
'Units', 'pixels', 'Callback', 'delete(gcbf)');
WindowAPI(FigH, 'Clip', get(ButtonH, 'Position'));
Tested: Matlab 6.5, R2015b/32&64, R2016b, R2018b, MSVC, BCC
See also:
ShowWindow, Matthew Simoneau:
Window Manipulation, Phil Goddard:
api_showwindow, Mihai Moldovan:
maxfig, Mihai Moldovan:
setFigTransparency, Yair Altman: