I need to eventually set the game screen to the topmost (foreground) window.
But my function does nothing (other user32.dll functions do work however)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
public class DatabaseManager : MonoBehaviour
{
//DLL imports
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool SetForegroundWindow(IntPtr hWnd);
static Process proc = Process.GetProcessesByName("firefox")[0];
IntPtr ptrFF = proc.Handle;
//------------------------------------------------------------------------
void Awake()
{
SetForegroundWindow(ptrFF);
}
//Other code functions like Update etc.
}
Nothing happens, no errors. Is there a way to force a window to the front