Commit bb38297d authored by mercury233's avatar mercury233

add windows resize and maximize, fix GetProcessWnd

parent 49a92472
......@@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using UnityEngine;
using YGOSharp.OCGWrapper.Enums;
......@@ -11,31 +12,45 @@ public static class UIHelper
[DllImport("user32.dll")]
static extern bool FlashWindow(IntPtr handle, bool invert);
public delegate bool WNDENUMPROC(IntPtr hwnd, uint lParam);
public delegate bool WNDENUMPROC(IntPtr hwnd, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, uint lParam);
static extern bool EnumWindows(WNDENUMPROC lpEnumFunc, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref uint lpdwProcessId);
static extern uint GetWindowThreadProcessId(IntPtr hWnd, ref IntPtr lpdwProcessId);
[DllImport("user32.dll")]
static extern int GetClassNameW(IntPtr hWnd, [MarshalAs(UnmanagedType.LPWStr)]StringBuilder lpString, int nMaxCount);
[DllImport("user32.dll")]
static extern bool IsZoomed(IntPtr hWnd);
[DllImport("user32.dll")]
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
[DllImport("kernel32.dll")]
static extern void SetLastError(uint dwErrCode);
static IntPtr myHWND = IntPtr.Zero;
static IntPtr GetProcessWnd()
{
if (myHWND != IntPtr.Zero)
return myHWND;
IntPtr ptrWnd = IntPtr.Zero;
uint pid = (uint)System.Diagnostics.Process.GetCurrentProcess().Id; // 当前进程 ID
IntPtr pid = (IntPtr)System.Diagnostics.Process.GetCurrentProcess().Id; // 当前进程 ID
bool bResult = EnumWindows(new WNDENUMPROC(delegate (IntPtr hwnd, uint lParam)
bool bResult = EnumWindows(new WNDENUMPROC(delegate (IntPtr hwnd, IntPtr mypid)
{
uint id = 0;
IntPtr id = IntPtr.Zero;
StringBuilder ClassName = new StringBuilder(256);
GetClassNameW(hwnd, ClassName, ClassName.Capacity);
if (GetParent(hwnd) == IntPtr.Zero)
if (string.Compare(ClassName.ToString(), "UnityWndClass", true, System.Globalization.CultureInfo.InvariantCulture) == 0)
{
GetWindowThreadProcessId(hwnd, ref id);
if (id == lParam) // 找到进程对应的主窗口句柄
if (id == mypid) // 找到进程对应的主窗口句柄
{
ptrWnd = hwnd; // 把句柄缓存起来
SetLastError(0); // 设置无错误
......@@ -47,7 +62,12 @@ public static class UIHelper
}), pid);
return (!bResult && Marshal.GetLastWin32Error() == 0) ? ptrWnd : IntPtr.Zero;
if (!bResult && Marshal.GetLastWin32Error() == 0)
{
myHWND = ptrWnd;
}
return myHWND;
}
public static void Flash()
......@@ -55,6 +75,35 @@ public static class UIHelper
FlashWindow(GetProcessWnd(),true);
}
public static bool isMaximized()
{
#if UNITY_STANDALONE_WIN
return IsZoomed(GetProcessWnd());
#else
// not a easy thing to check window status on non-windows desktop...
return false;
#endif
}
public static void MaximizeWindow()
{
#if UNITY_STANDALONE_WIN
ShowWindow(GetProcessWnd(), 3); // SW_MAXIMIZE
#endif
}
public static void RestoreWindow()
{
#if UNITY_STANDALONE_WIN
ShowWindow(GetProcessWnd(), 9); // SW_RESTORE
#endif
}
public static bool shouldMaximize()
{
return fromStringToBool(Config.Get("maximize_", "0"));
}
public enum RenderingMode
{
Opaque,
......
......@@ -926,6 +926,8 @@ public class Program : MonoBehaviour
{
preWid = Screen.width;
preheight = Screen.height;
//if (setting != null)
// setting.setScreenSizeValue();
Program.notGo(fixScreenProblems);
Program.go(500, fixScreenProblems);
}
......@@ -939,6 +941,10 @@ public class Program : MonoBehaviour
void gameStart()
{
if (UIHelper.shouldMaximize())
{
UIHelper.MaximizeWindow();
}
backGroundPic.show();
shiftToServant(menu);
}
......
......@@ -15,7 +15,6 @@ public class Setting : WindowServant2D
UIHelper.registEvent(gameObject, "full_", resizeScreen);
UIHelper.registEvent(gameObject, "resize_", resizeScreen);
UIHelper.getByName<UIToggle>(gameObject, "full_").value = Screen.fullScreen;
UIHelper.getByName<UIPopupList>(gameObject, "screen_").value = Screen.width.ToString() + "*" + Screen.height.ToString();
UIHelper.getByName<UIToggle>(gameObject, "ignoreWatcher_").value = UIHelper.fromStringToBool(Config.Get("ignoreWatcher_", "0"));
UIHelper.getByName<UIToggle>(gameObject, "ignoreOP_").value = UIHelper.fromStringToBool(Config.Get("ignoreOP_", "0"));
UIHelper.getByName<UIToggle>(gameObject, "smartSelect_").value = UIHelper.fromStringToBool(Config.Get("smartSelect_", "1"));
......@@ -74,6 +73,7 @@ public class Setting : WindowServant2D
UIHelper.registEvent(setting.Vlink.gameObject, onCP);
onchangeMouse();
onchangeCloud();
setScreenSizeValue();
}
private void readVales()
......@@ -103,6 +103,14 @@ public class Setting : WindowServant2D
Program.I().mouseParticle.SetActive(setting.mouseEffect.value);
}
//private int dontResizeTwice = 2;
public void setScreenSizeValue()
{
//dontResizeTwice = 3;
UIHelper.getByName<UIPopupList>(gameObject, "screen_").value = Screen.width.ToString() + "*" + Screen.height.ToString();
}
void onCP()
{
try
......@@ -202,6 +210,14 @@ public class Setting : WindowServant2D
void resizeScreen()
{
//if (dontResizeTwice > 0)
//{
// dontResizeTwice--;
// return;
//}
//dontResizeTwice = 2;
if (UIHelper.isMaximized())
UIHelper.RestoreWindow();
string[] mats = UIHelper.getByName<UIPopupList>(gameObject, "screen_").value.Split(new string[] { "*" }, StringSplitOptions.RemoveEmptyEntries);
if (mats.Length == 2)
{
......@@ -227,6 +243,7 @@ public class Setting : WindowServant2D
Config.Set("showoffATK", setting.showoffATK.value.ToString());
Config.Set("showoffStar", setting.showoffStar.value.ToString());
Config.Set("resize_", UIHelper.fromBoolToString(UIHelper.getByName<UIToggle>(gameObject, "resize_").value));
Config.Set("maximize_", UIHelper.fromBoolToString(UIHelper.isMaximized()));
}
public void save()
......
......@@ -15,7 +15,7 @@ PlayerSettings:
defaultCursor: {fileID: 0}
cursorHotspot: {x: 0, y: 0}
m_SplashScreenBackgroundColor: {r: 0.13333334, g: 0.17254902, b: 0.21176471, a: 1}
m_ShowUnitySplashScreen: 1
m_ShowUnitySplashScreen: 0
m_ShowUnitySplashLogo: 1
m_SplashScreenOverlayOpacity: 1
m_SplashScreenAnimation: 1
......@@ -76,7 +76,7 @@ PlayerSettings:
usePlayerLog: 1
bakeCollisionMeshes: 0
forceSingleInstance: 0
resizableWindow: 0
resizableWindow: 1
useMacAppStoreValidation: 0
macAppStoreCategory: public.app-category.games
gpuSkinning: 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment