mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Made TaskBarLayout creation more robust
TaskBarLayout now catches exceptions recording the taskbar location and handles them properly. It will skip any screenss that it cannot access the taskbar information for. The Screen layout generator for NVIDIA, AMD and Windows have all been updated to handle having no taskbar layout information (it just assumes the taskbar is down the bottom of the screen). Hopefully fixes #114
This commit is contained in:
parent
56c2410d85
commit
3fba28087c
@ -26,8 +26,8 @@ using System.Resources;
|
||||
[assembly: Guid("e4ceaf5e-ad01-4695-b179-31168eb74c48")]
|
||||
|
||||
// Version information
|
||||
[assembly: AssemblyVersion("2.3.2.15")]
|
||||
[assembly: AssemblyFileVersion("2.3.2.15")]
|
||||
[assembly: AssemblyVersion("2.3.2.16")]
|
||||
[assembly: AssemblyFileVersion("2.3.2.16")]
|
||||
[assembly: NeutralResourcesLanguageAttribute( "en" )]
|
||||
[assembly: CLSCompliant(true)]
|
||||
|
||||
|
@ -1171,7 +1171,7 @@ namespace DisplayMagicianShared
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Guess that it is at the bottom (90% correct)
|
||||
SharedLogger.logger.Error(ex, $"ProfileItem/GetNVIDIAScreenPositions: Exception trying to get the position of the taskbar on display {targetInfo.DisplayId}");
|
||||
SharedLogger.logger.Warn(ex, $"ProfileItem/GetNVIDIAScreenPositions: Exception trying to get the position of the taskbar on display {targetInfo.DisplayId}");
|
||||
screen.TaskBarEdge = TaskBarLayout.TaskBarEdge.Bottom;
|
||||
}
|
||||
|
||||
@ -1311,7 +1311,7 @@ namespace DisplayMagicianShared
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Guess that it is at the bottom (90% correct)
|
||||
SharedLogger.logger.Error(ex, $"ProfileItem/GetNVIDIAScreenPositions: Exception trying to get the position of the taskbar on display {targetId}");
|
||||
SharedLogger.logger.Warn(ex, $"ProfileItem/GetNVIDIAScreenPositions: Exception trying to get the position of the taskbar on display {targetId}");
|
||||
screen.TaskBarEdge = TaskBarLayout.TaskBarEdge.Bottom;
|
||||
}
|
||||
|
||||
@ -1564,7 +1564,7 @@ namespace DisplayMagicianShared
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Guess that it is at the bottom (90% correct)
|
||||
SharedLogger.logger.Error(ex, $"ProfileItem/GetWindowsScreenPositions: Exception trying to get the position of the taskbar on primary display {targetId}");
|
||||
SharedLogger.logger.Warn(ex, $"ProfileItem/GetWindowsScreenPositions: Exception trying to get the position of the taskbar on primary display {targetId}");
|
||||
screen.TaskBarEdge = TaskBarLayout.TaskBarEdge.Bottom;
|
||||
}
|
||||
|
||||
@ -1579,7 +1579,7 @@ namespace DisplayMagicianShared
|
||||
catch (Exception ex)
|
||||
{
|
||||
// Guess that it is at the bottom (90% correct)
|
||||
SharedLogger.logger.Error(ex, $"ProfileItem/GetWindowsScreenPositions: Exception trying to get the position of the taskbar on display {targetId}");
|
||||
SharedLogger.logger.Warn(ex, $"ProfileItem/GetWindowsScreenPositions: Exception trying to get the position of the taskbar on display {targetId}");
|
||||
screen.TaskBarEdge = TaskBarLayout.TaskBarEdge.Bottom;
|
||||
}
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ namespace DisplayMagicianShared.Windows
|
||||
if (Registry.CurrentUser.OpenSubKey(address) != null)
|
||||
{
|
||||
MMStuckRectVerFound = true;
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: Found MMStuckRect3 registry key! {address}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: Found MMStuckRect3 registry key! {address}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -77,13 +77,13 @@ namespace DisplayMagicianShared.Windows
|
||||
if (Registry.CurrentUser.OpenSubKey(address) != null)
|
||||
{
|
||||
MMStuckRectVerFound = true;
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: Found MMStuckRect2 registry key! {address}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: Found MMStuckRect2 registry key! {address}");
|
||||
}
|
||||
else
|
||||
{
|
||||
// It's not v2 or v3, so it must be a single display
|
||||
MMStuckRectVerFound = false;
|
||||
SharedLogger.logger.Warn($"TaskBarStuckRectangle/TaskBarStuckRectangle: Couldn't find an MMStuckRect2 or MMStuckRect3 registry key! Going to test if it is a single display only.");
|
||||
SharedLogger.logger.Warn($"TaskBarLayout/TaskBarStuckRectangle: Couldn't find an MMStuckRect2 or MMStuckRect3 registry key! Going to test if it is a single display only.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -107,25 +107,25 @@ namespace DisplayMagicianShared.Windows
|
||||
// Extract the values from the binary byte field
|
||||
PopulateFieldsFromBinary();
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
|
||||
// If we get here then we're done and don't need to continue with the rest of the code.
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen.");
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarStuckRectangle/TaskBarStuckRectangle: A MMStuckRect entry was found, but the version of the field is wrong.");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/TaskBarStuckRectangle: A MMStuckRect entry was found, but the version of the field is wrong.");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: A MMStuckRect entry was NOT found. We will try to find the object in the StuckRect registry key instead");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: A MMStuckRect entry was NOT found. We will try to find the object in the StuckRect registry key instead");
|
||||
}
|
||||
|
||||
bool StuckRectVerFound = false;
|
||||
@ -135,7 +135,7 @@ namespace DisplayMagicianShared.Windows
|
||||
if (Registry.CurrentUser.OpenSubKey(address) != null)
|
||||
{
|
||||
StuckRectVerFound = true;
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: Found StuckRect3 single display registry key! {address}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: Found StuckRect3 single display registry key! {address}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -145,11 +145,11 @@ namespace DisplayMagicianShared.Windows
|
||||
if (Registry.CurrentUser.OpenSubKey(address) != null)
|
||||
{
|
||||
StuckRectVerFound = true;
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: Found StuckRect2 single display registry key! {address}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: Found StuckRect2 single display registry key! {address}");
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarStuckRectangle/TaskBarStuckRectangle: Couldn't find an single display StuckRect2 or StuckRect3 registry key! So we have to just return after doing nothing as there is nothing we can do.");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/TaskBarStuckRectangle: Couldn't find an single display StuckRect2 or StuckRect3 registry key! So we have to just return after doing nothing as there is nothing we can do.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -174,25 +174,25 @@ namespace DisplayMagicianShared.Windows
|
||||
// Extract the values from the binary byte field
|
||||
PopulateFieldsFromBinary();
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/TaskBarStuckRectangle: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/TaskBarStuckRectangle: The taskbar for {RegKeyValue} is against the {Edge} edge, is positioned at ({TaskBarLocation.X},{TaskBarLocation.Y}) and is {TaskBarLocation.Width}x{TaskBarLocation.Height} in size.");
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarStuckRectangle/TaskBarStuckRectangle: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen.");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/TaskBarStuckRectangle: Unable to get the TaskBarStuckRectangle binary settings from {regKeyValue} screen.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarStuckRectangle/TaskBarStuckRectangle: A StuckRect entry was found, but the version of the field is wrong.");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/TaskBarStuckRectangle: A StuckRect entry was found, but the version of the field is wrong.");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"TaskBarStuckRectangle/TaskBarStuckRectangle: A StuckRect entry was NOT found. This means we're unable to get the taskbar location, an unable to return a sensible TaskBarStuckRectangle object.");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/TaskBarStuckRectangle: A StuckRect entry was NOT found. This means we're unable to get the taskbar location, an unable to return a sensible TaskBarStuckRectangle object.");
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -332,7 +332,7 @@ namespace DisplayMagicianShared.Windows
|
||||
Rows = BitConverter.ToUInt32(Binary, 44);
|
||||
}
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/PopulateFieldsFromBinary: Grabbed the following settings for {RegKeyValue} from the registry: DPI = {DPI}, Edge = {Edge}, Location = ({TaskBarLocation.X},{TaskBarLocation.Y}), MinSize = {TaskBarLocation.Width}x{TaskBarLocation.Height}, Options = {Options}, Rows = {Rows}.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/PopulateFieldsFromBinary: Grabbed the following settings for {RegKeyValue} from the registry: DPI = {DPI}, Edge = {Edge}, Location = ({TaskBarLocation.X},{TaskBarLocation.Y}), MinSize = {TaskBarLocation.Width}x{TaskBarLocation.Height}, Options = {Options}, Rows = {Rows}.");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -432,7 +432,7 @@ namespace DisplayMagicianShared.Windows
|
||||
Array.Copy(bytes, 0, Binary, 44, 4);
|
||||
}
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/PopulateBinaryFromFields: Set the following settings for {RegKeyValue} into registry: DPI = {DPI}, Edge = {Edge}, Location = ({TaskBarLocation.X},{TaskBarLocation.Y}), MinSize = {TaskBarLocation.Width}x{TaskBarLocation.Height}, Options = {Options}, Rows = {Rows}.");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/PopulateBinaryFromFields: Set the following settings for {RegKeyValue} into registry: DPI = {DPI}, Edge = {Edge}, Location = ({TaskBarLocation.X},{TaskBarLocation.Y}), MinSize = {TaskBarLocation.Width}x{TaskBarLocation.Height}, Options = {Options}, Rows = {Rows}.");
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -455,12 +455,12 @@ namespace DisplayMagicianShared.Windows
|
||||
RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
{
|
||||
key.SetValue(RegKeyValue, Binary);
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/Apply: Successfully applied TaskBarStuckRectangle registry settings for the {RegKeyValue} Screen in {address}!");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/Apply: Successfully applied TaskBarStuckRectangle registry settings for the {RegKeyValue} Screen in {address}!");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SharedLogger.logger.Error(ex, $"TaskBarStuckRectangle/GetCurrent: Unable to set the {RegKeyValue} TaskBarStuckRectangle registry settings in {address} due to an exception!");
|
||||
SharedLogger.logger.Error(ex, $"TaskBarLayout/GetCurrent: Unable to set the {RegKeyValue} TaskBarStuckRectangle registry settings in {address} due to an exception!");
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -474,12 +474,12 @@ namespace DisplayMagicianShared.Windows
|
||||
RegistryKeyPermissionCheck.ReadWriteSubTree))
|
||||
{
|
||||
key.SetValue(RegKeyValue, Binary);
|
||||
SharedLogger.logger.Trace($"TaskBarStuckRectangle/WriteToRegistry: Successfully applied TaskBarStuckRectangle registry settings for the {RegKeyValue} Screen in {address}!");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/WriteToRegistry: Successfully applied TaskBarStuckRectangle registry settings for the {RegKeyValue} Screen in {address}!");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SharedLogger.logger.Error(ex, $"TaskBarStuckRectangle/WriteToRegistry: Unable to set the {RegKeyValue} TaskBarStuckRectangle registry settings in {address} due to an exception!");
|
||||
SharedLogger.logger.Error(ex, $"TaskBarLayout/WriteToRegistry: Unable to set the {RegKeyValue} TaskBarStuckRectangle registry settings in {address} due to an exception!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -513,6 +513,7 @@ namespace DisplayMagicianShared.Windows
|
||||
MONITORINFOEX monitorInfo = new MONITORINFOEX();
|
||||
monitorInfo.cbSize = (UInt32)Marshal.SizeOf(typeof(MONITORINFOEX));
|
||||
//monitorInfo.szDevice = new char[Utils.CCHDEVICENAME];
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Getting the monitor coordinates from the main monitor");
|
||||
Utils.GetMonitorInfo(mainMonitorHwnd, ref monitorInfo);
|
||||
|
||||
abd.hWnd = mainTaskbarHwnd;
|
||||
@ -568,6 +569,10 @@ namespace DisplayMagicianShared.Windows
|
||||
tbsrMain.TaskBarLocation = tbsr.TaskBarLocation;
|
||||
tbsrMain.MainScreen = tbsr.MainScreen;
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Main monitor coordinates are {tbsrMain.MonitorLocation.X},{tbsrMain.MonitorLocation.Y} and it is {tbsrMain.MonitorLocation.Width}x{tbsrMain.MonitorLocation.Height}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Main taskbar coordinates are {tbsrMain.TaskBarLocation.X},{tbsrMain.TaskBarLocation.Y} and it is {tbsrMain.TaskBarLocation.Width}x{tbsrMain.TaskBarLocation.Height}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Main taskbar is {tbsrMain.Edge.ToString("G")}");
|
||||
|
||||
// Now as a LAST step we update the Binary field just before we apply it to make sure that the correct binary settings are stored
|
||||
tbsrMain.PopulateBinaryFromFields();
|
||||
taskBarStuckRectangles.Add("Settings", tbsrMain);
|
||||
@ -575,116 +580,128 @@ namespace DisplayMagicianShared.Windows
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SharedLogger.logger.Error(ex, $"WinLibrary/GetAllCurrentTaskBarPositions: Exception while trying to get the maintaskbar position");
|
||||
SharedLogger.logger.Error(ex, $"TaskBarLayout/GetAllCurrentTaskBarPositions: Exception while trying to get the main taskbar position");
|
||||
}
|
||||
|
||||
// Then go through the secondary windows and get the position of them
|
||||
// Tell Windows to refresh the Other Windows Taskbars if needed
|
||||
IntPtr lastTaskBarWindowHwnd = (IntPtr)Utils.NULL;
|
||||
for (int i = 0; i < 100; i++)
|
||||
try
|
||||
{
|
||||
// Find the next "Shell_SecondaryTrayWnd" window
|
||||
IntPtr nextTaskBarWindowHwnd = Utils.FindWindowEx((IntPtr)Utils.NULL, lastTaskBarWindowHwnd, "Shell_SecondaryTrayWnd", null);
|
||||
if (nextTaskBarWindowHwnd == (IntPtr)Utils.NULL)
|
||||
IntPtr lastTaskBarWindowHwnd = (IntPtr)Utils.NULL;
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
// No more windows taskbars to notify
|
||||
break;
|
||||
}
|
||||
|
||||
IntPtr secMonitorHwnd = Utils.MonitorFromWindow(nextTaskBarWindowHwnd, Utils.MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
// Figure out the monitor coordinates
|
||||
MONITORINFOEX monitorInfo = new MONITORINFOEX();
|
||||
monitorInfo.cbSize = (UInt32)Marshal.SizeOf(typeof(MONITORINFOEX));
|
||||
//monitorInfo.szDevice = new char[Utils.CCHDEVICENAME];
|
||||
Utils.GetMonitorInfo(secMonitorHwnd, ref monitorInfo);
|
||||
|
||||
// Figure out the position of the taskbar ourselves
|
||||
int monWidth = Math.Abs(monitorInfo.rcMonitor.left - monitorInfo.rcMonitor.right);
|
||||
int monHeight = Math.Abs(monitorInfo.rcMonitor.top - monitorInfo.rcMonitor.bottom);
|
||||
int wrkWidth = Math.Abs(monitorInfo.rcWork.left - monitorInfo.rcWork.right);
|
||||
int wrkHeight = Math.Abs(monitorInfo.rcWork.top - monitorInfo.rcWork.bottom);
|
||||
int tbWidth;
|
||||
int tbHeight;
|
||||
|
||||
TaskBarLayout tbsr = new TaskBarLayout();
|
||||
// Now we're at the point that we should be able to update the binary that we grabbed earlier when the object was created
|
||||
tbsr.ReadFromRegistry(GetRegKeyValueFromDevicePath(displaySources[monitorInfo.szDevice][0].DevicePath));
|
||||
if (monWidth == wrkWidth)
|
||||
{
|
||||
// Taskbar on top or bottom
|
||||
if (monitorInfo.rcMonitor.left == monitorInfo.rcWork.left && monitorInfo.rcMonitor.top == monitorInfo.rcWork.top)
|
||||
// Find the next "Shell_SecondaryTrayWnd" window
|
||||
IntPtr nextTaskBarWindowHwnd = Utils.FindWindowEx((IntPtr)Utils.NULL, lastTaskBarWindowHwnd, "Shell_SecondaryTrayWnd", null);
|
||||
if (nextTaskBarWindowHwnd == (IntPtr)Utils.NULL)
|
||||
{
|
||||
// Taskbar on bottom
|
||||
tbWidth = monWidth;
|
||||
tbHeight = monHeight - wrkHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcWork.bottom, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Bottom;
|
||||
// No more windows taskbars to notify
|
||||
break;
|
||||
}
|
||||
else if (monitorInfo.rcMonitor.right == monitorInfo.rcWork.right && monitorInfo.rcMonitor.bottom == monitorInfo.rcWork.bottom)
|
||||
|
||||
IntPtr secMonitorHwnd = Utils.MonitorFromWindow(nextTaskBarWindowHwnd, Utils.MONITOR_DEFAULTTONEAREST);
|
||||
|
||||
// Figure out the monitor coordinates
|
||||
MONITORINFOEX monitorInfo = new MONITORINFOEX();
|
||||
monitorInfo.cbSize = (UInt32)Marshal.SizeOf(typeof(MONITORINFOEX));
|
||||
//monitorInfo.szDevice = new char[Utils.CCHDEVICENAME];
|
||||
Utils.GetMonitorInfo(secMonitorHwnd, ref monitorInfo);
|
||||
|
||||
// Figure out the position of the taskbar ourselves
|
||||
int monWidth = Math.Abs(monitorInfo.rcMonitor.left - monitorInfo.rcMonitor.right);
|
||||
int monHeight = Math.Abs(monitorInfo.rcMonitor.top - monitorInfo.rcMonitor.bottom);
|
||||
int wrkWidth = Math.Abs(monitorInfo.rcWork.left - monitorInfo.rcWork.right);
|
||||
int wrkHeight = Math.Abs(monitorInfo.rcWork.top - monitorInfo.rcWork.bottom);
|
||||
int tbWidth;
|
||||
int tbHeight;
|
||||
|
||||
TaskBarLayout tbsr = new TaskBarLayout();
|
||||
// Now we're at the point that we should be able to update the binary that we grabbed earlier when the object was created
|
||||
tbsr.ReadFromRegistry(GetRegKeyValueFromDevicePath(displaySources[monitorInfo.szDevice][0].DevicePath));
|
||||
if (monWidth == wrkWidth)
|
||||
{
|
||||
// Taskbar on top
|
||||
tbWidth = monWidth;
|
||||
tbHeight = monHeight - wrkHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcWork.left, monitorInfo.rcMonitor.top, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Top;
|
||||
// Taskbar on top or bottom
|
||||
if (monitorInfo.rcMonitor.left == monitorInfo.rcWork.left && monitorInfo.rcMonitor.top == monitorInfo.rcWork.top)
|
||||
{
|
||||
// Taskbar on bottom
|
||||
tbWidth = monWidth;
|
||||
tbHeight = monHeight - wrkHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcWork.bottom, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Bottom;
|
||||
}
|
||||
else if (monitorInfo.rcMonitor.right == monitorInfo.rcWork.right && monitorInfo.rcMonitor.bottom == monitorInfo.rcWork.bottom)
|
||||
{
|
||||
// Taskbar on top
|
||||
tbWidth = monWidth;
|
||||
tbHeight = monHeight - wrkHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcWork.left, monitorInfo.rcMonitor.top, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Top;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid state
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar position was not on a horizontal edge of a monitor!");
|
||||
}
|
||||
|
||||
}
|
||||
else if (monHeight == wrkHeight)
|
||||
{
|
||||
// Taskbar on the sides
|
||||
if (monitorInfo.rcMonitor.right == monitorInfo.rcWork.right && monitorInfo.rcMonitor.bottom == monitorInfo.rcWork.bottom)
|
||||
{
|
||||
// Taskbar on left
|
||||
tbWidth = monWidth - wrkWidth;
|
||||
tbHeight = monHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Left;
|
||||
}
|
||||
else if (monitorInfo.rcMonitor.left == monitorInfo.rcWork.left && monitorInfo.rcMonitor.top == monitorInfo.rcWork.top)
|
||||
{
|
||||
// Taskbar on right
|
||||
tbWidth = monWidth - wrkWidth;
|
||||
tbHeight = monHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcWork.right, monitorInfo.rcMonitor.top, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Right;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid state
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar position was not on a vertical edge of a monitor!");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid state
|
||||
SharedLogger.logger.Error($"WinLibrary/GetAllCurrentTaskBarPositions: Taskbar position was not on a horizontal edge of a monitor!");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Taskbar position was not fully along one of the monitor edges!");
|
||||
}
|
||||
|
||||
}
|
||||
else if (monHeight == wrkHeight)
|
||||
{
|
||||
// Taskbar on the sides
|
||||
if (monitorInfo.rcMonitor.right == monitorInfo.rcWork.right && monitorInfo.rcMonitor.bottom == monitorInfo.rcWork.bottom)
|
||||
tbsr.MonitorLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monWidth, monHeight);
|
||||
tbsr.MainScreen = false;
|
||||
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Secondary monitor coordinates are {tbsr.MonitorLocation.X},{tbsr.MonitorLocation.Y} and it is {tbsr.MonitorLocation.Width}x{tbsr.MonitorLocation.Height}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Secondary taskbar coordinates are {tbsr.TaskBarLocation.X},{tbsr.TaskBarLocation.Y} and it is {tbsr.TaskBarLocation.Width}x{tbsr.TaskBarLocation.Height}");
|
||||
SharedLogger.logger.Trace($"TaskBarLayout/GetAllCurrentTaskBarPositions: Secondary taskbar is {tbsr.Edge.ToString("G")}");
|
||||
|
||||
// Now as a LAST step we update the Binary field just before we apply it to make sure that the correct binary settings are stored
|
||||
tbsr.PopulateBinaryFromFields();
|
||||
|
||||
if (!taskBarStuckRectangles.ContainsKey(monitorInfo.szDevice))
|
||||
{
|
||||
// Taskbar on left
|
||||
tbWidth = monWidth - wrkWidth;
|
||||
tbHeight = monHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Left;
|
||||
}
|
||||
else if (monitorInfo.rcMonitor.left == monitorInfo.rcWork.left && monitorInfo.rcMonitor.top == monitorInfo.rcWork.top)
|
||||
{
|
||||
// Taskbar on right
|
||||
tbWidth = monWidth - wrkWidth;
|
||||
tbHeight = monHeight;
|
||||
tbsr.TaskBarLocation = new System.Drawing.Rectangle(monitorInfo.rcWork.right, monitorInfo.rcMonitor.top, tbWidth, tbHeight);
|
||||
tbsr.Edge = TaskBarEdge.Right;
|
||||
taskBarStuckRectangles.Add(monitorInfo.szDevice, tbsr);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid state
|
||||
SharedLogger.logger.Error($"WinLibrary/GetAllCurrentTaskBarPositions: Taskbar position was not on a vertical edge of a monitor!");
|
||||
SharedLogger.logger.Error($"TaskBarLayout/GetAllCurrentTaskBarPositions: Skipping grabbing Taskbar position from a cloned display {monitorInfo.szDevice}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Invalid state
|
||||
SharedLogger.logger.Error($"WinLibrary/GetAllCurrentTaskBarPositions: Taskbar position was not fully along one of the monitor edges!");
|
||||
}
|
||||
|
||||
tbsr.MonitorLocation = new System.Drawing.Rectangle(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top, monWidth, monHeight);
|
||||
tbsr.MainScreen = false;
|
||||
|
||||
// Now as a LAST step we update the Binary field just before we apply it to make sure that the correct binary settings are stored
|
||||
tbsr.PopulateBinaryFromFields();
|
||||
|
||||
if (!taskBarStuckRectangles.ContainsKey(monitorInfo.szDevice))
|
||||
{
|
||||
taskBarStuckRectangles.Add(monitorInfo.szDevice, tbsr);
|
||||
// Prep the next taskbar window so we continue through them
|
||||
lastTaskBarWindowHwnd = nextTaskBarWindowHwnd;
|
||||
}
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Error($"WinLibrary/GetAllCurrentTaskBarPositions: Skipping grabbing Taskbar position from a cloned display {monitorInfo.szDevice}");
|
||||
}
|
||||
|
||||
// Prep the next taskbar window so we continue through them
|
||||
lastTaskBarWindowHwnd = nextTaskBarWindowHwnd;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SharedLogger.logger.Error(ex, $"TaskBarLayout/GetAllCurrentTaskBarPositions: Exception while trying to get a secondary taskbar position");
|
||||
}
|
||||
|
||||
|
||||
return taskBarStuckRectangles;
|
||||
}
|
||||
|
@ -74,20 +74,22 @@ namespace DisplayMagicianShared.Windows
|
||||
|
||||
if (value != null && value is int intValue)
|
||||
{
|
||||
SharedLogger.logger.Trace($"TaskBarSettings/GetCurrent: Got taskbar setting {valueName} = {intValue}");
|
||||
taskBarOptions.Add(new Tuple<string, int>(valueName, intValue));
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignored, as this will happen
|
||||
SharedLogger.logger.Error(ex,$"TaskBarSettings/GetCurrent: Exception getting taskbar setting {valueName}. It likely does not exist (which happens if it is not explicitly set).");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignored
|
||||
SharedLogger.logger.Error(ex, $"TaskBarSettings/GetCurrent: Exception opening taskbar setting registry key {AdvancedSettingsAddress}.");
|
||||
}
|
||||
|
||||
if (taskBarOptions.Count == 0)
|
||||
|
@ -866,10 +866,11 @@ namespace DisplayMagicianShared.Windows
|
||||
Dictionary<string, TaskBarLayout> taskBarStuckRectangles = new Dictionary<string, TaskBarLayout>();
|
||||
|
||||
// Now attempt to get the windows taskbar location for each display
|
||||
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Attempting to get the Windows Taskbar Layouts.");
|
||||
taskBarStuckRectangles = TaskBarLayout.GetAllCurrentTaskBarLayouts(windowsDisplayConfig.DisplaySources);
|
||||
|
||||
// Now we try to get the taskbar settings too
|
||||
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Attempting to get the Windows Taskbar settings.");
|
||||
SharedLogger.logger.Trace($"WinLibrary/GetWindowsDisplayConfig: Attempting to get the Windows Taskbar Settings.");
|
||||
TaskBarSettings taskBarSettings = TaskBarSettings.GetCurrent();
|
||||
|
||||
// Store the active paths and modes in our display config object
|
||||
|
Loading…
Reference in New Issue
Block a user