Skip to content

Commit ca61248

Browse files
committed
Send WM_ACTIVATEAPP for DirectDraw v1 to v3
#487
1 parent 710a4aa commit ca61248

File tree

5 files changed

+32
-12
lines changed

5 files changed

+32
-12
lines changed

Dllmain/BuildNo.rc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
#define BUILD_NUMBER 8094
1+
#define BUILD_NUMBER 8095

GDI/WndProc.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -384,15 +384,15 @@ LRESULT CALLBACK WndProc::Handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPa
384384
// Some games don't properly handle app activate in exclusive mode
385385
if (pDataStruct->IsDirectDraw)
386386
{
387-
static WPARAM IsActive = FALSE;
388-
const bool IsDuplicateMessage = (wParam == IsActive);
389-
IsActive = wParam;
390-
391-
if (IsDuplicateMessage || (pDataStruct->IsCreatingDevice && pDataStruct->IsExclusiveMode) || IsForcingWindowedMode)
387+
static WPARAM IsActive = 0xFFFF;
388+
Logging::Log() << __FUNCTION__ << " WM_ACTIVATEAPP IsExclusiveMode: " << pDataStruct->IsExclusiveMode << " IsCreatingDevice: " << pDataStruct->IsCreatingDevice << " " << IsActive << " -> " << wParam;
389+
const bool IsDuplicateMessage = (IsActive == wParam);
390+
if (IsDuplicateMessage || IsForcingWindowedMode)
392391
{
393-
LOG_LIMIT(3, __FUNCTION__ << " Warning: filtering " << (IsDuplicateMessage ? "duplicate " : "") << "'WM_ACTIVATEAPP': " << wParam);
394-
return CallWndProc(nullptr, hWnd, Msg, wParam, lParam);
392+
LOG_LIMIT(3, __FUNCTION__ << " Warning: filtering " << (IsDuplicateMessage ? "duplicate " : "") << "WM_ACTIVATEAPP: " << wParam);
393+
return NULL;
395394
}
395+
IsActive = wParam;
396396
}
397397
break;
398398

@@ -407,7 +407,7 @@ LRESULT CALLBACK WndProc::Handler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lPa
407407
{
408408
if (pDataStruct->IsActive == LOWORD(wParam))
409409
{
410-
LOG_LIMIT(3, __FUNCTION__ << " Warning: filtering duplicate 'WM_ACTIVATE': " << LOWORD(wParam));
410+
LOG_LIMIT(3, __FUNCTION__ << " Warning: filtering duplicate WM_ACTIVATE: " << LOWORD(wParam));
411411
return CallWndProc(nullptr, hWnd, Msg, wParam, lParam);
412412
}
413413
pDataStruct->IsActive = LOWORD(wParam);

d3d9/IDirect3D9Ex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@ HRESULT m_IDirect3D9Ex::CreateDeviceT(DEVICEDETAILS& DeviceDetails, UINT Adapter
537537
WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc(hWnd);
538538

539539
bool tmpFlag = false;
540-
ScopedFlagSet SetCreatingDevice(WndDataStruct ? WndDataStruct->IsCreatingDevice : tmpFlag, (WndDataStruct && !WndDataStruct->IsDirectDraw));
540+
ScopedFlagSet SetCreatingDevice(WndDataStruct && !WndDataStruct->IsDirectDraw ? WndDataStruct->IsCreatingDevice : tmpFlag);
541541

542542
if (WndDataStruct)
543543
{

d3d9/IDirect3DDevice9Ex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3401,7 +3401,7 @@ HRESULT m_IDirect3DDevice9Ex::ResetT(T func, D3DPRESENT_PARAMETERS* pPresentatio
34013401
WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc(hWnd);
34023402

34033403
bool tmpFlag = false;
3404-
ScopedFlagSet SetCreatingDevice(WndDataStruct ? WndDataStruct->IsCreatingDevice : tmpFlag, (WndDataStruct && !WndDataStruct->IsDirectDraw));
3404+
ScopedFlagSet SetCreatingDevice(WndDataStruct && !WndDataStruct->IsDirectDraw ? WndDataStruct->IsCreatingDevice : tmpFlag);
34053405

34063406
if (WndDataStruct && !WndDataStruct->IsDirectDraw)
34073407
{

ddraw/IDirectDrawX.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,14 @@ HRESULT m_IDirectDrawX::SetCooperativeLevel(HWND hWnd, DWORD dwFlags, DWORD Dire
17261726
// Check window handle
17271727
if (IsWindow(DisplayMode.hWnd) && ((!hWnd && Config.DdrawIntroVideoFix) || DisplayMode.hWnd == hWnd))
17281728
{
1729+
// Hook WndProc
1730+
WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc(hWnd);
1731+
if (WndDataStruct)
1732+
{
1733+
WndDataStruct->IsDirectDraw = true;
1734+
WndDataStruct->DirectXVersion = ClientDirectXVersion;
1735+
}
1736+
17291737
// Set exclusive mode resolution
17301738
if (ExclusiveMode && DisplayMode.Width && DisplayMode.Height && DisplayMode.BPP)
17311739
{
@@ -3247,6 +3255,13 @@ HRESULT m_IDirectDrawX::ResetD9Device()
32473255
return DDERR_WRONGMODE;
32483256
}
32493257

3258+
// Hook WndProc before creating device
3259+
WndProc::DATASTRUCT* WndDataStruct = WndProc::AddWndProc(GetHwnd());
3260+
3261+
// Mark as creating device
3262+
bool tmpFlag = false;
3263+
ScopedFlagSet SetCreatingDevice(WndDataStruct ? WndDataStruct->IsCreatingDevice : tmpFlag);
3264+
32503265
// Reset device if current thread matches creation thread
32513266
if (IsWindow(hFocusWindow) && FocusWindowThreadID == GetCurrentThreadId())
32523267
{
@@ -3644,7 +3659,6 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)
36443659
}
36453660
CopyGDISurface = false;
36463661

3647-
36483662
// Create default state block
36493663
GetDefaultStates();
36503664

@@ -3719,6 +3733,12 @@ HRESULT m_IDirectDrawX::CreateD9Device(char* FunctionName)
37193733
PostMessage(hWnd, WM_SETFOCUS, NULL, NULL);
37203734
PostMessage(hWnd, WM_SYNCPAINT, (WPARAM)32, NULL);
37213735
}
3736+
3737+
// Activate app
3738+
if (ExclusiveMode && ClientDirectXVersion < 4 && LasthWnd != hFocusWindow)
3739+
{
3740+
PostMessage(hWnd, WM_ACTIVATEAPP, TRUE, (LPARAM)GetWindowThreadProcessId(LastActiveWindow, nullptr));
3741+
}
37223742
}
37233743

37243744
// Store display frequency

0 commit comments

Comments
 (0)