Unity 程序去边框并实现拖拽窗口
2017-06-19 16:48
405 查看
文章转自:http://blog.csdn.net/xu1989101/article/details/52620546
自己前一段时间一直查找相关资料、一直都没有,百度出来的都是一模一样的最大化、最小化、无边框的功能,就是没有拖拽的功能,自己搞定了就贴代码出来,省的其它程序员走弯路。
直接上代码,看注释。看不懂的就留言吧。
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using UnityEngine.UI;
public class popuxxx : MonoBehaviour {
public Rect screenPosition;
[DllImport("user32.dll")]
static extern IntPtr SetWindowLong (IntPtr hwnd,int _nIndex ,int dwNewLong);
[DllImport("user32.dll")]
static extern bool SetWindowPos (IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow ();
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
const int WS_POPUP = 0x800000;
const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活}
public void btn_onclick(){ //最小化
ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED );
}
public void btn_onclickxx(){ //最大化
ShowWindow(GetForegroundWindow(),SW_SHOWMAXIMIZED);
}
IntPtr Handle;
float xx;
bool bx;
void Start ()
{
bx = false;
xx = 0f;
#if UNITY_STANDALONE_WIN
Resolution[] r = Screen.resolutions;
screenPosition = new Rect ((r[r.Length-1].width-Screen.width)/2,(r[r.Length-1].height-Screen.height)/2,Screen.width,Screen.height);
SetWindowLong(GetForegroundWindow (), GWL_STYLE, WS_POPUP);//将网上的WS_BORDER替换成WS_POPUP
Handle = GetForegroundWindow (); //FindWindow ((string)null, "popu_windows");
SetWindowPos (GetForegroundWindow (), 0,(int)screenPosition.x,(int)screenPosition.y, (int)screenPosition.width,(int) screenPosition.height, SWP_SHOWWINDOW);
#endif
}
void Update(){
#if UNITY_STANDALONE_WIN
if (Input.GetMouseButtonDown (0)) {
xx =0f;
bx=true;
}
if(bx && xx>=0.3f ){ //这样做为了区分界面上面其它需要滑动的操作
ReleaseCapture();
SendMessage(Handle, 0xA1, 0x02, 0);
SendMessage(Handle, 0x0202, 0, 0);
}
if(bx)
xx +=Time.deltaTime;
if(Input.GetMouseButtonUp(0)){
xx =0f;
bx=false;
}
#endif
}
}
自己前一段时间一直查找相关资料、一直都没有,百度出来的都是一模一样的最大化、最小化、无边框的功能,就是没有拖拽的功能,自己搞定了就贴代码出来,省的其它程序员走弯路。
直接上代码,看注释。看不懂的就留言吧。
using UnityEngine;
using System.Collections;
using System;
using System.Runtime.InteropServices;
using UnityEngine.UI;
public class popuxxx : MonoBehaviour {
public Rect screenPosition;
[DllImport("user32.dll")]
static extern IntPtr SetWindowLong (IntPtr hwnd,int _nIndex ,int dwNewLong);
[DllImport("user32.dll")]
static extern bool SetWindowPos (IntPtr hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow ();
[DllImport("user32.dll")]
public static extern bool ReleaseCapture();
[DllImport("user32.dll")]
public static extern bool SendMessage(IntPtr hwnd, int wMsg, int wParam, int lParam);
[DllImport("user32.dll")]
public static extern bool ShowWindow(IntPtr hwnd, int nCmdShow);
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
const int WS_POPUP = 0x800000;
const int SW_SHOWMINIMIZED = 2; //{最小化, 激活}
const int SW_SHOWMAXIMIZED = 3; //{最大化, 激活}
public void btn_onclick(){ //最小化
ShowWindow(GetForegroundWindow(), SW_SHOWMINIMIZED );
}
public void btn_onclickxx(){ //最大化
ShowWindow(GetForegroundWindow(),SW_SHOWMAXIMIZED);
}
IntPtr Handle;
float xx;
bool bx;
void Start ()
{
bx = false;
xx = 0f;
#if UNITY_STANDALONE_WIN
Resolution[] r = Screen.resolutions;
screenPosition = new Rect ((r[r.Length-1].width-Screen.width)/2,(r[r.Length-1].height-Screen.height)/2,Screen.width,Screen.height);
SetWindowLong(GetForegroundWindow (), GWL_STYLE, WS_POPUP);//将网上的WS_BORDER替换成WS_POPUP
Handle = GetForegroundWindow (); //FindWindow ((string)null, "popu_windows");
SetWindowPos (GetForegroundWindow (), 0,(int)screenPosition.x,(int)screenPosition.y, (int)screenPosition.width,(int) screenPosition.height, SWP_SHOWWINDOW);
#endif
}
void Update(){
#if UNITY_STANDALONE_WIN
if (Input.GetMouseButtonDown (0)) {
xx =0f;
bx=true;
}
if(bx && xx>=0.3f ){ //这样做为了区分界面上面其它需要滑动的操作
ReleaseCapture();
SendMessage(Handle, 0xA1, 0x02, 0);
SendMessage(Handle, 0x0202, 0, 0);
}
if(bx)
xx +=Time.deltaTime;
if(Input.GetMouseButtonUp(0)){
xx =0f;
bx=false;
}
#endif
}
}
相关文章推荐
- Unity 去边框 并实现拖拽窗口
- 转:隐藏QT窗口边框 并且在隐藏后实现窗口拖拽
- 隐藏QT窗口边框 并且在隐藏后实现窗口拖拽 同时实现透明度
- 隐藏QT窗口边框 并且在隐藏后实现窗口拖拽 同时实现透明度
- <Qt C++>无边框窗口实现拖拽缩放
- Windows Form Tips: 无边框窗口实现用鼠标拖拽的功能
- QML实现的无边框窗口的拉伸,拖拽,基本解决闪烁严重问题
- [VC/MFC]一条语句实现程序运行时隐藏窗口
- 无边框窗口实现拖垃效果
- ajax中可拖拽窗口最简实现原理
- jQuery实现了一个拖拽小东西的程序
- 实现无标题栏但有边框的窗口
- javascript 实现WINDOWS 风格的可拖拽的DIV浮动窗口
- 在VC中实现全屏窗口程序
- 无边框窗口实现拖拉效果
- javascript应用:实现复选框全选/全不选切换,创建无边框的弹出窗口!
- 百度空间中实现拖拽、悬浮窗口效果的popup.js分析
- 〖原创〗如何实现程序自动关闭powerbuilder弹出的消息窗口?
- [VC/MFC]一条语句实现程序运行时隐藏窗口
- c#如何实现无标题栏窗口程序的移动?