Skip to content

Commit

Permalink
Fix variable names and other stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
integralfx committed Jul 27, 2019
1 parent 12dda19 commit da9cc38
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion MemTestHelper2/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

<TabItem Header="About">
<Grid Background="#252525" Margin="0">
<Label Content="Version 2.0.0" HorizontalAlignment="Center" Margin="180,70,180,104" VerticalAlignment="Center"/>
<Label Content="Version 2.0.1" HorizontalAlignment="Center" Margin="180,70,180,104" VerticalAlignment="Center"/>
<Label Content="Discord:" HorizontalAlignment="Center" Margin="138,98,248,76" VerticalAlignment="Center"/>
<TextBox x:Name="txtDiscord" HorizontalAlignment="Left" Margin="190,98,0,0" TextWrapping="Wrap"
Text="∫ntegral#7834" VerticalAlignment="Top" IsReadOnly="True" Width="89" PreviewMouseDoubleClick="txtDiscord_DoubleClick"/>
Expand Down
21 changes: 12 additions & 9 deletions MemTestHelper2/WinAPI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,32 @@ public static string ControlGetText(IntPtr hwndParent, string className)
return str.ToString();
}

// Finds the first window that matches pid, and if non-empty, windowTitle.
public static IntPtr GetHWNDFromPID(int pid, String windowTitle = "")
{
IntPtr hwnd = IntPtr.Zero;

EnumWindows(
delegate (IntPtr curr_hwnd, IntPtr lParam)
delegate (IntPtr currHwnd, IntPtr lParam)
{
int len = GetWindowTextLength(curr_hwnd);
if (len != windowTitle.Length) return true;
int len = GetWindowTextLength(currHwnd);
if (windowTitle.Length > 0 && len != windowTitle.Length)
return true;

StringBuilder sb = new StringBuilder(len + 1);
GetWindowText(curr_hwnd, sb, sb.Capacity);
GetWindowText(currHwnd, sb, sb.Capacity);

uint proc_id;
GetWindowThreadProcessId(curr_hwnd, out proc_id);
uint currPid;
GetWindowThreadProcessId(currHwnd, out currPid);

if (proc_id == pid)
if (currPid == pid)
{
if (windowTitle.Length == 0)
hwnd = curr_hwnd;
hwnd = currHwnd;
else
{
if (sb.ToString() == windowTitle)
hwnd = curr_hwnd;
hwnd = currHwnd;
else return true;
}

Expand Down

0 comments on commit da9cc38

Please sign in to comment.