我对 c# 只知道一点点,而且我的大部分代码都来自谷歌。我正在尝试移动一个窗口,我通过使用SetWindowPos
. 但是,我希望窗口部分位于屏幕之外,但 Microsoft Windows 不允许。下面的代码是我到目前为止得到的。当然我在谷歌上搜索了答案,找到了答案,我唯一不知道的是如何将它放入我的程序中。
有人可以解释一下我将如何将其放入我的应用程序中吗?
谷歌回答:将窗口部分移出屏幕顶部
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Data;
using System.Runtime.InteropServices;
using System.Diagnostics;
namespace WindowMover
{
static class Logic
{
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int Y, int cx, int cy, int wFlags);
public static void Main()
{
const short SWP_NOSIZE = 1;
const short SWP_NOZORDER = 0X4;
const int SWP_NOACTIVATE = 0x0010;
Process[] processes = Process.GetProcesses("DeviceEmulator");
foreach (var process in processes)
{
if (process.ProcessName == "DeviceEmulator")
{
var handle = process.MainWindowHandle;
SetWindowPos(handle, 0, 0, 0, -100, -100, SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE);
}
}
}
}
}