-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBrowserSetting.cs
171 lines (151 loc) · 5.14 KB
/
BrowserSetting.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
using System.Diagnostics;
using Microsoft.Win32;
namespace KCB2
{
class BrowserSetting
{
const string FeatureControl = @"Software\Microsoft\Internet Explorer\MAIN\FeatureControl\";
const string BrowserEmurationKey = "FEATURE_BROWSER_EMULATION";
const string GPURenderingKey = "FEATURE_GPU_RENDERING";
const string BrowserEmuration = FeatureControl + BrowserEmurationKey;
const string GPURendering = FeatureControl+GPURenderingKey;
/// <summary>
/// 実行プロセス名を取得
/// </summary>
static public string ProcessName
{
get
{
string name;
using (var proc = Process.GetCurrentProcess())
{
name = proc.MainModule.ModuleName;
}
Debug.WriteLine("ProcessName:" + name);
return name;
}
}
/// <summary>
/// エミュレーションするIEのバージョン
/// </summary>
public enum BrowserVer
{
IE11_FORCE = 11001,
IE11 = 11000,
IE10_FORCE = 10001,
IE10 = 10000,
IE9_FORCE = 9999,
IE9 = 9000,
IE8_FORCE = 8888,
IE8 = 8000,
IE7 = 7000,
}
/// <summary>
/// WebBrowserコントロールがエミュレーションするIEのバージョン
/// </summary>
static public BrowserVer EmurateBrowser
{
get
{
try
{
var key = Registry.CurrentUser.OpenSubKey(BrowserEmuration);
if (key == null)
return BrowserVer.IE7;
int emuVer = (int)key.GetValue(ProcessName, (int)BrowserVer.IE7);
key.Close();
return (BrowserVer)emuVer;
}
catch (Exception ex)
{
string msg = "ブラウザバージョンの取得に失敗しました\n" + ex.ToString();
Debug.WriteLine(msg);
MessageBox.Show(msg);
return BrowserVer.IE7;
}
}
set
{
try
{
var key = Registry.CurrentUser.CreateSubKey(BrowserEmuration);
//IE7は標準なので、エントリを削除する
if (value == BrowserVer.IE7)
{
if (key.GetValue(ProcessName) != null)
key.DeleteValue(ProcessName);
key.Close();
return;
}
key.SetValue(ProcessName, (int)value, RegistryValueKind.DWord);
key.Close();
}
catch (Exception ex)
{
string msg = "ブラウザバージョンの設定に失敗しました\n" + ex.ToString();
Debug.WriteLine(msg);
MessageBox.Show(msg);
}
}
}
/// <summary>
/// GPUレンダリングの設定
/// </summary>
public static bool EnableGPURendering
{
get
{
try
{
var key = Registry.CurrentUser.OpenSubKey(GPURendering);
if (key == null)
return false;
var val = key.GetValue(ProcessName);
if (val == null)
{
key.Close();
return false;
}
int enable = (int)val;
key.Close();
return enable == 1;
}
catch (Exception ex)
{
string msg = "GPUレンダリング設定の読み込みに失敗しました\n" + ex.ToString();
Debug.WriteLine(msg);
MessageBox.Show(msg);
return false;
}
}
set
{
try
{
var key = Registry.CurrentUser.CreateSubKey(GPURendering);
if (value == false)
{
if (key.GetValue(ProcessName) != null)
key.DeleteValue(ProcessName);
key.Close();
return;
}
key.SetValue(ProcessName, 1, RegistryValueKind.DWord);
key.Close();
}
catch (Exception ex)
{
string msg = "GPUレンダリング設定の書き込みに失敗しました\n" + ex.ToString();
Debug.WriteLine(msg);
MessageBox.Show(msg);
}
}
}
}
}