我做了一个无边界窗口应用程序和一个“假”标题栏来拖动它。
我正在使用user32.dll,
这将启动窗口拖动(由unity ibegindraghandler触发):
public const int WM_NCLBUTTONDOWN = 0xA1;
public const int WM_NCLBUTTONUP = 0x00A2;
public const int WM_LBUTTONUP = 0x0202;
[DllImport("User32.dll")]
public static extern bool ReleaseCapture();
[DllImport("User32.dll")]
public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
IntPtr window = GetActiveWindow();
...
...
ReleaseCapture();
SendMessage(window, WM_NCLBUTTONDOWN, HTCAPTION, 0);
停止拖动(不确定此部分):
ReleaseCapture();
SendMessage(window, WM_NCLBUTTONUP, HTCAPTION, 0);
SendMessage(window, WM_LBUTTONUP, HTCAPTION, 0);
它在编辑器和构建上都很好,但在开发构建上会产生一个错误:
出现异常情况:playerloop内部函数
已递归调用。请与客户支持联系
示例项目,以便我们可以重现问题并进行故障排除
它。启动程序窗口:发送消息(intptr、int32、int32、int32)
启动程序窗口:startwindowdrag()(位于e:\ unity projects\crime club
launcher\assets\scripts\lib\launcher窗口.cs:115)
windowdragzone:unityengine.eventsystems.ibegindraghandler.onbegindrag(pointereventdata)
(位于E:\Unity Projects\Crime Club Launcher\Assets\WindowDragzone.cs:9)
unityEngine.eventSystems.executeEvents:执行(ibegindraghandler,
BaseEventData)(位于
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\executeevents.cs:64)
UnityEngine.EventSystems.ExecuteEvents:执行(游戏对象,
baseEventData,eventFunction`1)(位于
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\executeevents.cs:261)
UnityEngine.EventSystems.PointerinPutModule:进程拖动(PointerEventData)
(在
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\inputmodules\pointerinputmodule.cs:261)
unityengine.eventsystems.standaloneinputmodule:processmouseevent(int32)
(在
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\inputmodules\standaloneiniputmodule.cs:434)
unityEngine.eventSystems.StandaloneInputModule:processMouseEvent()(位于
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\inputmodules\standaloneiniputmodule.cs:412)
unityEngine.eventSystems.StandaloneInputModule:process()(位于
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\inputmodules\standaloneiniputmodule.cs:186)
unityEngine.eventSystems.eventSystem:update()(位于
C:\buildslave\unity\build\extensions\guisystem\unityengine.ui\eventsystem\eventsystem.cs:283)
你觉得这个怎么样?
编辑:
好吧,所以我最终通过替换
SendMessage(window, WM_NCLBUTTONDOWN, HTCAPTION, 0);
签署人:
private const int WM_SYSCOMMAND = 0x112;
private const int MOUSE_MOVE = 0xF012;
SendMessage(window, WM_SYSCOMMAND, MOUSE_MOVE, 0);
现在我有最后一个小问题:
鼠标释放时,窗口会被拖动或放下,但我看样子窗口会将焦点放在类似的东西上:
第一次点击总是错过,我必须点击两次才能再次拖动或简单地与Unity应用程序交互。
我尝试了onendrag中user32的函数:
显示窗口、设置活动窗口、设置焦点等…
我发现的一切都与这个问题有关,但它们都没有明显的效果,我仍然必须点击两次。
最佳答案
最后,通过将sendMessage()替换为:
SendMessageCallback(window, WM_SYSCOMMAND, MOUSE_MOVE, 0, WindowDropCallback, 0);