Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Bartosz Klimowicz · Apr 10, 2016 at 11:55 AM · buildbug

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: alt text

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.

capture1.png (81.9 kB)
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bartosz Klimowicz · Apr 11, 2016 at 07:14 AM 0
Share

Fixed by using windows update -> every update related to visual studio.

avatar image Bartosz Klimowicz · Apr 16, 2016 at 11:04 AM 0
Share

Again the same problem when i open up the project after few days, anyone know what is happening?

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges