Date: Tue, 19 Oct 2004 23:04:58 -0700
authorSam Lantinga
Fri, 12 Nov 2004 23:14:47 +0000
changeset 970fb8b91365766
parent 969 cfb9518670f4
child 971 96671ebc50a4
Date: Tue, 19 Oct 2004 23:04:58 -0700
From: "Trevor Scroggins"
Subject: [SDL] [PATCH] DirectX and SDL_WINDOWID Hack

Hello, all. The IDirectInputDevice2_SetCooperativeLevel call in
SDL_dx5events.c expects to be passed a root-level HWND. More often than not,
a child window is used with the SDL_WINDOWID hack, causing the
IDirectInputDevice2_SetCooperativeLevel call to fail.

This is a small patch to SDL_dx5events.c v1.21 that fixes the problem by
retrieving a handle to the root-level ancestor of the current SDL_Window and
passing that handle to IDirectInputDevice2_SetCooperativeLevel.
src/video/windx5/SDL_dx5events.c
     1.1 --- a/src/video/windx5/SDL_dx5events.c	Fri Nov 12 22:09:17 2004 +0000
     1.2 +++ b/src/video/windx5/SDL_dx5events.c	Fri Nov 12 23:14:47 2004 +0000
     1.3 @@ -141,6 +141,7 @@
     1.4  	LPDIRECTINPUTDEVICE device;
     1.5  	HRESULT     result;
     1.6  	DIPROPDWORD dipdw;
     1.7 +	HWND        topwnd;
     1.8  
     1.9  	/* Create the DirectInput object */
    1.10  	result = DInputCreate(SDL_Instance, DIRECTINPUT_VERSION,
    1.11 @@ -167,8 +168,9 @@
    1.12  			SetDIerror("DirectInputDevice::QueryInterface", result);
    1.13  			return(-1);
    1.14  		}
    1.15 +		topwnd =  GetAncestor(SDL_Window, GA_ROOT);
    1.16  		result = IDirectInputDevice2_SetCooperativeLevel(SDL_DIdev[i],
    1.17 -					SDL_Window, inputs[i].win_level);
    1.18 +					topwnd, inputs[i].win_level);
    1.19  		if ( result != DI_OK ) {
    1.20  			SetDIerror("DirectInputDevice::SetCooperativeLevel",
    1.21  									result);
    1.22 @@ -640,6 +642,7 @@
    1.23  	DWORD level;
    1.24  	int i;
    1.25  	HRESULT result;
    1.26 +	HWND topwnd;
    1.27  
    1.28  	for ( i=0; i<MAX_INPUTS; ++i ) {
    1.29  		if ( SDL_DIdev[i] != NULL ) {
    1.30 @@ -649,8 +652,9 @@
    1.31  				level = inputs[i].win_level;
    1.32  			}
    1.33  			IDirectInputDevice2_Unacquire(SDL_DIdev[i]);
    1.34 +			topwnd = GetAncestor(SDL_Window, GA_ROOT);
    1.35  			result = IDirectInputDevice2_SetCooperativeLevel(
    1.36 -					SDL_DIdev[i], SDL_Window, level);
    1.37 +					SDL_DIdev[i], topwnd, level);
    1.38  			IDirectInputDevice2_Acquire(SDL_DIdev[i]);
    1.39  			if ( result != DI_OK ) {
    1.40  				SetDIerror(