Skip to content

Commit

Permalink
new stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Lixkote committed May 10, 2024
1 parent 0517687 commit 96b37cb
Show file tree
Hide file tree
Showing 7 changed files with 201 additions and 17 deletions.
2 changes: 1 addition & 1 deletion DirectStart/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/>
</startup>
</configuration>
2 changes: 1 addition & 1 deletion DirectStart/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion DirectStart/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added DirectStart/Resources/demo3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions DirectStart/Skins/Metro.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<Style x:Key="IsSkinSupportDuiBackgroundColor" TargetType="{x:Type TextBlock}">
<!-- False for not support background dui color, true for support background dui color. -->
<!-- This applies the metro dui color (the one from windows 8.1 start screen) to the start menu background-->
<Setter Property="Text" Value="True"></Setter>
<Setter Property="Text" Value="False"></Setter>
</Style>

<Style x:Key="PowerGlyphStyle" TargetType="{x:Type Image}">
Expand Down Expand Up @@ -54,7 +54,11 @@
</Style>

<Style x:Key="StartMenuBackgroundStyle" TargetType="{x:Type Grid}">

<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="pack://siteoforigin:,,,/Resources/demo3.png"/>
</Setter.Value>
</Setter>
</Style>


Expand Down
199 changes: 188 additions & 11 deletions DirectStart/StartMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,147 @@ public StartMenu()
}
}

private void AdjustToTaskbar()
private double GetTaskbarHeight()
{
// First, try to get taskbar height using Screen class
double taskbarHeight = GetTaskbarHeightUsingScreenClass();

// If the taskbar height obtained is non-negative, return it
if (taskbarHeight >= 0)
return taskbarHeight;

// If the taskbar height obtained is negative, try an alternate method
taskbarHeight = GetTaskbarHeightUsingShell32();

return taskbarHeight;
}

private double GetTaskbarHeightUsingScreenClass()
{
try
{
// Get the working area of the screen (excluding the taskbar)
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;

// Get the total area of the screen
Rectangle screenArea = Screen.PrimaryScreen.Bounds;

// Calculate the taskbar height by subtracting the working area height from the total screen height
double taskbarHeight = screenArea.Height - workingArea.Height;

return taskbarHeight;
}
catch
{
// Handle any exceptions gracefully
return -1;
}
}

private double GetTaskbarHeightUsingShell32()
{
try
{
APPBARDATA appBarData = new APPBARDATA();
appBarData.cbSize = (uint)Marshal.SizeOf(appBarData);
IntPtr result = SHAppBarMessage(ABM_GETTASKBARPOS, ref appBarData);
if (result == IntPtr.Zero)
return -1;

RECT taskbarRect = appBarData.rc;
return taskbarRect.Bottom - taskbarRect.Top;
}
catch
{
// Handle any exceptions gracefully
return -1;
}
}

// P/Invoke declarations
[StructLayout(LayoutKind.Sequential)]
private struct APPBARDATA
{
public uint cbSize;
public IntPtr hWnd;
public uint uCallbackMessage;
public uint uEdge;
public RECT rc;
public IntPtr lParam;
}

[StructLayout(LayoutKind.Sequential)]
private struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}

[DllImport("shell32.dll")]
private static extern IntPtr SHAppBarMessage(uint dwMessage, ref APPBARDATA pData);

private const uint ABM_GETTASKBARPOS = 5;

private double GetTaskbarWidth()
{
// First, try to get taskbar width using Screen class
double taskbarWidth = GetTaskbarWidthUsingScreenClass();

// If the taskbar width obtained is non-negative, return it
if (taskbarWidth >= 0)
return taskbarWidth;

// If the taskbar width obtained is negative, try an alternate method
taskbarWidth = GetTaskbarWidthUsingShell32();

return taskbarWidth;
}

private double GetTaskbarWidthUsingScreenClass()
{
try
{
// Get the working area of the screen (excluding the taskbar)
Rectangle workingArea = Screen.PrimaryScreen.WorkingArea;

// Get the total area of the screen
Rectangle screenArea = Screen.PrimaryScreen.Bounds;

// Calculate the taskbar width by subtracting the working area width from the total screen width
double taskbarWidth = screenArea.Width - workingArea.Width;

return taskbarWidth;
}
catch
{
// Handle any exceptions gracefully
return -1;
}
}

