Added a userdata parameter to SDL_SetWindowsMessageHook()

This commit is contained in:
Sam Lantinga 2015-05-13 22:39:32 -07:00
parent b2be9253e3
commit 1c6ea0f226
3 changed files with 7 additions and 5 deletions

View File

@ -46,8 +46,8 @@ extern "C" {
/**
\brief Set a function that is called for every windows message, before TranslateMessage()
*/
typedef void (*SDL_WindowsMessageHook)(void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback);
typedef void (SDLCALL * SDL_WindowsMessageHook)(void *userdata, void *hWnd, unsigned int message, Uint64 wParam, Sint64 lParam);
extern DECLSPEC void SDLCALL SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata);
/**
\brief Returns the D3D9 adapter index that matches the specified display index.

View File

@ -625,5 +625,5 @@ SDL_DYNAPI_PROC(Uint32,SDL_GetQueuedAudioSize,(SDL_AudioDeviceID a),(a),return)
SDL_DYNAPI_PROC(void,SDL_ClearQueuedAudio,(SDL_AudioDeviceID a),(a),)
SDL_DYNAPI_PROC(SDL_Window*,SDL_GetGrabbedWindow,(void),(),return)
#ifdef __WIN32__
SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a),(a),)
SDL_DYNAPI_PROC(void,SDL_SetWindowsMessageHook,(SDL_WindowsMessageHook a, void *b),(a,b),)
#endif

View File

@ -928,10 +928,12 @@ WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
/* A message hook called before TranslateMessage() */
static SDL_WindowsMessageHook g_WindowsMessageHook = NULL;
static void *g_WindowsMessageHookData = NULL;
void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback)
void SDL_SetWindowsMessageHook(SDL_WindowsMessageHook callback, void *userdata)
{
g_WindowsMessageHook = callback;
g_WindowsMessageHookData = userdata;
}
void
@ -944,7 +946,7 @@ WIN_PumpEvents(_THIS)
if (g_WindowsEnableMessageLoop) {
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
if (g_WindowsMessageHook) {
g_WindowsMessageHook(msg.hwnd, msg.message, msg.wParam, msg.lParam);
g_WindowsMessageHook(g_WindowsMessageHookData, msg.hwnd, msg.message, msg.wParam, msg.lParam);
}
/* Always translate the message in case it's a non-SDL window (e.g. with Qt integration) */