From df66b90f129d0461133a8ff8e8d664d89992dc87 Mon Sep 17 00:00:00 2001
From: Dave Pickles <davep@nugate.demon.co.uk>
Date: Sun, 28 Nov 1999 20:14:49 +0000
Subject: [PATCH] Prevent a crash if messages are sent to a toolbar window
 before WM_NCCREATE or after WM_DESTROY.

---
 dlls/comctl32/toolbar.c | 22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

diff --git a/dlls/comctl32/toolbar.c b/dlls/comctl32/toolbar.c
index 3bccd30bccd..b3fd83f3a03 100644
--- a/dlls/comctl32/toolbar.c
+++ b/dlls/comctl32/toolbar.c
@@ -2943,6 +2943,7 @@ TOOLBAR_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
 
     /* free toolbar info data */
     COMCTL32_Free (infoPtr);
+    SetWindowLongA (hwnd, 0, 0);
 
     return 0;
 }
@@ -3411,6 +3412,21 @@ TOOLBAR_StyleChanged (HWND hwnd, INT nType, LPSTYLESTRUCT lpStyle)
 static LRESULT WINAPI
 ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
+
+    switch (uMsg)
+    {
+       case WM_DESTROY:
+           return TOOLBAR_Destroy (hwnd, wParam, lParam);
+
+       case WM_NCCREATE:
+           return TOOLBAR_NCCreate (hwnd, wParam, lParam);
+    }
+
+    if (!TOOLBAR_GetInfoPtr (hwnd))
+    {
+       return DefWindowProcA (hwnd, uMsg, wParam, lParam);
+    }
+
     switch (uMsg)
     {
 	case TB_ADDBITMAP:
@@ -3671,9 +3687,6 @@ ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 	case WM_CREATE:
 	    return TOOLBAR_Create (hwnd, wParam, lParam);
 
-	case WM_DESTROY:
-	    return TOOLBAR_Destroy (hwnd, wParam, lParam);
-
 	case WM_ERASEBKGND:
 	    return TOOLBAR_EraseBackground (hwnd, wParam, lParam);
 
@@ -3701,9 +3714,6 @@ ToolbarWindowProc (HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 	case WM_NCCALCSIZE:
 	    return TOOLBAR_NCCalcSize (hwnd, wParam, lParam);
 
-	case WM_NCCREATE:
-	    return TOOLBAR_NCCreate (hwnd, wParam, lParam);
-
 	case WM_NCPAINT:
 	    return TOOLBAR_NCPaint (hwnd, wParam, lParam);
 
-- 
GitLab