Fixes an issue with Fallout's window disappearing from the taskbar every other
time it's minimized.
Also fixes StarCraft's Save Screen Capture dialog being hidden after the main
window is restored.
Commandos 2 reacts to WM_DISPLAYCHANGE messages by reapplying the full-screen
cooperative level and the display mode. This makes the RestoreDisplayMode call
(which itself generates WM_DISPLAYCHANGE) ineffective.
Additionally, on WM_ACTIVATE it removes the primary surface, which DDrawCompat
was relying on for full-screen detection.
This fix returns DDERR_EXCLUSIVEMODEALREADYSET if the app tries to set
full-screen cooperative level while inactive. The tracking of full-screen
mode is now done via a dummy surface instead of the primary surface.
Some DirectDraw methods are implemented by delegating to the same method
in a higher interface version. In this case, the hooking logic could be
executed twice, leading to unwanted side effects. This is now avoided.
Aiming to fix Alt-Tabbing issues (such as black screen instead of desktop)
by temporarily setting the cooperative level to windowed mode, restoring
the display mode and minimizing the main window when the app is inactive.
It's not sufficient to make g_renderingRefCount atomic, because after it is
found to be nonzero in beginGdiRendering, a call to endGdiRendering from
another thread may make it zero before beginGdiRendering has a chance of
entering the critical section. This would mean that the DirectDraw primary
surface is no longer locked, even though beginGdiRendering expects that it is.
To prevent potential issues, the g_renderingRefCount check is now also
guarded by the critical section.
GetWindowDC(GetDC(NULL)) may return a special window with a class name of
"CompatWindowDesktopReplacement". Presumably the shim engine installs an
IAT hook for GetWindowDC that replaces this window handle with the normal
desktop window handle.
CALL_ORIG_FUNC(WindowFromDC) returns with an unpatched pointer, therefore
it doesn't perform the above replacement. This results in using the
replacement window's clipping region (whole screen) instead of the desktop
window's clipping region (empty), and things become visible that shouldn't
be, e.g. some character symbols at the top left corner of the screen when
launchning Diablo II.
As a workaround, WindowFromDC is used without CALL_ORIG_FUNC.
Using flip for direct front buffer updates can cause performance problems
if the driver forces vertical sync and overrides the DDFLIP_NOVSYNC flag.
On the other hand, DDFLIP_NOVSYNC flip requests on the compat primary
surface should be handled via real flip to allow vertical sync override.
Scenario:
Thread #1 enters the DirectDraw critical section
Thread #2 enters the GDI critical section
Thread #2 starts waiting on the DirectDraw critical section
Thread #1 starts waiting on the GDI critical section
Solution:
If the primary surface has not been locked yet, enter the DirectDraw critical
section before entering the GDI critical section.
Immersive context menus don't display correctly when theming is disabled:
all menu items have empty labels and no icons.
Disabled this menu style through a faked registry value.
Now size box rendering works correctly, so no need for that workaround in
CompatGdiScrollBar.
There seems to be a bug with subclassing scroll bars though, as the cursor
will no longer change to a sizing arrow when it's over a size box control.
At least there is a simple workaround for that via WM_SETCURSOR.