From 5b396acfc3967060dced7ebeacdad1c6421222a1 Mon Sep 17 00:00:00 2001 From: MaxXor Date: Mon, 27 Jul 2015 13:20:39 +0200 Subject: [PATCH] Fixed #295 --- Client/Core/Helper/ScreenHelper.cs | 5 ++--- Client/Core/Utilities/NativeMethods.cs | 17 +++++++---------- Server/Controls/ListViewEx.cs | 18 +++++++++++------- Server/Core/Utilities/NativeMethods.cs | 21 +++------------------ 4 files changed, 23 insertions(+), 38 deletions(-) diff --git a/Client/Core/Helper/ScreenHelper.cs b/Client/Core/Helper/ScreenHelper.cs index 5e1fd7fc..2938cbe1 100644 --- a/Client/Core/Helper/ScreenHelper.cs +++ b/Client/Core/Helper/ScreenHelper.cs @@ -12,18 +12,17 @@ namespace xClient.Core.Helper public static Bitmap CaptureScreen(int screenNumber) { Rectangle bounds = GetBounds(screenNumber); - IntPtr desktopHandle = NativeMethods.GetDesktopWindow(); Bitmap screen = new Bitmap(bounds.Width, bounds.Height); using (Graphics g = Graphics.FromImage(screen)) { IntPtr destDeviceContext = g.GetHdc(); - IntPtr srcDeviceContext = NativeMethods.GetWindowDC(desktopHandle); + IntPtr srcDeviceContext = NativeMethods.CreateDC("DISPLAY", null, null, IntPtr.Zero); NativeMethods.BitBlt(destDeviceContext, 0, 0, bounds.Width, bounds.Height, srcDeviceContext, bounds.X, bounds.Y, SRCCOPY); - NativeMethods.ReleaseDC(desktopHandle, srcDeviceContext); + NativeMethods.DeleteDC(srcDeviceContext); g.ReleaseHdc(destDeviceContext); } diff --git a/Client/Core/Utilities/NativeMethods.cs b/Client/Core/Utilities/NativeMethods.cs index ef6f6b0f..7f0b888f 100644 --- a/Client/Core/Utilities/NativeMethods.cs +++ b/Client/Core/Utilities/NativeMethods.cs @@ -4,7 +4,7 @@ using System.Runtime.InteropServices; namespace xClient.Core.Utilities { /// - /// Provides some methods from the "user32.dll" and uxtheme libraries. + /// Provides access to Win32 API and Microsoft C Runtime Library (msvcrt.dll). /// public static class NativeMethods { @@ -18,15 +18,6 @@ namespace xClient.Core.Utilities [DllImport("user32.dll")] public static extern void mouse_event(int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo); - [DllImport("user32.dll", SetLastError = false)] - public static extern IntPtr GetDesktopWindow(); - - [DllImport("user32.dll")] - public static extern IntPtr GetWindowDC(IntPtr hWnd); - - [DllImport("user32.dll")] - public static extern bool ReleaseDC(IntPtr hWnd, IntPtr hDC); - /// /// Performs a bit-block transfer of the color data corresponding to a /// rectangle of pixels from the specified source device context into @@ -48,6 +39,12 @@ namespace xClient.Core.Utilities [return: MarshalAs(UnmanagedType.Bool)] public static extern bool BitBlt([In] IntPtr hdc, int nXDest, int nYDest, int nWidth, int nHeight, [In] IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop); + [DllImport("gdi32.dll")] + public static extern IntPtr CreateDC(string lpszDriver, string lpszDevice, string lpszOutput, IntPtr lpInitData); + + [DllImport("gdi32.dll")] + public static extern bool DeleteDC([In] IntPtr hdc); + [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)] public static extern unsafe int memcmp(byte* ptr1, byte* ptr2, uint count); diff --git a/Server/Controls/ListViewEx.cs b/Server/Controls/ListViewEx.cs index e846aff4..ed171adf 100644 --- a/Server/Controls/ListViewEx.cs +++ b/Server/Controls/ListViewEx.cs @@ -7,9 +7,6 @@ namespace xServer.Controls { internal class AeroListView : ListView { - private const int LVS_EX_DOUBLEBUFFER = 0x10000; - private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 4150; - private const uint WM_CHANGEUISTATE = 0x127; private const int UIS_SET = 1; @@ -34,12 +31,19 @@ namespace xServer.Controls { base.OnHandleCreated(e); - if (!PlatformHelper.RunningOnMono && PlatformHelper.VistaOrHigher) + if (PlatformHelper.RunningOnMono) return; + + if (PlatformHelper.VistaOrHigher) { + // set window theme to explorer NativeMethods.SetWindowTheme(this.Handle, "explorer", null); - NativeMethods.SendMessage(this.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, new IntPtr(LVS_EX_DOUBLEBUFFER), - new IntPtr(LVS_EX_DOUBLEBUFFER)); - NativeMethods.SendMessage(this.Handle, WM_CHANGEUISTATE, NativeMethodsHelper.MakeLong(UIS_SET, UISF_HIDEFOCUS), 0); + } + + if (PlatformHelper.XpOrHigher) + { + // removes the ugly dotted line around focused item + NativeMethods.SendMessage(this.Handle, WM_CHANGEUISTATE, + NativeMethodsHelper.MakeLong(UIS_SET, UISF_HIDEFOCUS), 0); } } } diff --git a/Server/Core/Utilities/NativeMethods.cs b/Server/Core/Utilities/NativeMethods.cs index d2eb059d..98c26e4a 100644 --- a/Server/Core/Utilities/NativeMethods.cs +++ b/Server/Core/Utilities/NativeMethods.cs @@ -4,29 +4,14 @@ using System.Runtime.InteropServices; namespace xServer.Core.Utilities { /// - /// Provides some methods from the "user32.dll" and uxtheme libraries. + /// Provides access to Win32 API and Microsoft C Runtime Library (msvcrt.dll). /// public static class NativeMethods { - [DllImport("user32.dll", SetLastError = true)] + [DllImport("user32.dll")] public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam); - [DllImport("user32.dll", SetLastError = true)] - public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam); - - [DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)] - public static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, string lParam); - - [DllImport("user32.dll", SetLastError = true)] - public static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName); - - [DllImport("user32.dll", SetLastError = true)] - public static extern IntPtr SetCursor(IntPtr hCursor); - - [DllImport("user32.dll", SetLastError = true)] - public static extern IntPtr LoadImage(IntPtr hinst, string lpszName, uint uType, int cxDesired, int cyDesired, uint fuLoad); - - [DllImport("uxtheme.dll", CharSet = CharSet.Unicode, SetLastError = true)] + [DllImport("uxtheme.dll", CharSet = CharSet.Unicode)] public extern static int SetWindowTheme(IntPtr hWnd, string pszSubAppName, string pszSubIdList); [DllImport("msvcrt.dll", CallingConvention = CallingConvention.Cdecl)]