Skip to content

Commit bf7b6c2

Browse files
committed
further improvements to DWM code, but still not working
1 parent 7f0df95 commit bf7b6c2

3 files changed

Lines changed: 46 additions & 56 deletions

File tree

FlashpointSecurePlayer/FlashpointProxy.cs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,30 +101,35 @@ private static void GetSystemProxy(ref INTERNET_PER_CONN_OPTION_LIST internetPer
101101

102102
// allocate a block of memory of the options
103103
internetPerConnOptionList.pOptions = Marshal.AllocCoTaskMem(Marshal.SizeOf(internetPerConnOptionListOptions[0]) + Marshal.SizeOf(internetPerConnOptionListOptions[1]));
104-
105-
IntPtr internetPerConnOptionPointer = internetPerConnOptionList.pOptions;
106104

107-
// marshal data from a managed object to unmanaged memory
108-
for (int i = 0; i < internetPerConnOptionListOptions.Length; i++) {
109-
Marshal.StructureToPtr(internetPerConnOptionListOptions[i], internetPerConnOptionPointer, false);
110-
internetPerConnOptionPointer = (IntPtr)((int)internetPerConnOptionPointer + Marshal.SizeOf(internetPerConnOptionListOptions[i]));
111-
}
105+
try {
106+
IntPtr internetPerConnOptionPointer = internetPerConnOptionList.pOptions;
112107

113-
// fill the internetPerConnOptionList structure
114-
internetPerConnOptionList.dwSize = internetPerConnOptionListSize;
108+
// marshal data from a managed object to unmanaged memory
109+
for (int i = 0; i < internetPerConnOptionListOptions.Length; i++) {
110+
Marshal.StructureToPtr(internetPerConnOptionListOptions[i], internetPerConnOptionPointer, false);
111+
internetPerConnOptionPointer = (IntPtr)((int)internetPerConnOptionPointer + Marshal.SizeOf(internetPerConnOptionListOptions[i]));
112+
}
115113

116-
// NULL == LAN, otherwise connectoid name
117-
internetPerConnOptionList.pszConnection = IntPtr.Zero;
114+
// fill the internetPerConnOptionList structure
115+
internetPerConnOptionList.dwSize = internetPerConnOptionListSize;
118116

119-
// set two options
120-
internetPerConnOptionList.dwOptionCount = (uint)internetPerConnOptionListOptions.Length;
121-
internetPerConnOptionList.dwOptionError = 0;
117+
// NULL == LAN, otherwise connectoid name
118+
internetPerConnOptionList.pszConnection = IntPtr.Zero;
122119

123-
// query internet options
124-
bool result = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, ref internetPerConnOptionList, ref internetPerConnOptionListSize);
125-
126-
if (!result) {
127-
throw new FlashpointProxyException("Could not query the Internet Options.");
120+
// set two options
121+
internetPerConnOptionList.dwOptionCount = (uint)internetPerConnOptionListOptions.Length;
122+
internetPerConnOptionList.dwOptionError = 0;
123+
124+
// query internet options
125+
bool result = InternetQueryOption(IntPtr.Zero, INTERNET_OPTION.INTERNET_OPTION_PER_CONNECTION_OPTION, ref internetPerConnOptionList, ref internetPerConnOptionListSize);
126+
127+
if (!result) {
128+
throw new FlashpointProxyException("Could not query the Internet Options.");
129+
}
130+
} catch (Exception ex) {
131+
Marshal.FreeCoTaskMem(internetPerConnOptionList.pOptions);
132+
throw ex;
128133
}
129134
}
130135

FlashpointSecurePlayer/Shared.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ public struct MSLLHOOKSTRUCT {
318318
public static extern bool UnhookWindowsHookEx(IntPtr hhk);
319319

320320
public enum DWMWINDOWATTRIBUTE : uint {
321-
DWMWA_NCRENDERING_ENABLED,
321+
DWMWA_NCRENDERING_ENABLED = 1,
322322
DWMWA_NCRENDERING_POLICY,
323323
DWMWA_TRANSITIONS_FORCEDISABLED,
324324
DWMWA_ALLOW_NCPAINT,
@@ -346,10 +346,10 @@ public enum DWMWINDOWATTRIBUTE : uint {
346346
}
347347

348348
[DllImport("DWMAPI.DLL")]
349-
public static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, IntPtr pvAttribute, uint cbAttribute);
349+
public static extern int DwmGetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, out int pvAttribute, uint cbAttribute);
350350

