Skip to content

Instantly share code, notes, and snippets.

@DenchiSoft
Created February 22, 2018 19:55
Show Gist options
  • Select an option

  • Save DenchiSoft/67066025dbfdbf89e4b07976fe6c3b8b to your computer and use it in GitHub Desktop.

Select an option

Save DenchiSoft/67066025dbfdbf89e4b07976fe6c3b8b to your computer and use it in GitHub Desktop.
Setting the window to consume or pass through clicks.
[DllImport("user32.dll", EntryPoint = "SetLayeredWindowAttributes")]
private static extern int SetLayeredWindowAttributes(IntPtr hwnd, int crKey, byte bAlpha, int dwFlags);
[DllImport("user32.dll")]
private static extern int SetWindowLong(IntPtr hWnd, int nIndex, uint dwNewLong);
// Sets window to pass through clicks.
private void SetInactive() {
    #if !UNITY_EDITOR
    SetWindowLong(hwnd, GWL_STYLE, WS_POPUP | WS_VISIBLE);
    SetWindowLong (hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW | WS_EX_LAYERED | WS_EX_TRANSPARENT); 
    SetLayeredWindowAttributes (hwnd, 0, 255, LWA_ALPHA);
    #endif
}
// Sets window to consume clicks.
private void SetActive() {
   #if !UNITY_EDITOR
    SetWindowLong (hwnd, GWL_EXSTYLE, WS_EX_TOOLWINDOW | ~((WS_EX_LAYERED) | (WS_EX_TRANSPARENT)));
    #endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment