From 868161b7f0f5de708f242aaf82a3165edbaa22e8 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Thu, 14 Aug 2014 16:12:43 -0400 Subject: Moved code to handle window user data in the Windows backend to a single function. --- redo/common_windows.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'redo/common_windows.c') diff --git a/redo/common_windows.c b/redo/common_windows.c index 01da0ef..53f2b3e 100644 --- a/redo/common_windows.c +++ b/redo/common_windows.c @@ -29,11 +29,23 @@ void updateWindow(HWND hwnd) xpanic("error calling UpdateWindow()", GetLastError()); } -void storelpParam(HWND hwnd, LPARAM lParam) +void *getWindowData(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT *lResult, void (*storeHWND)(void *, HWND)) { CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; + void *data; - SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); + data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + if (data == NULL) { + // the lpParam is available during WM_NCCREATE and WM_CREATE + if (uMsg == WM_NCCREATE) { + SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); + data = (void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); + (*storeHWND)(data, hwnd); + } + // act as if we're not ready yet, even during WM_NCCREATE (nothing important to the switch statement below happens here anyway) + *lResult = DefWindowProcW(hwnd, uMsg, wParam, lParam); + } + return data; } /* -- cgit v1.2.3