351351
[DllImport("DWMAPI.DLL")]
352-
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, IntPtr pvAttribute, uint cbAttribute);
352+
public static extern int DwmSetWindowAttribute(IntPtr hwnd, DWMWINDOWATTRIBUTE dwAttribute, ref int pvAttribute, uint cbAttribute);
353353

354354
[StructLayout(LayoutKind.Sequential)]
355355
public struct SECURITY_ATTRIBUTES {

FlashpointSecurePlayer/WebBrowserMode.cs

Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,23 @@ private IntPtr LowLevelMouseProc(int nCode, IntPtr wParam, IntPtr lParam) {
5858

5959
private bool TransitionsForceDisabled {
6060
get {
61-
int attributeValueSize = Marshal.SizeOf(typeof(int));
62-
IntPtr attributeValuePointer = Marshal.AllocHGlobal(attributeValueSize);
63-
64-
try {
65-
DwmGetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, attributeValuePointer, (uint)attributeValueSize);
66-
return (Marshal.ReadInt32(attributeValuePointer, 0) != 0) ? true : false;
67-
} finally {
68-
Marshal.FreeHGlobal(attributeValuePointer);
61+
int attributeValue = 0;
62+
63+
int err = DwmGetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, out attributeValue, (uint)Marshal.SizeOf(typeof(int)));
64+
65+
if (err != S_OK) {
66+
Marshal.ThrowExceptionForHR(err);
6967
}
68+
return (attributeValue != 0) ? true : false;
7069
}
7170

7271
set {
7372
int attributeValue = value ? 1 : 0;
73+
74+
int err = DwmSetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, ref attributeValue, (uint)Marshal.SizeOf(typeof(int)));
7475

75-
int attributeValueSize = Marshal.SizeOf(attributeValue);
76-
IntPtr attributeValuePointer = Marshal.AllocHGlobal(attributeValueSize);
77-
78-
try {
79-
Marshal.WriteInt32(attributeValuePointer, 0, attributeValue);
80-
81-
DwmSetWindowAttribute(Handle, DWMWINDOWATTRIBUTE.DWMWA_TRANSITIONS_FORCEDISABLED, attributeValuePointer, (uint)attributeValueSize);
82-
} finally {
83-
Marshal.FreeHGlobal(attributeValuePointer);
76+
if (err != S_OK) {
77+
Marshal.ThrowExceptionForHR(err);
8478
}
8579
}
8680
}
@@ -114,6 +108,7 @@ private bool ExitFullscreenLabelTimer {
114108
}
115109

116110
private bool fullscreen = false;
111+
private bool fullscreenTransitionsForceDisabled = false;
117112
private FormBorderStyle fullscreenFormBorderStyle = FormBorderStyle.Sizable;
118113
private FormWindowState fullscreenWindowState = FormWindowState.Maximized;
119114
private Point fullscreenLocation;
@@ -152,9 +147,11 @@ public bool Fullscreen {
152147
closableWebBrowserSize = closableWebBrowser.Size;
153148

154149
try {
150+
fullscreenTransitionsForceDisabled = TransitionsForceDisabled;
155151
TransitionsForceDisabled = true;
156152
} catch {
157-
// Fail silently.
153+
// no Aero!
154+
fullscreenTransitionsForceDisabled = false;
158155
}
159156

160157
// need to do this first to have an effect if starting maximized
@@ -181,13 +178,7 @@ public bool Fullscreen {
181178

182179
// commit by bringing the window to the front
183180
BringToFront();
184-
185-
try {
186-
TransitionsForceDisabled = false;
187-
} catch {
188-
// Fail silently.
189-
}
190-
} else {
181+
} else {
191182
// hide "Press F11 to exit fullscreen" label
192183
ExitFullscreenLabelTimer = false;
193184

@@ -198,12 +189,6 @@ public bool Fullscreen {
198189
}
199190
}
200191

201-
try {
202-
TransitionsForceDisabled = true;
203-
} catch {
204-
// Fail silently.
205-
}
206-
207192
// need to do this first to reset the window to its former size
208193
FormBorderStyle = FormBorderStyle.Sizable;
209194
// exit fullscreen
@@ -226,11 +211,11 @@ public bool Fullscreen {
226211

227212
// commit by bringing the window to the front
228213
BringToFront();
229-
214+
230215
try {
231-
TransitionsForceDisabled = false;
216+
TransitionsForceDisabled = fullscreenTransitionsForceDisabled;
232217
} catch {
233-
// Fail silently.
218+
// no Aero!
234219
}
235220
}
236221
}

0 commit comments

Comments
 (0)