From e050dd783707eea87a2f41587c2f9880dec63b1c Mon Sep 17 00:00:00 2001 From: Tau Date: Sat, 28 Sep 2019 18:46:35 -0400 Subject: [PATCH] idzio/wnd.c: Add helper for message window creation --- idzio/meson.build | 2 ++ idzio/wnd.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ idzio/wnd.h | 5 +++ 3 files changed, 93 insertions(+) create mode 100644 idzio/wnd.c create mode 100644 idzio/wnd.h diff --git a/idzio/meson.build b/idzio/meson.build index 9f181fb..d5976c9 100644 --- a/idzio/meson.build +++ b/idzio/meson.build @@ -14,6 +14,8 @@ idzio_dll = shared_library( 'idzio.h', 'shifter.c', 'shifter.h', + 'wnd.c', + 'wnd.h', 'xi.c', 'xi.h', ], diff --git a/idzio/wnd.c b/idzio/wnd.c new file mode 100644 index 0000000..092477e --- /dev/null +++ b/idzio/wnd.c @@ -0,0 +1,86 @@ +#include + +#include +#include + +#include "util/dprintf.h" + +/* DirectInput requires a window for correct initialization (and also force + feedback), so this source file provides some utilities for creating a + generic message-only window. */ + +static LRESULT WINAPI idz_io_wnd_proc( + HWND hwnd, + UINT msg, + WPARAM wparam, + LPARAM lparam); + +HRESULT idz_io_wnd_create(HINSTANCE inst, HWND *out) +{ + HRESULT hr; + WNDCLASSEXW wcx; + ATOM atom; + HWND hwnd; + + assert(inst != NULL); /* We are not an EXE */ + assert(out != NULL); + + *out = NULL; + + memset(&wcx, 0, sizeof(wcx)); + wcx.cbSize = sizeof(wcx); + wcx.lpfnWndProc = idz_io_wnd_proc; + wcx.hInstance = inst; + wcx.lpszClassName = L"IDZIO"; + + atom = RegisterClassExW(&wcx); + + if (atom == 0) { + hr = HRESULT_FROM_WIN32(GetLastError()); + dprintf("IDZIO: RegisterClassExW failed: %08x\n", (int) hr); + + goto fail; + } + + hwnd = CreateWindowExW( + 0, + (wchar_t *) (intptr_t) atom, + L"", + 0, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + CW_USEDEFAULT, + HWND_MESSAGE, + NULL, + inst, + NULL); + + if (hwnd == NULL) { + hr = HRESULT_FROM_WIN32(GetLastError()); + dprintf("IDZIO: CreateWindowExW failed: %08x\n", (int) hr); + + goto fail; + } + + *out = hwnd; + + return S_OK; + +fail: + UnregisterClassW((wchar_t *) (intptr_t) atom, inst); + + return hr; +} + +static LRESULT WINAPI idz_io_wnd_proc( + HWND hwnd, + UINT msg, + WPARAM wparam, + LPARAM lparam) +{ + switch (msg) { + default: + return DefWindowProcW(hwnd, msg, wparam, lparam); + } +} diff --git a/idzio/wnd.h b/idzio/wnd.h new file mode 100644 index 0000000..aa74417 --- /dev/null +++ b/idzio/wnd.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +HRESULT idz_io_wnd_create(HINSTANCE inst, HWND *out);