private double GetTaskbarWidthUsingShell32()
{
try
{
APPBARDATA appBarData = new APPBARDATA();
appBarData.cbSize = (uint)Marshal.SizeOf(appBarData);
IntPtr result = SHAppBarMessage(ABM_GETTASKBARPOS, ref appBarData);
if (result == IntPtr.Zero)
return -1;

RECT taskbarRect = appBarData.rc;
return taskbarRect.Right - taskbarRect.Left;
}
catch
{
// Handle any exceptions gracefully
return -1;
}
}

private void AdjustToTaskbar()
{
var desktopWorkingArea = SystemParameters.WorkArea;
// Get the screen
Expand All @@ -148,9 +288,9 @@ private void AdjustToTaskbar()
}
else
{
taskbarheightinpx = SystemParameters.PrimaryScreenHeight - screen.WorkingArea.Height;
taskbarheightinpx = GetTaskbarHeight();
}
double taskbarwidthinpx = SystemParameters.PrimaryScreenWidth - screen.WorkingArea.Width;
double taskbarwidthinpx = GetTaskbarWidth();
var taskbarPosition = GetTaskbarPosition.Taskbar.Position;
Version osVersion = Environment.OSVersion.Version;

Expand Down Expand Up @@ -206,13 +346,27 @@ private void AdjustToTaskbar()
{
StartLogoBottom.Visibility = Visibility.Hidden;
}
StartLogoBottom.Height = taskbarheightinpx + 1;
Menu.Margin = new Thickness(0, 0, 0, taskbarheightinpx);
if (forceFillStartButton == "true")
{
// Windows 8
StartLogoBottom.Visibility = Visibility.Visible;
try
{
StartLogoBottom.Height = taskbarheightinpx + 1;
Menu.Margin = new Thickness(0, 0, 0, taskbarheightinpx);
if (forceFillStartButton == "true")
{
// Windows 8
StartLogoBottom.Visibility = Visibility.Visible;
}
}
catch (Exception ex)
{
StartLogoBottom.Height = 48 + 1;
Menu.Margin = new Thickness(0, 0, 0, 48);
if (forceFillStartButton == "true")
{
// Windows 8
StartLogoBottom.Visibility = Visibility.Visible;
}
Debug.WriteLine("Taskbar height exception: " + ex.ToString());
}
break;
case GetTaskbarPosition.TaskbarPosition.Left:
// Taskbar on left
Expand Down Expand Up @@ -291,7 +445,30 @@ private void AdjustToTaskbar()
int maxfrequent = 5;
int startfrequent = 0;

private void GetFrequentsNew()
private string GetDisplayNameFromExePath(string exePath)
{
string displayName = string.Empty;

try
{
var fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(exePath);
displayName = fileVersionInfo.FileDescription;

// If display name is longer than 17 characters, get the path without extension
if (displayName.Length > 25)
{
displayName = Path.GetFileNameWithoutExtension(exePath);
}
}
catch (Exception ex)
{
Debug.WriteLine($"An error occurred: {ex.Message}", "Error");
}

return displayName;
}

private void GetFrequentsNew()
{
if (startfrequent <= maxfrequent)
{
Expand Down Expand Up @@ -323,7 +500,7 @@ private void GetFrequentsNew()
{
Recent.Add(new StartMenuLink
{
Title = System.IO.Path.GetFileNameWithoutExtension(entry.DecodedName),
Title = GetDisplayNameFromExePath(entry.DecodedName),
Icon = IconHelper.GetFileIcon(entry.DecodedName),
Link = entry.DecodedName
});
Expand Down
5 changes: 4 additions & 1 deletion DirectStart/StartMenuCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<OutputType>WinExe</OutputType>
<RootNamespace>B8TAM</RootNamespace>
<AssemblyName>Start menu</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<WarningLevel>4</WarningLevel>
Expand Down Expand Up @@ -220,6 +220,9 @@
</COMReference>
</ItemGroup>
<ItemGroup>
<Content Include="Resources\demo3.png">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
<Content Include="Resources\folder.ico">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>
Expand Down

0 comments on commit 96b37cb

Please sign in to comment.