OSDN Git Service

AppliStation-GUI,ListViewのちらつき防止。
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / NativeMethods.cs
index 5cdd40a..36481b0 100644 (file)
@@ -16,7 +16,7 @@ namespace AppliStation.Util
                {\r
                }\r
                \r
-               \r
+\r
                /// <summary>\r
                /// WindowsVista向け、プログレスバーステータス(色)を設定する\r
                /// </summary>\r
@@ -103,6 +103,41 @@ namespace AppliStation.Util
                \r
                #endregion\r
                \r
+               #region ListView関連\r
+               \r
+               /// <summary>\r
+               /// リストビューにダブルバッファでの描画をするか否かを設定する\r
+               /// </summary>\r
+               /// <remarks>マウスでの選択に半透明ツールを採用するか否かもこの設定に依存</remarks>\r
+               /// <param name="listView">対象のリストビュー</param>\r
+               /// <param name="bEnable">ダブルバッファでの描画をするとき<code>true</code></param>\r
+               public static void ListView_SetDoubleBuffer(ListView listView, bool bEnable)\r
+               {\r
+                       try {\r
+                               // SendMessage(listView.Handle, LVM_SETEXTENDEDLISTVIEWSTYLE, LVS_EX_DOUBLEBUFFER, bEnable? LVS_EX_DOUBLEBUFFER:0);\r
+                               SendMessage(listView.Handle, 0x1036, 0x00010000, ((bEnable)? 0x00010000u:0x0u));\r
+                       } catch (Exception) {\r
+                       }\r
+               }\r
+               \r
+               /// <summary>\r
+               /// 選択されたアイテムの部分の背景にグラデーションがかかった感じになる、\r
+               /// Vista以降でのエクスプローラの見た目をListViewに反映させる。\r
+               /// </summary>\r
+               /// <remarks>Vista未満のバージョンでは何もしない。</remarks>\r
+               /// <param name="listView">対象のListView</param>\r
+               public static void ListView_EnableVistaExplorerTheme(ListView listView)\r
+               {\r
+                       // Vista未満はなにもしない\r
+                       OperatingSystem os = Environment.OSVersion;\r
+                       if (os.Platform != PlatformID.Win32NT || os.Version.Major < 6) return;\r
+                       \r
+                       try {\r
+                               SetWindowTheme(listView.Handle, "explorer", null);\r
+                       } catch (Exception) {\r
+                       }\r
+               }\r
+               \r
                #region ColumnHeaderのソートの三角印用\r
                \r
                [StructLayout(LayoutKind.Sequential, CharSet=CharSet.Auto)]\r
@@ -163,6 +198,8 @@ namespace AppliStation.Util
                \r
                #endregion\r
                \r
+               #endregion\r
+               \r
                #region EnableWindow(コメントアウト)\r
 //             /// <summary>\r
 //             /// 指定されたコントロール(ウィンドウ)への、\r
@@ -197,5 +234,8 @@ namespace AppliStation.Util
                \r
                [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
                internal static extern IntPtr SendMessage( IntPtr hWnd, UInt32 Msg, int wParam, ref HD_ITEM lParam);\r
+\r
+               [DllImport("uxtheme.dll", ExactSpelling=true, CharSet=CharSet.Unicode)]\r
+               internal static extern int SetWindowTheme(IntPtr hWnd, String pszSubAppName, String pszSubIdList);\r
        }\r
 }\r