查看: 1190|回复: 0
打印 上一主题 下一主题

[其他] unity win10 打包置顶隐藏鼠标

[复制链接]
may    

8830

主题

81

听众

7万

积分

首席设计师

Rank: 8Rank: 8

纳金币
52344
精华
343

最佳新人 热心会员 灌水之王 活跃会员 突出贡献 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2019-10-29 01:22:23 |只看该作者 |倒序浏览
来自:504337179

闲着没事,发一些通用脚本把,此脚本可以置顶程序,输出运行后置顶,无法切换,默认隐藏鼠标 按c 显示鼠标
特别实用.
  1. using System;
  2. using System.Runtime.Interopservices;
  3. using UnityEngine;

  4. public class myWindowMod : MonoBehaviour
  5. {
  6.     public string appName;
  7.     public Rect screenPosition;
  8.     // [DllImport("user32.dll")]
  9.     // static extern IntPtr SetWindowLong(IntPtr hwnd, int _nIndex, int dwNewLong);
  10.     [DllImport("user32.dll")]
  11.     static extern bool SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
  12.     [DllImport("user32.dll")]
  13.     static extern IntPtr GetForegroundWindow();
  14.     // not used rigth now
  15.     [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
  16.     static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
  17.     const uint SWP_SHOWWINDOW = 0x0040;
  18.     [DllImport("user32.dll")]
  19.     public static extern IntPtr FindWindowEx(IntPtr parent, IntPtr childe, string strclass, string strname);

  20.     [Flags]
  21.     public enum SetWindowPosFlags : uint
  22.     {
  23.         // ReSharper disable InconsistentNaming

  24.         /// <summary>
  25.         /// If the calling thread and the thread that owns the window are attached to different input queues, the system posts the request to the thread that owns the window. This prevents the calling thread from blocking its execution while other threads process the request.
  26.         /// </summary>
  27.         SWP_ASYNCWINDOWPOS = 0x4000,

  28.         /// <summary>
  29.         /// Prevents generation of the WM_SYNCPAINT message.
  30.         /// </summary>
  31.         SWP_DEFERERASE = 0x2000,

  32.         /// <summary>
  33.         /// Draws a frame (defined in the window's class description) around the window.
  34.         /// </summary>
  35.         SWP_DRAWFRAME = 0x0020,

  36.         /// <summary>
  37.         /// Applies new frame styles set using the SetWindowLong function. Sends a WM_NCCALCSIZE message to the window, even if the window's size is not being changed. If this flag is not specified, WM_NCCALCSIZE is sent only when the window's size is being changed.
  38.         /// </summary>
  39.         SWP_FRAMECHANGED = 0x0020,

  40.         /// <summary>
  41.         /// Hides the window.
  42.         /// </summary>
  43.         SWP_HIDEWINDOW = 0x0080,

  44.         /// <summary>
  45.         /// Does not activate the window. If this flag is not set, the window is activated and moved to the top of either the topmost or non-topmost group (depending on the setting of the hWndInsertAfter parameter).
  46.         /// </summary>
  47.         SWP_NOACTIVATE = 0x0010,

  48.         /// <summary>
  49.         /// Discards the entire contents of the client area. If this flag is not specified, the valid contents of the client area are saved and copied back into the client area after the window is sized or repositioned.
  50.         /// </summary>
  51.         SWP_NOCOPYBITS = 0x0100,

  52.         /// <summary>
  53.         /// Retains the current position (ignores X and Y parameters).
  54.         /// </summary>
  55.         SWP_NOMOVE = 0x0002,

  56.         /// <summary>
  57.         /// Does not change the owner window's position in the Z order.
  58.         /// </summary>
  59.         SWP_NOOWNERZORDER = 0x0200,

  60.         /// <summary>
  61.         /// Does not redraw changes. If this flag is set, no repainting of any kind occurs. This applies to the client area, the nonclient area (including the title bar and scroll bars), and any part of the parent window uncovered as a result of the window being moved. When this flag is set, the application must explicitly invalidate or redraw any parts of the window and parent window that need redrawing.
  62.         /// </summary>
  63.         SWP_NOREDRAW = 0x0008,

  64.         /// <summary>
  65.         /// Same as the SWP_NOOWNERZORDER flag.
  66.         /// </summary>
  67.         SWP_NOREPOSITION = 0x0200,

  68.         /// <summary>
  69.         /// Prevents the window from receiving the WM_WINDOWPOSCHANGING message.
  70.         /// </summary>
  71.         SWP_NOSENDCHANGING = 0x0400,

  72.         /// <summary>
  73.         /// Retains the current size (ignores the cx and cy parameters).
  74.         /// </summary>
  75.         SWP_NOSIZE = 0x0001,

  76.         /// <summary>
  77.         /// Retains the current Z order (ignores the hWndInsertAfter parameter).
  78.         /// </summary>
  79.         SWP_NOZORDER = 0x0004,

  80.         /// <summary>
  81.         /// Displays the window.
  82.         /// </summary>
  83.         SWP_SHOWWINDOW = 0x0040,

  84.         // ReSharper restore InconsistentNaming
  85.     }

  86.     static readonly IntPtr HWND_TOP = new IntPtr(0);

  87.     private const int GWL_STYLE = (-16);
  88.     public const int WS_CAPTION = 0xC00000;
  89.     const uint SWP_NOMOVE = 0x2;

  90.     const uint SWP_NOSIZE = 1;
  91.     [DllImport("User32.dll", CharSet = CharSet.Auto)]
  92.     public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
  93.     string curpath;
  94.     IntPtr p;

  95.     void Start()
  96.     {
  97.         Application.targetFrameRate = 30;
  98.         Cursor.visible = false;
  99.         // string fileAddress = Application.dataPath + "/FileOperation.txt";
  100.         // curpath = Directory.GetCurrentDirectory();
  101.         // StreamReader sr1 = File.OpenText(curpath + @"\xx.txt");
  102.         // string linew1 = sr1.ReadToEnd();
  103.         // myplay = linew1.TrimEnd('\r', '\n');
  104.         // int xx = int.Parse(linew1.TrimEnd('\r', '\n'));
  105.         // sr1.Close();

  106.         // StreamReader sr2 = File.OpenText(curpath + @"\yy.txt");
  107.         // string linew2 = sr2.ReadToEnd();
  108.         // mystop = linew2.TrimEnd('\r', '\n');
  109.         // int yy = int.Parse(linew2.TrimEnd('\r', '\n'));
  110.         // sr2.Close();

  111.         // StreamReader sr3 = File.OpenText(curpath + @"\width.txt");
  112.         // string linew3 = sr3.ReadToEnd();
  113.         // mystop = linew2.TrimEnd('\r', '\n');
  114.         // int wid = int.Parse(linew3.TrimEnd('\r', '\n'));
  115.         // sr3.Close();

  116.         // StreamReader sr4 = File.OpenText(curpath + @"\height.txt");
  117.         // string linew4 = sr4.ReadToEnd();
  118.         // mystop = linew2.TrimEnd('\r', '\n');
  119.         // int hei = int.Parse(linew4.TrimEnd('\r', '\n'));
  120.         // sr4.Close();


  121.         p = FindWindowEx(IntPtr.Zero, IntPtr.Zero, null, appName);
  122.         // SetWindowLong(GetForegroundWindow(), GWL_STYLE, 369164288);
  123.         // SetWindowLong(this.Handle, -16, 369164288);

  124.         Screen.SetResolution((int)screenPosition.width, (int)screenPosition.height, false);
  125.         SetWindowPos(p, -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);

  126.         SetWindowLong(p, -16, 369164288);

  127.         // SetWindowPos(p, 0, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_NOMOVE | SWP_NOSIZE);

  128.         // SetWindowLong(p, GWL_STYLE, GetWindowLong(3, GWL_STYLE )& ~WS_CAPTION).ToString();
  129.         // SetWindowPos(p, HWND_TOP, 0, 0, 0, 0, SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_FRAMECHANGED);
  130.     }
  131.     void Update()
  132.     {
  133.         SetWindowPos(p, -1, (int)screenPosition.x, (int)screenPosition.y, (int)screenPosition.width, (int)screenPosition.height, SWP_SHOWWINDOW);
  134.         SetWindowLong(p, -16, 369164288);

  135.         if (Input.GetKeyDown(KeyCode.C))
  136.         {
  137.             var v = Cursor.visible;
  138.             Cursor.visible = !v;
  139.         }
  140.     }
  141. }
复制代码
脚本挂载在任意位置
app Name 为productname
这个一定要输对,不然无法置顶


分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2025-2-24 18:21 , Processed in 0.077790 second(s), 29 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部