Alexandre Julliard : user32: Factor out the calling of a window' s winproc into a separate function.

Alexandre Julliard julliard at wine.codeweavers.com
Thu Aug 9 08:23:00 CDT 2007


Module: wine
Branch: master
Commit: 334ede409935e3327ef31318ea236ac0731bfd97
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=334ede409935e3327ef31318ea236ac0731bfd97

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Wed Aug  8 17:02:42 2007 +0200

user32: Factor out the calling of a window's winproc into a separate function.

---

 dlls/user32/message.c      |   76 +++++++++++---------------------------------
 dlls/user32/user_private.h |    2 +
 dlls/user32/winproc.c      |   41 +++++++++++++++++++++++
 3 files changed, 62 insertions(+), 57 deletions(-)

diff --git a/dlls/user32/message.c b/dlls/user32/message.c
index 25cf934..a7c93d9 100644
--- a/dlls/user32/message.c
+++ b/dlls/user32/message.c
@@ -1513,7 +1513,6 @@ static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpar
 {
     struct user_thread_info *thread_info = get_user_thread_info();
     LRESULT result = 0;
-    WNDPROC winproc;
     CWPSTRUCT cwp;
     CWPRETSTRUCT cwpret;
 
@@ -1535,16 +1534,7 @@ static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lpar
     HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, same_thread, (LPARAM)&cwp, unicode );
 
     /* now call the window procedure */
-    if (unicode)
-    {
-        if (!(winproc = (WNDPROC)GetWindowLongPtrW( hwnd, GWLP_WNDPROC ))) goto done;
-        result = CallWindowProcW( winproc, hwnd, msg, wparam, lparam );
-    }
-    else
-    {
-        if (!(winproc = (WNDPROC)GetWindowLongPtrA( hwnd, GWLP_WNDPROC ))) goto done;
-        result = CallWindowProcA( winproc, hwnd, msg, wparam, lparam );
-    }
+    if (!WINPROC_call_window( hwnd, msg, wparam, lparam, &result, unicode )) goto done;
 
     /* and finally the WH_CALLWNDPROCRET hook */
     cwpret.lResult = result;
@@ -2971,9 +2961,7 @@ BOOL WINAPI TranslateMessage( const MSG *msg )
  */
 LRESULT WINAPI DispatchMessageA( const MSG* msg )
 {
-    WND * wndPtr;
     LRESULT retval;
-    WNDPROC winproc;
 
       /* Process timer messages */
     if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
@@ -2981,31 +2969,19 @@ LRESULT WINAPI DispatchMessageA( const MSG* msg )
         if (msg->lParam) return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
                                                  msg->message, msg->wParam, GetTickCount() );
     }
+    if (!msg->hwnd) return 0;
 
-    if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
-    {
-        if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-        return 0;
-    }
-    if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
-    {
-        if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
-        else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-        return 0;
-    }
-    if (wndPtr->tid != GetCurrentThreadId())
+    SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
+                      msg->wParam, msg->lParam );
+
+    if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
+                              &retval, FALSE ))
     {
-        SetLastError( ERROR_MESSAGE_SYNC_ONLY );
-        WIN_ReleasePtr( wndPtr );
-        return 0;
+        if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
+        retval = 0;
     }
-    winproc = wndPtr->winproc;
-    WIN_ReleasePtr( wndPtr );
 
-    SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
-                      msg->wParam, msg->lParam );
-    retval = CallWindowProcA( winproc, msg->hwnd, msg->message,
-                              msg->wParam, msg->lParam );
     SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
                      msg->wParam, msg->lParam );
 
@@ -3043,9 +3019,7 @@ LRESULT WINAPI DispatchMessageA( const MSG* msg )
  */
 LRESULT WINAPI DispatchMessageW( const MSG* msg )
 {
-    WND * wndPtr;
     LRESULT retval;
-    WNDPROC winproc;
 
       /* Process timer messages */
     if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
@@ -3053,31 +3027,19 @@ LRESULT WINAPI DispatchMessageW( const MSG* msg )
         if (msg->lParam) return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
                                                  msg->message, msg->wParam, GetTickCount() );
     }
+    if (!msg->hwnd) return 0;
 
-    if (!(wndPtr = WIN_GetPtr( msg->hwnd )))
-    {
-        if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-        return 0;
-    }
-    if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
-    {
-        if (IsWindow( msg->hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
-        else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
-        return 0;
-    }
-    if (wndPtr->tid != GetCurrentThreadId())
+    SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
+                      msg->wParam, msg->lParam );
+
+    if (!WINPROC_call_window( msg->hwnd, msg->message, msg->wParam, msg->lParam,
+                              &retval, TRUE ))
     {
-        SetLastError( ERROR_MESSAGE_SYNC_ONLY );
-        WIN_ReleasePtr( wndPtr );
-        return 0;
+        if (!IsWindow( msg->hwnd )) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
+        else SetLastError( ERROR_MESSAGE_SYNC_ONLY );
+        retval = 0;
     }
-    winproc = wndPtr->winproc;
-    WIN_ReleasePtr( wndPtr );
 
-    SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
-                      msg->wParam, msg->lParam );
-    retval = CallWindowProcW( winproc, msg->hwnd, msg->message,
-                              msg->wParam, msg->lParam );
     SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval,
                      msg->wParam, msg->lParam );
 
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index 692eca9..f580e6f 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -246,6 +246,8 @@ extern LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd
 extern INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam );
 extern INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
 extern INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );
+extern BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
+                                 LRESULT *result, BOOL unicode );
 
 /* message spy definitions */
 
diff --git a/dlls/user32/winproc.c b/dlls/user32/winproc.c
index 50b5858..0664b37 100644
--- a/dlls/user32/winproc.c
+++ b/dlls/user32/winproc.c
@@ -2197,6 +2197,47 @@ LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT
 
 
 /**********************************************************************
+ *		WINPROC_call_window
+ *
+ * Call the window procedure of the specified window.
+ */
+BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
+                          LRESULT *result, BOOL unicode )
+{
+    WND *wndPtr;
+    WINDOWPROC *proc;
+
+    if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
+    if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
+    if (wndPtr->tid != GetCurrentThreadId())
+    {
+        WIN_ReleasePtr( wndPtr );
+        return FALSE;
+    }
+    proc = handle_to_proc( wndPtr->winproc );
+    WIN_ReleasePtr( wndPtr );
+
+    if (!proc) return TRUE;
+
+    if (unicode)
+    {
+        if (proc->procW)
+            call_window_proc( hwnd, msg, wParam, lParam, result, proc->procW );
+        else
+            WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procA );
+    }
+    else
+    {
+        if (proc->procA)
+            call_window_proc( hwnd, msg, wParam, lParam, result, proc->procA );
+        else
+            WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procW );
+    }
+    return TRUE;
+}
+
+
+/**********************************************************************
  *		CallWindowProc (USER.122)
  */
 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,




More information about the wine-cvs mailing list