diff --git a/windows/dialog.c b/windows/dialog.c
index 8a01df3069563cf9ae2d14392dd3c26f30dc4e43..23f25604a9212d1979901b2e992b624528b08ea0 100644
--- a/windows/dialog.c
+++ b/windows/dialog.c
@@ -1883,75 +1883,104 @@ HWND16 WINAPI GetNextDlgTabItem16( HWND16 hwndDlg, HWND16 hwndCtrl,
     return (HWND16)GetNextDlgTabItem( hwndDlg, hwndCtrl, fPrevious );
 }
 
-
 /***********************************************************************
- *           GetNextDlgTabItem32   (USER32.276)
+ *           DIALOG_GetNextTabItem
+ *
+ * Helper for GetNextDlgTabItem
  */
-HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
-                                   BOOL fPrevious )
+static HWND DIALOG_GetNextTabItem( HWND hwndMain, HWND hwndDlg, HWND hwndCtrl, BOOL fPrevious )
 {
-    WND *pWnd = NULL,
-        *pWndLast = NULL,
-        *pWndCtrl = NULL,
-        *pWndDlg = NULL;
-    HWND retvalue;
+    LONG dsStyle;
+    LONG exStyle;
+    UINT wndSearch = fPrevious ? GW_HWNDPREV : GW_HWNDNEXT;
+    HWND retWnd = 0;
+    HWND hChildFirst = 0;
 
-    if (!(pWndDlg = WIN_FindWndPtr( hwndDlg ))) return 0;
-    if (hwndCtrl)
+    if(!hwndCtrl) 
     {
-        if (!(pWndCtrl = WIN_FindWndPtr( hwndCtrl )))
+        hChildFirst = GetWindow(hwndDlg,GW_CHILD);
+        if(fPrevious) hChildFirst = GetWindow(hChildFirst,GW_HWNDLAST);
+    }
+    else
     {
-            retvalue = 0;
-            goto END;
+        HWND hParent = GetParent(hwndCtrl);
+        BOOL bValid = FALSE;
+        while( hParent)
+        {
+            if(hParent == hwndMain)
+            {
+                bValid = TRUE;
+                break;
+            }
+            hParent = GetParent(hParent);
         }
-        /* Make sure hwndCtrl is a top-level child */
-        while ((pWndCtrl->dwStyle & WS_CHILD) && (pWndCtrl->parent != pWndDlg))
-            WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->parent);
-        if (pWndCtrl->parent != pWndDlg)
+        if(bValid)
         {
-            retvalue = 0;
-            goto END;
-    }
+            hChildFirst = GetWindow(hwndCtrl,wndSearch);
+            if(!hChildFirst)
+            {
+                if(GetParent(hwndCtrl) != hwndMain)
+                    hChildFirst = GetWindow(GetParent(hwndCtrl),wndSearch);
+                else
+                {
+                    if(fPrevious)
+                        hChildFirst = GetWindow(hwndCtrl,GW_HWNDLAST);
+                    else
+                        hChildFirst = GetWindow(hwndCtrl,GW_HWNDFIRST);
+                }
+            }
+        }	
     }
-    else
+    while(hChildFirst)
     {
-        /* No ctrl specified -> start from the beginning */
-        if (!(pWndCtrl = WIN_LockWndPtr(pWndDlg->child)))
+        BOOL bCtrl = FALSE;
+        while(hChildFirst)
         {
-            retvalue = 0;
-            goto END;
+            dsStyle = GetWindowLongA(hChildFirst,GWL_STYLE);
+            exStyle = GetWindowLongA(hChildFirst,GWL_EXSTYLE);
+            if(dsStyle & DS_CONTROL || exStyle & WS_EX_CONTROLPARENT)
+            {
+                bCtrl=TRUE;
+                break;
+            }
+            else if( (dsStyle & WS_TABSTOP) && (dsStyle & WS_VISIBLE) && !(dsStyle & WS_DISABLED))
+                break;
+            hChildFirst = GetWindow(hChildFirst,wndSearch);
         }
-        
-        if (!fPrevious)
-            while (pWndCtrl->next) WIN_UpdateWndPtr(&pWndCtrl,pWndCtrl->next);
+        if(hChildFirst)
+        {
+            if(bCtrl)
+                retWnd = DIALOG_GetNextTabItem(hwndMain,hChildFirst,(HWND)NULL,fPrevious );
+            else
+                retWnd = hChildFirst;
+        }
+        if(retWnd) break;
+        hChildFirst = GetWindow(hChildFirst,wndSearch);
     }
-
-    pWndLast = WIN_LockWndPtr(pWndCtrl);
-    pWnd = WIN_LockWndPtr(pWndCtrl->next);
-    while (1)
+    if(!retWnd && hwndCtrl)
     {
-        if (!pWnd) pWnd = WIN_LockWndPtr(pWndDlg->child);
-        if (pWnd == pWndCtrl) break;
-	if ((pWnd->dwStyle & WS_TABSTOP) && (pWnd->dwStyle & WS_VISIBLE) &&
-            !(pWnd->dwStyle & WS_DISABLED))
+        HWND hParent = GetParent(hwndCtrl);
+        while(hParent)
 	{
-            WIN_UpdateWndPtr(&pWndLast,pWnd);
-	    if (!fPrevious) break;
+            if(hParent == hwndMain) break;
+            retWnd = DIALOG_GetNextTabItem(hwndMain,GetParent(hParent),hParent,fPrevious );
+            if(retWnd) break;
+            hParent = GetParent(hParent);
 	}
-        WIN_UpdateWndPtr(&pWnd,pWnd->next);
+        if(!retWnd)
+            retWnd = DIALOG_GetNextTabItem(hwndMain,hwndMain,(HWND)NULL,fPrevious );
     }
-    retvalue = pWndLast->hwndSelf;
-    
-    WIN_ReleaseWndPtr(pWndLast);
-    WIN_ReleaseWndPtr(pWnd);
-END:
-    WIN_ReleaseWndPtr(pWndCtrl);
-    WIN_ReleaseWndPtr(pWndDlg);
-
-    return retvalue;
-
+    return retWnd;
 }
 
+/***********************************************************************
+ *           GetNextDlgTabItem32   (USER32.276)
+ */
+HWND WINAPI GetNextDlgTabItem( HWND hwndDlg, HWND hwndCtrl,
+                                   BOOL fPrevious )
+{
+    return DIALOG_GetNextTabItem(hwndDlg,hwndDlg,hwndCtrl,fPrevious); 
+}
 
 /**********************************************************************
  *           DIALOG_DlgDirSelect