I'm trying to write a simple thing that prevents a third party application from being able to minimize. I'm going to use EasyHook as I think that's the easiest way of doing this.
My code is going to be in C#. I've been looking at the examples in the EasyHook repo, I'm just not sure which windows function I need to replace to achieve this.
Or if there is another way of doing this that would be good too.
Example (not working):
Program.cs
using System;
using System.Text.RegularExpressions;
using EasyHook;
namespace AutoMaximize
{
internal class Program
{
private static void Main(string[] args)
{
WindowFinder wf = new WindowFinder();
PInvoke.HWND hwnd = new PInvoke.HWND();
wf.FindWindows(
new PInvoke.HWND(),
new Regex(@"Notepad\+\+"),
null,
null,
delegate(PInvoke.HWND wnd)
{
hwnd = wnd;
return true;
});
uint processId = 0;
PInvoke.GetWindowThreadProcessId(hwnd, out processId);
try
{
RemoteHooking.Inject((int) processId, InjectionOptions.Default, "AutoMaximizeInject_x86.dll", "AutoMaximizeInject_x64.dll");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
}
}
AutoMaximizeInject.cs
using System;
using EasyHook;
namespace AutoMaximize
{
public class AutoMaximizeInject : IEntryPoint
{
#region Delegates
public delegate int DShowWindow(IntPtr hWnd, int nCmdShow);
#endregion
public LocalHook ShowWindowHook = null;
public AutoMaximizeInject(RemoteHooking.IContext inContext, string inChannelName) { }
public void Run(RemoteHooking.IContext inContext, string inArg)
{
try
{
ShowWindowHook = LocalHook.Create(LocalHook.GetProcAddress("user32.dll", "ShowWindow"), new DShowWindow(ShowWindowHooked), this);
/*
* Don't forget that all hooks will start deaktivated...
* The following ensures that all threads are intercepted:
*/
ShowWindowHook.ThreadACL.SetExclusiveACL(new Int32[1]);
}
catch (Exception)
{
}
}
public static int ShowWindowHooked(IntPtr hWnd, int nCmdShow)
{
try
{
switch (nCmdShow)
{
case PInvoke.SW_FORCEMINIMIZE:
case PInvoke.SW_HIDE:
case PInvoke.SW_MAXIMIZE:
case PInvoke.SW_MINIMIZE:
case PInvoke.SW_NORMAL:
case PInvoke.SW_RESTORE:
case PInvoke.SW_SHOW:
case PInvoke.SW_SHOWDEFAULT:
case PInvoke.SW_SHOWMINIMIZED:
case PInvoke.SW_SHOWMINNOACTIVE:
case PInvoke.SW_SHOWNA:
case PInvoke.SW_SHOWNOACTIVATE:
case PInvoke.SW_SMOOTHSCROLL:
nCmdShow = PInvoke.SW_MAXIMIZE;
break;
}
}
catch (Exception)
{
}
return PInvoke.ShowWindow(hWnd, nCmdShow);
}
}
}
Now the PInvoke stuff I'm not listing I know works I use it in other programs. The current issue is a crash down in the EasyHook.WOW64Bypass.Install() function the process it tries to run "EasyHook64Svc.exe" is crashing out.
I'm not sure if I did something wrong or if this is a EasyHook error. If someone could let know which it is that'd help a lot.