Skip to content

Commit

Permalink
Removed unused methods
Browse files Browse the repository at this point in the history
  • Loading branch information
SamChaps committed Dec 9, 2022
1 parent 5b532f0 commit 9238a80
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 120 deletions.
69 changes: 0 additions & 69 deletions src/modules/peek/Peek.UI/Extensions/WindowExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,74 +55,5 @@ public static void BringToForeground(this Window window)
PInvoke.ShowWindow(new HWND(windowHandle), Windows.Win32.UI.WindowsAndMessaging.SHOW_WINDOW_CMD.SW_SHOW);
PInvoke.AttachThreadInput(windowThreadProcessId, currentThreadId, false);
}

private static void AcquireForegroundPrivilege()
{
IntPtr remoteProcessHandle = 0;
IntPtr user32Handle = 0;
IntPtr remoteThreadHandle = 0;

try
{
// Get the handle of the shell window.
IntPtr topHandle = NativeMethods.GetShellWindow();
if (topHandle == 0)
{
throw new InvalidOperationException("Failed to get the shell desktop window.");
}

// Open the process that owns it.
IntPtr remoteProcessId = 0;
NativeMethods.GetWindowThreadProcessId(topHandle, ref remoteProcessId);
if (remoteProcessId == 0)
{
throw new InvalidOperationException("Failed to get the shell process ID.");
}

remoteProcessHandle = NativeMethods.OpenProcess(NativeMethods.PROCESS_ALL_ACCESS, false, remoteProcessId);
if (remoteProcessHandle == 0)
{
throw new InvalidOperationException("Failed to open the shell process.");
}

// Get the address of the AllowSetForegroundWindow API.
user32Handle = NativeMethods.LoadLibrary("user32.dll");
IntPtr entryPoint = NativeMethods.GetProcAddress(user32Handle, "AllowSetForegroundWindow");

// Create a remote thread in the other process and make it call the API.
remoteThreadHandle = NativeMethods.CreateRemoteThread(
remoteProcessHandle,
0,
100000,
entryPoint,
NativeMethods.GetCurrentProcessId(),
0,
0);
if (remoteThreadHandle == 0)
{
throw new InvalidOperationException("Failed to create the remote thread.");
}

// Wait for the remote thread to terminate.
_ = NativeMethods.WaitForSingleObject(remoteThreadHandle, 5000);
}
finally
{
if (remoteProcessHandle != 0)
{
_ = NativeMethods.CloseHandle(remoteProcessHandle);
}

if (remoteThreadHandle != 0)
{
_ = NativeMethods.CloseHandle(remoteThreadHandle);
}

if (user32Handle != 0)
{
_ = NativeMethods.FreeLibrary(user32Handle);
}
}
}
}
}
51 changes: 0 additions & 51 deletions src/modules/peek/Peek.UI/Native/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ namespace Peek.UI.Native

public static class NativeMethods
{
internal const uint PROCESS_ALL_ACCESS = 0x1f0fff;
internal const IntPtr HWND_TOP = 0;
internal const uint SWP_DRAWFRAME = 0x0020;
internal const uint SWP_NOMOVE = 0x0002;
internal const uint SWP_NOSIZE = 0x0001;
internal const uint SWP_SHOWWINDOW = 0x0040;
internal const int WM_SYSCOMMAND = 0x0112;
internal const int SC_RESTORE = 0xF120;

[Flags]
public enum AssocF
{
Expand Down Expand Up @@ -56,47 +47,5 @@ public enum AssocStr

[DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Auto)]
internal static extern HResult AssocQueryString(AssocF flags, AssocStr str, string pszAssoc, string? pszExtra, [Out] StringBuilder? pszOut, [In][Out] ref uint pcchOut);

[DllImport("user32.dll")]
internal static extern IntPtr GetWindowThreadProcessId(IntPtr hWnd, ref IntPtr ProcessId);

[DllImport("kernel32.dll")]
internal static extern IntPtr OpenProcess(uint fdwAccess, bool fInherit, IntPtr IDProcess);

[DllImport("kernel32.dll")]
internal static extern int CloseHandle(IntPtr hObject);

[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string lpProcName);

[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string lpLibName);

[DllImport("kernel32.dll")]
internal static extern bool FreeLibrary(IntPtr lib);

[DllImport("kernel32.dll")]
internal static extern IntPtr CreateRemoteThread(IntPtr hProcess, IntPtr bogusAttributes, int dwStackSize, IntPtr lpStartAddress, IntPtr lpParameter, int dwCreationFlags, IntPtr lpThreadId);

[DllImport("kernel32.dll")]
internal static extern uint WaitForSingleObject(IntPtr hObject, int dwMilliseconds);

[DllImport("user32.dll")]
internal static extern IntPtr GetShellWindow();

[DllImport("kernel32.dll")]
internal static extern IntPtr GetCurrentProcess();

[DllImport("kernel32.dll")]
internal static extern int GetCurrentProcessId();

[DllImport("user32.dll")]
internal static extern int SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);

