0
我只知道一些关于c#的知识,我的大部分代码都是关闭的。我正在尝试的是移动一个窗口,我通过使用SetWindowPos
得到了这个工作。但是,我希望窗口局部在屏幕外,但Microsoft Windows不允许。下面的代码是我到目前为止。当然,我在谷歌搜索答案,并找到答案,我不知道唯一的是如何把这个到我的程序。SetWindowPos在屏幕外
有人可以解释我如何将它放入我的应用程序?
谷歌回答:Move a window partially off the top of the screen
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);
}
}
}
}
}
你的代码没有意义,你试图给窗口一个负面的大小。这当然不可能。然后指定SWP_NOSIZE告诉SetWindowPos()它不应该改变大小。改变位置。不要通过(0,0),将它放在屏幕的左上角,按照定义,不要部分地离开屏幕。 – 2013-02-22 02:05:14
谢谢,这至少解决了一个谜团! – user2097402 2013-02-22 10:19:24