We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 905

Summary: WM_Paint gets swallowed by SDL even on an external window
Product: SDL Reporter: Mason Wheeler <masonwheeler>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: Windows (All)   

Description Mason Wheeler 2009-12-14 19:09:10 UTC
If an external window passes its HWND to SDL_CreateWindowFrom, SDL needs to pass certain messages back to it, including WM_Paint.

--- C:\Users\Mason\AppData\Local\Temp\SDL_win32events.-revBASE.svn001.tmp.c	2009-12-14 19:05:37.000000000 -0800
+++ C:\Users\Mason\Documents\SDL-1.3\SDL-1.3.0-4423\src\video\win32\SDL_win32events.c	2009-09-28 08:35:19.000000000 -0800
@@ -591,21 +591,24 @@
              */
         }
         break;
 
         /* We were occluded, refresh our display */
     case WM_PAINT:
-        {
-            RECT rect;
-            if (GetUpdateRect(hwnd, &rect, FALSE)) {
-                ValidateRect(hwnd, &rect);
-                SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED,
-                                    0, 0);
-            }
-        }
-        return (0);
+		{
+			if (!(SDL_GetWindowFlags(data->windowID) & SDL_WINDOW_FOREIGN)) {
+				RECT rect;
+				if (GetUpdateRect(hwnd, &rect, FALSE)) {
+					ValidateRect(hwnd, &rect);
+					SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED,
+										0, 0);
+				}
+				return (0);
+			}
+			else break;
+		}
 
         /* If this isn't our window, we don't need to repaint the frame.
            This fixes a reentrancy issue that can cause stack overflows with foreign windows.
            3/21/09 Mason Wheeler */
     case WM_NCPAINT:
         {
Comment 1 Sam Lantinga 2009-12-14 21:24:51 UTC
After discussing this with Mason, I'm going to change it so all windows messages get forwarded to foreign windows' message handlers.
Comment 2 Sam Lantinga 2009-12-15 01:23:07 UTC
This should be fixed with revision 5401.

I'm not entirely happy with that code because a window procedure which is set only to handle a couple of events will then call DefWindowProc for an event that SDL has already processed.  Hopefully this will be taken care of when we add the ability for the app to specify what type of events should be processed on a foreign window.