I am creating a gesture system for the Kinect SDK in a C # / WPF application. I want to add a gesture to increase and decrease the magnifier. I would prefer to use the built-in Windows magnifier or its basic logic, but any way to get the same effect (with multiple monitors) will work.
How can I programmatically call windows magnifier scaling functions?
So far, the only thing I have found with hope is to start the process and press the button through Win32; but when I do this, it raises an empty blank window when I call the handle of the Magnifier window.
I linked this code together with a combination of what I know about C #, a bunch of Win32 API calls that I really don't know very well, and tons of Googling.
private void ZoomIn()
{
if (Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "magnify").Count() == 0) {
Process.Start("magnify.exe");
System.Threading.Thread.Sleep(500); }
IntPtr handle = Process.GetProcesses().Where(p => p.ProcessName.ToLower() == "magnify").First().Handle;
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
placement.length = Marshal.SizeOf(placement);
GetWindowPlacement(handle, ref placement);
MoveWindow(handle, new Point(0, 0));
if (placement.rcNormalPosition.Size.Width == 132) {
SetCursorPos(15, 15);
mouse_event((int)HardwareEvents.MouseLeftDown, 15, 15, 0, 0);
mouse_event((int)HardwareEvents.MouseLeftUp, 15, 15, 0, 0); }
SetCursorPos(25, 25);
mouse_event((int)HardwareEvents.MouseLeftDown, 25, 25, 0, 0);
mouse_event((int)HardwareEvents.MouseLeftUp, 25, 25, 0, 0);
}
private void MoveWindow(IntPtr handle, Point point)
{
SetWindowPos(handle, new IntPtr((int)SpecialWindowHandles.HWND_TOP), (int)point.X, (int)point.Y, 500, 500, SetWindowPosFlags.ShowWindow);
}
private struct WINDOWPLACEMENT {
public int length;
public int flags;
public int showCmd;
public System.Drawing.Point ptMinPosition;
public System.Drawing.Point ptMaxPosition;
public System.Drawing.Rectangle rcNormalPosition; }
[DllImport("user32.dll")]
static extern bool GetWindowPlacement(IntPtr hWnd, ref WINDOWPLACEMENT lpwndl);
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
public static class HardwareEvents
{
public static int MouseMove = 0x0001;
public static int MouseLeftDown = 0x0002, MouseLeftUp = 0x0004;
public static int MouseRightDown = 0x0008, MouseRightUp = 0x0010;
public static int MiddleMouseDown = 0x20, MiddleMouseUp = 0x40;
public static int MouseWheel = 0x800;
}