[DllImport("user32.dll")]
internal static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

[DllImport("user32.dll")]
internal static extern int SetForegroundWindow(IntPtr hWnd);
}
}

1 comment on commit 9238a80

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (138)
Abbrivation
apidl
ari
arw
BESTEFFORT
BHIDSF
BVal
calpwstr
CARRAY
CElems
Chromakey
cidl
crw
CVal
DANGEROUSLYCOMMITMERELYTODISKCACHE
dcr
dcs
Dct
DDEIf
Dds
DELAYCREATION
drf
Dwma
eip
Exa
exabyte
Excep
EXCEPINFO
EXTRINSICPROPERTIES
EXTRINSICPROPERTIESONLY
FASTPROPERTIESONLY
filetime
HANDLERPROPERTIESONLY
HDR
hicon
hif
HVal
IBitmap
IBlock
IColor
icolumn
IContext
IDecoder
IEncoder
IEnum
IIDI
iiq
IMetadata
IPalette
IQuery
IReader
ISource
ISurface
ithumbnail
jfi
jif
kdc
Keybd
Lcid
LOCKBYTES
LOCKTYPE
LVal
mdc
mef
Mega
mrw
neighborings
NOOPEN
nrw
ONLYIFCURRENT
ONLYONCE
OPENSLOWITEM
openspecs
OPLOCK
ori
overriden
pbgra
PBlob
pcch
pcelt
pcs
pef
PElems
Percision
petabyte
pkey
ppenum
pprop
PREFERQUERYPROPERTIES
Previer
PRGBA
PROPERTYNOTFOUND
PROPVARIANT
pscid
psfi
pstatstg
pstm
pui
pvar
raf
retunred
rfid
RGBE
rgelt
rgf
rwl
rwz
sachaple
SAFEARRAY
SCID
Scode
Shcontf
SHELLDETAILS
Shgno
Softcoded
srf
SRGB
STGC
STGTY
Stroe
Strret
terabyte
titlebar
tlbimp
toogle
UMsg
UOffset
USERDEFINED
UType
VARTYPE
VERSIONED
windowsapp
WMSDK
WReserved
WScan
wsp
WVk
YQuantized
Previously acknowledged words that are now absent brucelindbloom chromaticities companding DCR Eqn ffaa FILETIME HICON ITHUMBNAIL Pbgra PKEY Windowsapp :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:microsoft/PowerToys.git repository
on the samchaps/window-behaviors branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/PowerToys/actions/runs/3654026130/attempts/1'
Available 📚 dictionaries could cover words not in the 📘 dictionary

This includes both expected items (2140) from .github/actions/spell-check/expect.txt and unrecognized words (138)

Dictionary Entries Covers
cspell:win32/src/win32.txt 53509 133
cspell:cpp/src/cpp.txt 30216 129
cspell:python/src/python/python-lib.txt 3873 31
cspell:php/php.txt 2597 17
cspell:node/node.txt 1768 14
cspell:typescript/typescript.txt 1211 12
cspell:java/java.txt 7642 11
cspell:python/src/python/python.txt 453 10
cspell:aws/aws.txt 218 8
cspell:r/src/r.txt 808 7

Consider adding them using (in .github/workflows/spelling2.yml):

      with:
        extra_dictionaries:
          cspell:win32/src/win32.txt
          cspell:cpp/src/cpp.txt
          cspell:python/src/python/python-lib.txt
          cspell:php/php.txt
          cspell:node/node.txt
          cspell:typescript/typescript.txt
          cspell:java/java.txt
          cspell:python/src/python/python.txt
          cspell:aws/aws.txt
          cspell:r/src/r.txt

To stop checking additional dictionaries, add:

      with:
        check_extra_dictionaries: ''
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.