[PATCH] comctl32/updown: Remove window subclass right before window is destroyed

Nikolay Sivov nsivov at codeweavers.com
Sun Jan 21 10:51:36 CST 2018


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/comctl32/updown.c | 33 +++++++++++++++++++++------------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/dlls/comctl32/updown.c b/dlls/comctl32/updown.c
index 4f44b9032a..67b646da0e 100644
--- a/dlls/comctl32/updown.c
+++ b/dlls/comctl32/updown.c
@@ -592,14 +592,22 @@ UPDOWN_Buddy_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
     switch(uMsg)
     {
     case WM_KEYDOWN:
-	UPDOWN_KeyPressed(infoPtr, (int)wParam);
-	if ((wParam == VK_UP) || (wParam == VK_DOWN)) return 0;
-	break;
+        if (infoPtr)
+        {
+            UPDOWN_KeyPressed(infoPtr, (int)wParam);
+            if (wParam == VK_UP || wParam == VK_DOWN)
+                return 0;
+        }
+        break;
 
     case WM_MOUSEWHEEL:
-	UPDOWN_MouseWheel(infoPtr, (int)wParam);
-	break;
+        if (infoPtr)
+            UPDOWN_MouseWheel(infoPtr, (int)wParam);
+        break;
 
+    case WM_NCDESTROY:
+        RemoveWindowSubclass(hwnd, UPDOWN_Buddy_SubclassProc, BUDDY_SUBCLASSID);
+        break;
     default:
 	break;
     }
@@ -607,6 +615,11 @@ UPDOWN_Buddy_SubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam,
     return DefSubclassProc(hwnd, uMsg, wParam, lParam);
 }
 
+static void UPDOWN_ResetSubclass (UPDOWN_INFO *infoPtr)
+{
+    SetWindowSubclass(infoPtr->Buddy, UPDOWN_Buddy_SubclassProc, BUDDY_SUBCLASSID, 0);
+}
+
 /***********************************************************************
  *           UPDOWN_SetBuddy
  *
@@ -628,9 +641,8 @@ static HWND UPDOWN_SetBuddy (UPDOWN_INFO* infoPtr, HWND bud)
 
     old_buddy = infoPtr->Buddy;
 
-    /* there is already a buddy assigned */
-    if (infoPtr->Buddy) RemoveWindowSubclass(infoPtr->Buddy, UPDOWN_Buddy_SubclassProc,
-                                             BUDDY_SUBCLASSID);
+    UPDOWN_ResetSubclass (infoPtr);
+
     if (!IsWindow(bud)) bud = NULL;
 
     /* Store buddy window handle */
@@ -942,10 +954,7 @@ static LRESULT WINAPI UpDownWindowProc(HWND hwnd, UINT message, WPARAM wParam, L
 
 	case WM_DESTROY:
 	    Free (infoPtr->AccelVect);
-
-	    if (infoPtr->Buddy)
-	       RemoveWindowSubclass(infoPtr->Buddy, UPDOWN_Buddy_SubclassProc,
-	                            BUDDY_SUBCLASSID);
+            UPDOWN_ResetSubclass (infoPtr);
 	    Free (infoPtr);
 	    SetWindowLongPtrW (hwnd, 0, 0);
             theme = GetWindowTheme (hwnd);
-- 
2.15.1




More information about the wine-devel mailing list