using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class C {
public delegate bool WNDENUMPROC(IntPtr hwnd, uint lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, uint lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId);
[DllImport("kernel32.dll")]
public static extern void SetLastError(uint dwErrCode);
public static IntPtr GetProcessWnd()
{
IntPtr ptrWnd = IntPtr.Zero;
uint pid = (uint)Process.GetCurrentProcess().Id; // 当前进程 ID
bool bResult = EnumWindows(new WNDENUMPROC(delegate (IntPtr hwnd, uint lParam)
{
uint
Unity3D 获取主窗口句柄
最新推荐文章于 2023-03-03 18:51:37 发布
本文介绍了一个使用C#和DllImport调用Windows API的方法,在Unity3D中获取主窗口句柄。通过EnumWindows、GetParent、GetWindowThreadProcessId等函数,遍历并检查窗口句柄,匹配当前进程ID,最终找到并返回主窗口句柄。
摘要由CSDN通过智能技术生成