Finding the height of windows taskbar

16 次查看(过去 30 天)
IISc geetha
IISc geetha 2012-11-21
回答: Jan 2021-3-24
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

回答(3 个)

Ralph Coleman
Ralph Coleman 2020-10-7
编辑:Ralph Coleman 2020-10-7
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 2012-11-21
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 个评论
Rik
Rik 2017-11-16
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 2019-5-1
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.

请先登录,再进行评论。


Jan
Jan 2021-3-24
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.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by