Skip to content

Commit

Permalink
Pull request していただいたコードを整理。
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowMage committed Jan 17, 2015
1 parent 7909f30 commit b35b379
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 52 deletions.
1 change: 1 addition & 0 deletions OverlayPlugin.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Files", "Files", "{84CCF15D
full.exclude = full.exclude
LICENSE.txt = LICENSE.txt
PS-Zip.psm1 = PS-Zip.psm1
README-en.md = README-en.md
README.md = README.md
EndProjectSection
EndProject
Expand Down
46 changes: 44 additions & 2 deletions OverlayPlugin/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,58 @@ public static extern IntPtr CreateDIBSection(

public const int DIB_RGB_COLORS = 0x0000;

[DllImport("user32.dll")]
[DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)]
public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);

[DllImport("user32.dll")]
[DllImport("user32.dll", EntryPoint = "GetWindowLong", SetLastError = true)]
public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

public const int GWL_EXSTYLE = -20;
public const int WS_EX_TRANSPARENT = 0x00000020;
public const int WS_EX_TOOLWINDOW = 0x00000080;

[DllImport("kernel32")]
public static extern void CopyMemory(IntPtr dest, IntPtr src, uint count);


// For hide from ALT+TAB preview

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
public static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
public static extern void SetLastError(int dwErrorCode);

private static int ToIntPtr32(IntPtr intPtr)
{
return unchecked((int)intPtr.ToInt64());
}

public static IntPtr SetWindowLongA(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
int error = 0;
IntPtr result = IntPtr.Zero;

SetLastError(0);

if (IntPtr.Size == 4)
{
Int32 result32 = SetWindowLong(hWnd, nIndex, ToIntPtr32(dwNewLong));
error = Marshal.GetLastWin32Error();
result = new IntPtr(result32);
}
else
{
result = SetWindowLongPtr(hWnd, nIndex, dwNewLong);
error = Marshal.GetLastWin32Error();
}

if ((result == IntPtr.Zero) && (error != 0))
{
throw new System.ComponentModel.Win32Exception(error);
}

return result;
}
}
}
3 changes: 2 additions & 1 deletion OverlayPlugin/OverlayForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ public OverlayForm(string url, int maxFrameRate = 30)

this.url = url;

Util.Hide(this);
// Alt+Tab を押したときに表示されるプレビューから除外する
Util.HidePreview(this);
}

public void Reload()
Expand Down
2 changes: 1 addition & 1 deletion OverlayPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.3.1")]
[assembly: AssemblyVersion("0.2.4.0")]
52 changes: 4 additions & 48 deletions OverlayPlugin/Util.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,55 +40,11 @@ public static bool IsOnScreen(Form form)
return false;
}

[DllImport("user32.dll")]
public static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);

[DllImport("user32.dll", EntryPoint = "SetWindowLongPtr", SetLastError = true)]
private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong);

[DllImport("user32.dll", EntryPoint = "SetWindowLong", SetLastError = true)]
private static extern Int32 SetWindowLong(IntPtr hWnd, int nIndex, Int32 dwNewLong);

[DllImport("kernel32.dll", EntryPoint = "SetLastError")]
public static extern void SetLastError(int dwErrorCode);

private static int ptr32(IntPtr intPtr)
{
return unchecked((int)intPtr.ToInt64());
}

public static IntPtr SetWindowLongA(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
{
int error = 0;
IntPtr result = IntPtr.Zero;

SetLastError(0);

if (IntPtr.Size == 4)
{
Int32 result32 = SetWindowLong(hWnd, nIndex, ptr32(dwNewLong));
error = Marshal.GetLastWin32Error();
result = new IntPtr(result32);
}
else
{
result = SetWindowLongPtr(hWnd, nIndex, dwNewLong);
error = Marshal.GetLastWin32Error();
}

if ((result == IntPtr.Zero) && (error != 0))
{
throw new System.ComponentModel.Win32Exception(error);
}

return result;
}

public static void Hide(System.Windows.Forms.Form form)
public static void HidePreview(System.Windows.Forms.Form form)
{
int ex = (int)GetWindowLong(form.Handle, (int)(-20));
ex |= (int)(0x00000080);
SetWindowLongA(form.Handle, (int)(-20), (IntPtr)ex);
int ex = NativeMethods.GetWindowLong(form.Handle, NativeMethods.GWL_EXSTYLE);
ex |= NativeMethods.WS_EX_TOOLWINDOW;
NativeMethods.SetWindowLongA(form.Handle, NativeMethods.GWL_EXSTYLE, (IntPtr)ex);
}
}
}

0 comments on commit b35b379

Please sign in to comment.