Finding the height of windows taskbar

16 visualizaciones (últimos 30 días)
IISc geetha
IISc geetha el 21 de Nov. de 2012
Respondida: Jan el 24 de Mzo. de 2021
Dear all, I want to place my figure above the location of the taskbar. The height of the taskbar varies according to screen size..Can somebody tell me how to find the height of the windows taskbar in pixels using Matlab.
Yours faithfully, Geetha

Respuestas (3)

Ralph Coleman
Ralph Coleman el 7 de Oct. de 2020
Editada: Ralph Coleman el 7 de Oct. de 2020
Temporarily maximizing a window is slow, and the Position property is not updated until rendering has completed.
Fortunately, if you do not mind using Java commands in your MATLAB script, there is a much more elegant way to find the screen size and the space occupied by the taskbar of your main display:
toolkit = java.awt.Toolkit.getDefaultToolkit();
scr_size = toolkit.getScreenSize();
fprintf('Screen size is: %d x %d\n', scr_size.width, scr_size.height)
jframe = javax.swing.JFrame;
insets = toolkit.getScreenInsets(jframe.getGraphicsConfiguration());
fprintf('Windows task bar height is: %d\n', insets.bottom)
Note that the other properties of "insets" can be used if the taskbar is not located in the usual place at the bottom.
scr_size = get(0,'ScreenSize');
titleBarHeight = 31;
scr_size = scr_size + ...
[insets.left, insets.bottom, -insets.left-insets.right, -titleBarHeight-insets.bottom-insets.top];
uifigure('Position', scr_size);
This example code will create a figure which fills the available space (without being maximized), independently of the position of the taskbar.
To avoid hard-coding the height of the title bar (31 pixels), you could use the following code, but there must exist a better way I am sure to retrieve this value, which does not depend on MATLAB but on the operating system.
fh = figure('Menu','none','ToolBar','none','Visible','off');
titleBarHeight = fh.OuterPosition(4) - fh.InnerPosition(4) + fh.OuterPosition(2) - fh.InnerPosition(2);
delete(fh)

Matt Fig
Matt Fig el 21 de Nov. de 2012
Here is how to figure it out. First make a figure then maximize it, then look at its position.
>> figure % maximize this figure
>> P2 = get(gcf,'pos');
>> P2(2) % The taskbar height.
ans =
49
  2 comentarios
Rik
Rik el 16 de Nov. de 2017
This is not true for all setups. Some setups have the taskbar at a side, or even the top. You will have to use the screensize as well ( get(0,'screensize')), which might cause problems with a dual monitor setup.
Would there be another way? Because I would like to use this in my script that maximizes a figure. (this would be used when using the jFrame or the alt-space x hotkey don't work)
Daniel Charles
Daniel Charles el 1 de Mayo de 2019
I like your idea of maximing a figure to find the usable area of the screen. Perhaps a more complete approach would look something like this:
h = figure('Units','pixels'); % open a figure, save the handles to a variable
h.WindowState = 'maximized'; % maximize the figure window
h.OuterPosition % will give you [x-location, y-location, width, height] relative to the lower lefthand corner of the screen
You can get the position(s) and size(s) of the monitor(s) using:
r = groot; % graphics root object
r.MonitorPositions % will give you [x-location, y-location, width, height] for each monitor in rows
Then you can do the math to figure out which screen the figure is on, if the taskbar is on that screen, and, if so, where.

Iniciar sesión para comentar.


Jan
Jan el 24 de Mzo. de 2021
You can move the taskbar to the side and to the top, hide it dynamically and change the size. The static determination of the height is not reliable.
You can use FEX: WindowAPI to determine the sizes of the monitors with and without task bar.

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by