大概很少有人需要这种需求吧,不废话,贴代码.
using UnityEngine;
using System.Runtime.InteropServices;
using System;
public class WinAPITest : MonoBehaviour {
[DllImport("user32.dll")]
private static extern IntPtr GetActiveWindow();
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
const int WM_SYSCOMMAND = 0x0112;
const int SC_MOVE = 0xF010;
const int HTCAPTION = 0x0002;
IntPtr hwnd;
void Start() {
hwnd = GetActiveWindow();
}
void Update () {
ReleaseCapture();
SendMessage(hwnd, WM_SYSCOMMAND, SC_MOVE + HTCAPTION, 0);
}
}