Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dylan Bickerstaff committed Mar 25, 2024
1 parent c7460fe commit ba619f9
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 93 deletions.
54 changes: 27 additions & 27 deletions SuperLauncher/ComInterop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,74 +10,74 @@ public class ExplorerBrowser { }
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("dfd3b6b5-c10c-4be9-85f6-a66969f402f6")]
public interface IExplorerBrowser
{
public uint Initialize([In] IntPtr hwndParent, [In] ref Win32Interop.RECT prc, [In, Optional] ref FOLDERSETTINGS pfs);
public uint Initialize([In] nint hwndParent, [In] ref Win32Interop.RECT prc, [In, Optional] ref FOLDERSETTINGS pfs);
public uint Destroy();
public uint SetRect([In, Out] ref IntPtr phdwp, [In] Win32Interop.RECT rcBrowser);
public uint SetRect([In, Out] ref nint phdwp, [In] Win32Interop.RECT rcBrowser);
public uint SetPropertyBag([In] string pszPropertyBag);
public uint SetEmptyText([In] string pszEmptyText);
public uint SetFolderSettings([In] ref FOLDERSETTINGS pfs);
public uint Advise([In] IExplorerBrowserEvents psbe, [Out] out uint pdwCookie);
public uint Unadvise([In] uint dwCookie);
public uint SetOptions([In] EXPLORER_BROWSER_OPTIONS dwFlags);
public uint GetOptions([Out] out EXPLORER_BROWSER_OPTIONS pdwFlags);
public uint BrowseToIDList([In] IntPtr pidl, [In] BROWSETOFLAGS uFlags);
public uint BrowseToObjects([In] IntPtr punk, [In] BROWSETOFLAGS uflags);
public uint FillFromObject([In] IntPtr punk, [In] EXPLORER_BROWSER_FILL_FLAGS dwFlags);
public uint BrowseToIDList([In] nint pidl, [In] BROWSETOFLAGS uFlags);
public uint BrowseToObjects([In] nint punk, [In] BROWSETOFLAGS uflags);
public uint FillFromObject([In] nint punk, [In] EXPLORER_BROWSER_FILL_FLAGS dwFlags);
public uint RemoveAll();
public uint GetCurrentView([In] Guid riid, [Out] out IntPtr ppv);
public uint GetCurrentView([In] Guid riid, [Out] out nint ppv);
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("00000114-0000-0000-c000-000000000046")]
public interface IOleWindow
{
public uint GetWindow([Out] out IntPtr phwnd);
public uint GetWindow([Out] out nint phwnd);
public uint ContextSensitiveHelp([In] bool fEnterMode);
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("000214E3-0000-0000-C000-000000000046")]
public interface IShellView
{
public uint GetWindow([Out] out IntPtr phwnd);
public uint GetWindow([Out] out nint phwnd);
public uint ContextSensitiveHelp([In] bool fEnterMode);
public uint TranslateAccelerator([In] IntPtr pmsg);
public uint TranslateAccelerator([In] nint pmsg);
public uint EnableModeless([In] bool fEnable);
public uint UIActivate([In] uint uState);
public uint Refresh();
public uint CreateViewWindow([In] ref IShellView psvPrevious, [In] FOLDERSETTINGS pfs, [In] IntPtr psb, [In] ref Win32Interop.RECT prcView, [Out] out IntPtr phWnd);
public uint CreateViewWindow([In] ref IShellView psvPrevious, [In] FOLDERSETTINGS pfs, [In] nint psb, [In] ref Win32Interop.RECT prcView, [Out] out nint phWnd);
public uint DestroyViewWindow();
public uint GetCurrentInfo([Out] out FOLDERSETTINGS pfs);
public uint AddPropertySheetPages([In] uint dwReserved, [In] object pfn, [In] uint lparam);
public uint SaveViewState();
public uint SelectItem([In] IntPtr pidlItem, [In] uint uFlags);
public uint GetItemObject([In] uint uItem, [In] Guid riid, [Out] out IntPtr ppv);
public uint SelectItem([In] nint pidlItem, [In] uint uFlags);
public uint GetItemObject([In] uint uItem, [In] Guid riid, [Out] out nint ppv);
}
[ComImport, InterfaceType(ComInterfaceType.InterfaceIsIUnknown), Guid("cde725b0-ccc9-4519-917e-325d72fab4ce")]
public interface IFolderView
{
public uint GetCurrentViewMode([Out] out IntPtr pViewMode);
public uint GetCurrentViewMode([Out] out nint pViewMode);
public uint SetCurrentViewMode([In] FOLDERVIEWMODE ViewMode);
public uint GetFolder([In] Guid riid, [Out] out IntPtr ppv);
public uint Item([In] int iItemIndex, [Out] out IntPtr ppidl);
public uint ItemCount([In] SVGIO uFlags, [Out] out IntPtr pcItems);
public uint Items([In] SVGIO uFlags, [In] Guid riid, [Out] out IntPtr ppv);
public uint GetSelectionMarkedItem([Out] out IntPtr piItem);
public uint GetFocusedItem([Out] out IntPtr piItem);
public uint GetItemPosition([In] IntPtr pidl, [Out] IntPtr ppt);
public uint GetSpacing([Out][In] IntPtr ppt);
public uint GetDefaultSpacing([Out] out IntPtr ppt);
public uint GetFolder([In] Guid riid, [Out] out nint ppv);
public uint Item([In] int iItemIndex, [Out] out nint ppidl);
public uint ItemCount([In] SVGIO uFlags, [Out] out nint pcItems);
public uint Items([In] SVGIO uFlags, [In] Guid riid, [Out] out nint ppv);
public uint GetSelectionMarkedItem([Out] out nint piItem);
public uint GetFocusedItem([Out] out int piItem);
public uint GetItemPosition([In] nint pidl, [Out] nint ppt);
public uint GetSpacing([Out][In] nint ppt);
public uint GetDefaultSpacing([Out] out nint ppt);
public uint GetAutoArrange();
public uint SelectItem([In] int iItem, [In] SVSIF dwFlags);
public uint SelectAndPositionItems([In] uint cidl, [In] IntPtr apidl, [In] IntPtr apt, [In] SVSIF dwFlags);
public uint SelectAndPositionItems([In] uint cidl, [In] nint apidl, [In] nint apt, [In] SVSIF dwFlags);
}
[ComImport, Guid("361bbdc7-e6ee-4e13-be58-58e2240c810f"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IExplorerBrowserEvents
{
[PreserveSig]
uint OnNavigationPending([In] IntPtr pidlFolder);
uint OnNavigationPending([In] nint pidlFolder);
[PreserveSig]
uint OnViewCreated([In] IntPtr psv);
uint OnViewCreated([In] nint psv);
[PreserveSig]
uint OnNavigationComplete([In] IntPtr pidlFolder);
uint OnNavigationComplete([In] nint pidlFolder);
[PreserveSig]
uint OnNavigationFailed([In] IntPtr pidlFolder);
uint OnNavigationFailed([In] nint pidlFolder);
}
[StructLayout(LayoutKind.Sequential)]
public struct FOLDERSETTINGS
Expand Down
6 changes: 3 additions & 3 deletions SuperLauncher/CredentialManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ public static class CredentialManager
[DllImport("advapi32.dll")]
public static extern bool CredWriteA(CREDENTIAL Credential, CredWriteFlags Flags);
[DllImport("advapi32.dll")]
public static extern bool CredReadA(string TargetName, CredType Type, CredReadFlags Flags, out IntPtr Credential);
public static extern bool CredReadA(string TargetName, CredType Type, CredReadFlags Flags, out nint Credential);
[DllImport("advapi32.dll")]
public static extern bool CredDeleteA(string TargetName, CredType Type, CredDeleteFlags Flags);
public static bool CredReadA(string TargetName, CredType Type, CredReadFlags Flags, out CREDENTIAL Credential)
{
bool success = CredReadA(TargetName, Type, Flags, out IntPtr credPtr);
bool success = CredReadA(TargetName, Type, Flags, out nint credPtr);
Credential = new();
try { Marshal.PtrToStructure(credPtr, Credential); } catch { }
return success;
Expand All @@ -28,7 +28,7 @@ public class CREDENTIAL
public string Comment;
public FILETIME LastWritten;
public uint CredentialBlobSize;
public IntPtr CredentialBlob;
public nint CredentialBlob;
public CredPersist Persist;
public uint AttributeCount;
public uint Attributes;
Expand Down
8 changes: 4 additions & 4 deletions SuperLauncher/Launcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public partial class Launcher : Form
private readonly int HandleWidth = 5;
private readonly int BottomRightMargin = 5;
[DllImport("user32.dll", SetLastError = true)]
static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
static extern bool SetWindowPos(nint hWnd, nint hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("dwmapi.dll")]
private static extern int DwmExtendFrameIntoClientArea(IntPtr hwnd, ref MARGINS margins);
private static extern int DwmExtendFrameIntoClientArea(nint hwnd, ref MARGINS margins);
[StructLayout(LayoutKind.Sequential)]
private struct MARGINS
{
Expand Down Expand Up @@ -86,9 +86,9 @@ protected override void WndProc(ref Message m)
}
if (m.Msg == 0x1) //WM_CREATE
{
SetWindowPos(Handle, IntPtr.Zero, Left, Top, Width, Height, 0x20); //SWP_FRAMECHANGED
SetWindowPos(Handle, nint.Zero, Left, Top, Width, Height, 0x20); //SWP_FRAMECHANGED
}
if (m.Msg == 0x83 && m.WParam == (IntPtr)1) //WM_NCCALCSIZE
if (m.Msg == 0x83 && m.WParam == (nint)1) //WM_NCCALCSIZE
{
return;
}
Expand Down
8 changes: 4 additions & 4 deletions SuperLauncher/ModernLauncher.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public ModernLauncher()
Width = Settings.Default.Width;
Height = Settings.Default.Height;
}
private IntPtr HwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
private nint HwndSourceHook(nint hwnd, int msg, nint wParam, nint lParam, ref bool handled)
{
if (msg == 0x0312 && wParam.ToInt32() == 0) //WM_HOTKEY //ALT + S
{
Expand All @@ -79,7 +79,7 @@ private IntPtr HwndSourceHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam
{
OpenWindow();
}
return IntPtr.Zero;
return nint.Zero;
}
private void InitializeNotifyIcon()
{
Expand Down Expand Up @@ -114,7 +114,7 @@ private void UpdateAnimations(bool Center = false)
{
Win32Interop.MONITORINFO mi = new();
mi.cbSize = (uint)Marshal.SizeOf(mi);
IntPtr hMonitor = Win32Interop.MonitorFromWindow(WIH.Handle, Win32Interop.MonitorFromWindowFlags.MONITOR_DEFAULTTONEAREST);
nint hMonitor = Win32Interop.MonitorFromWindow(WIH.Handle, Win32Interop.MonitorFromWindowFlags.MONITOR_DEFAULTTONEAREST);
Win32Interop.GetMonitorInfo(hMonitor, out mi);
OpenTopAnimation.From = CloseTopAnimation.From = Top;
CloseTopAnimation.To = DPI.ScalePixelsDown(mi.rcMonitor.bottom);
Expand Down Expand Up @@ -215,7 +215,7 @@ private void CloseTopAnimation_Completed(object sender, EventArgs e)
}
private void OpenTopAnimation_Completed(object sender, EventArgs e)
{
Win32Interop.InvalidateRect(WIH.Handle, IntPtr.Zero, false);
Win32Interop.InvalidateRect(WIH.Handle, nint.Zero, false);
}
private void ModernApplication_Exit(object sender, ExitEventArgs e)
{
Expand Down
16 changes: 1 addition & 15 deletions SuperLauncher/ModernLauncherIcon.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
using System;
using System.Diagnostics;
using System.Drawing;
using System.Threading.Tasks;
using System.Timers;
using System.Windows;
using System.Windows.Controls;
Expand Down Expand Up @@ -164,19 +162,7 @@ private void BadgeTimer_Elapsed(object sender, ElapsedEventArgs e)
public void StartProgram()
{
((ModernLauncher)Window.GetWindow(this)).CloseWindow();
Task.Run(() =>
{
try
{
Process.Start(new ProcessStartInfo()
{
FileName = FilePath,
UseShellExecute = true,
WorkingDirectory = Environment.GetEnvironmentVariable("USERPROFILE")
});
}
catch { }
});
Shared.StartProcess(FilePath);
}
private void UserControl_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
Expand Down
27 changes: 23 additions & 4 deletions SuperLauncher/ModernLauncherShared.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Win32;
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
Expand Down Expand Up @@ -62,16 +64,16 @@ public static void SetWindowColor(Window Window)
public static void EnableAcrylic(Window Window)
{
Window.Background = Brushes.Transparent;
IntPtr handle = new WindowInteropHelper(Window).Handle;
IntPtr dwmDmVal = Marshal.AllocHGlobal(4);
nint handle = new WindowInteropHelper(Window).Handle;
nint dwmDmVal = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(dwmDmVal, 1);
Win32Interop.DwmSetWindowAttribute(handle, Win32Interop.DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, dwmDmVal, 4);
Marshal.FreeHGlobal(dwmDmVal);
IntPtr dwmBdVal = Marshal.AllocHGlobal(4);
nint dwmBdVal = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(dwmBdVal, 3);
Win32Interop.DwmSetWindowAttribute(handle, Win32Interop.DWMWINDOWATTRIBUTE.DWMWA_SYSTEMBACKDROP_TYPE, dwmBdVal, 4);
Marshal.FreeHGlobal(dwmBdVal);
IntPtr dwmTbVal = Marshal.AllocHGlobal(4);
nint dwmTbVal = Marshal.AllocHGlobal(4);
Marshal.WriteInt32(dwmTbVal, unchecked((int)0xFFFFFFFE));
Win32Interop.DwmSetWindowAttribute(handle, Win32Interop.DWMWINDOWATTRIBUTE.DWMWA_CAPTION_COLOR, dwmTbVal, 4);
Marshal.FreeHGlobal(dwmTbVal);
Expand All @@ -82,5 +84,22 @@ public static string ExtRemover(string FilePath)
FilePath = FilePath.Remove(FilePath.LastIndexOf('.'));
return FilePath;
}
public static void StartProcess(string FilePath, string Arguments = "")
{
Task.Run(() =>
{
try
{
Process.Start(new ProcessStartInfo()
{
FileName = FilePath,
Arguments = Arguments,
UseShellExecute = true,
WorkingDirectory = Environment.GetEnvironmentVariable("USERPROFILE")
});
}
catch { }
});
}
}
}
Loading

0 comments on commit ba619f9

Please sign in to comment.