私はC#について少ししか知りません。私のコードのほとんどはグーグルから離れています。私がしようとしているのは、ウィンドウを移動することですSetWindowPos
. ただし、ウィンドウを部分的に画面の外に出したいのですが、Microsoft Windows では許可されていません。以下のコードは、これまでに取得したものです。もちろん、私はグーグルで答えを検索し、答えを見つけました。私が知らないのは、これを私のプログラムに入れる方法だけです。
これをアプリケーションにどのように組み込むかを誰かに説明してもらえますか?
Google の回答:ウィンドウを画面の上部から部分的に移動します
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);
}
}
}
}
}