- Home /
Winapi suddenly causes problem to open game build
I am developing a MOBA like game and i want to make its client windowed and borderless (using external user32.dll). It worked fine until it suddenly stopped, with just one build i get window looking like this:
instead of: http://i.imgur.com/w4oNrZ6.jpg
Here's the code that should (and did for some time) do the work:
using UnityEngine;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using UnityEngine.UI;
public class WindowHandler : MonoBehaviour
{
private 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")]
static extern bool GetCursorPos(out POINT mousePoint);
[StructLayout(LayoutKind.Sequential)]
public struct POINT
{
public int MouseX;
public int MouseY;
public static implicit operator Point(POINT point)
{
return new Point(point.MouseX, point.MouseY);
}
}
const uint SWP_SHOWWINDOW = 0x0040;
const int GWL_STYLE = -16;
const int WS_BORDER = 1;
private const int width = 1380;
private const int height = 780;
private Vector2 ClickPos;
private Vector2 MousePos;
private Vector2 WindowPos;
public static Point GetCursorPosition()
{
POINT Point;
GetCursorPos(out Point);
return Point;
}
void Start()
{
ScreenPosition.width = width;
ScreenPosition.height = height;
ScreenPosition.x = 270;
ScreenPosition.y = 150;
SetWindowLong(GetForegroundWindow(), GWL_STYLE, WS_BORDER);
bool result = SetWindowPos(GetForegroundWindow(), 0, (int)ScreenPosition.x, (int)ScreenPosition.y, (int)ScreenPosition.width, (int)ScreenPosition.height, SWP_SHOWWINDOW);
}
void Update()
{
Ray Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
RaycastHit RaycastHit;
if (Physics.Raycast(Ray, out RaycastHit))
{
if (RaycastHit.collider.name == "Window")
{
if (Input.GetMouseButtonDown(0))
{
ClickPos.x = GetCursorPosition().X;
ClickPos.y = GetCursorPosition().Y;
//ScreenPosition.x = WindowPos.x;
//ScreenPosition.y = WindowPos.y;
}
if (Input.GetMouseButton(0))
{
MousePos.x = GetCursorPosition().X;
MousePos.y = GetCursorPosition().Y;
WindowPos.x = ScreenPosition.x + MousePos.x - ClickPos.x;
WindowPos.y = ScreenPosition.y + MousePos.y - ClickPos.y;
SetWindowPos(GetForegroundWindow(), 0, (int)WindowPos.x, (int)WindowPos.y, (int)ScreenPosition.width, (int)ScreenPosition.height, SWP_SHOWWINDOW);
}
}
}
}
}
It has to be problem with my PC, cause when i run this build on another PC it works fine, and i dont really have a clue how to fix it. Thanks in advance.
Fixed by using windows update -> every update related to visual studio.
Again the same problem when i open up the project after few days, anyone know what is happening?
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Shaders do not work in build. 0 Answers
Why do static lightmapped objects in my windows build appear washed out? 0 Answers
Unity IL2CPP 0 Answers
Webgl build on new project = error 1 Answer