gpt4 book ai didi

c# - 调用 Windows 放大镜

转载 作者:太空狗 更新时间:2023-10-29 23:41:33 31 4
gpt4 key购买 nike

我正在 C#/WPF 应用程序中为 Kinect SDK 构建手势系统。我想添加放大镜放大和缩小的手势。我更愿意使用内置的 Windows 放大镜或其底层逻辑,但任何获得类似效果(多显示器感知)的方法都可以。

如何以编程方式调用 Windows 放大镜的缩放功能?

到目前为止,我发现唯一有希望的是启动进程并通过 Win32 单击按钮;但是当我这样做时,当我调用放大镜窗口的句柄时,它会拉出一个空白的空窗口。

我通过结合我对 C# 的了解、一堆我不太了解的 Win32 API 调用以及大量谷歌搜索,将这段代码拼凑在一起。

private void ZoomIn()
{
// Make sure the Magnifier is running, and get its handle
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;

// Figure out what size ("mode") it's in
WINDOWPLACEMENT placement = new WINDOWPLACEMENT();
placement.length = Marshal.SizeOf(placement);
GetWindowPlacement(handle, ref placement);

// Move the Magnifier to a predetermined location so we know where to click
MoveWindow(handle, new Point(0, 0));

// If Magnifier is in small mode, click it to put it in big mode.
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); }

// Click the zoom in button. Yeah, I know, hackish. Isn't Win32 awesome?
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)
{
// TODO: Figure out how to look up the target window's size
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; // best guess on the 0010
public static int MiddleMouseDown = 0x20, MiddleMouseUp = 0x40;
public static int MouseWheel = 0x800;
}

最佳答案

已解决。此代码发送 Win + 击键。

        keybd_event(0x5B, 0x45, 0, new UIntPtr(0));
keybd_event(0xBB, 0x45, 1, new UIntPtr(0));

http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx

关于c# - 调用 Windows 放大镜,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6418520/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com