-  // base init
-  if ( !CreateBase(parent, id, pos, size, style, wxDefaultValidator, name) )
-      return FALSE;
-
-  parent->AddChild(this);
-
-  // style
-  m_windowStyle = style | wxTAB_TRAVERSAL;
-
-  long tabStyle = WS_TABSTOP | TCS_TABS;
-
-  if ( m_windowStyle & wxBORDER )
-    tabStyle |= WS_BORDER;
-  if ( m_windowStyle & wxCLIP_SIBLINGS )
-    tabStyle |= WS_CLIPSIBLINGS;
-  if (m_windowStyle & wxCLIP_CHILDREN)
-    tabStyle |= WS_CLIPCHILDREN;
-
-  if ( m_windowStyle & wxTC_MULTILINE )
-    tabStyle |= TCS_MULTILINE;
-  if (m_windowStyle & wxNB_FIXEDWIDTH)
-    tabStyle |= TCS_FIXEDWIDTH ;
-  if (m_windowStyle & wxNB_BOTTOM)
-    tabStyle |= TCS_RIGHT;
-  if (m_windowStyle & wxNB_LEFT)
-    tabStyle |= TCS_VERTICAL;
-  if (m_windowStyle & wxNB_RIGHT)
-    tabStyle |= TCS_VERTICAL|TCS_RIGHT;
-
-  // note that we don't want to have the default WS_EX_CLIENTEDGE style for the
-  // notebook, so explicitly specify 0 as last parameter
-  if ( !MSWCreateControl(WC_TABCONTROL, tabStyle, pos, size, _T(""), 0) )
-  {
-    return FALSE;
-  }
+    if ( (style & wxBK_ALIGN_MASK) == wxBK_DEFAULT )
+    {
+#if defined(__POCKETPC__)
+        style |= wxBK_BOTTOM | wxNB_FLAT;
+#else
+        style |= wxBK_TOP;
+#endif
+    }
+
+#ifdef __WXWINCE__
+    // Not sure why, but without this style, there is no border
+    // around the notebook tabs.
+    if (style & wxNB_FLAT)
+        style |= wxBORDER_SUNKEN;
+#endif
+
+#if !wxUSE_UXTHEME
+    // ComCtl32 notebook tabs simply don't work unless they're on top if we have uxtheme, we can
+    // work around it later (after control creation), but if we don't have uxtheme, we have to clear
+    // those styles
+    const int verComCtl32 = wxApp::GetComCtl32Version();
+    if ( verComCtl32 == 600 )
+    {
+        style &= ~(wxBK_BOTTOM | wxBK_LEFT | wxBK_RIGHT);
+    }
+#endif //wxUSE_UXTHEME
+
+#if defined(__WINE__) && wxUSE_UNICODE
+    LPCTSTR className = L"SysTabControl32";
+#else
+    LPCTSTR className = WC_TABCONTROL;
+#endif
+
+#if USE_NOTEBOOK_ANTIFLICKER
+    // SysTabCtl32 class has natively CS_HREDRAW and CS_VREDRAW enabled and it
+    // causes horrible flicker when resizing notebook, so get rid of it by
+    // using a class without these styles (but otherwise identical to it)
+    if ( !HasFlag(wxFULL_REPAINT_ON_RESIZE) )
+    {
+        static ClassRegistrar s_clsNotebook;
+        if ( !s_clsNotebook.IsInitialized() )
+        {
+            // get a copy of standard class and modify it
+            WNDCLASS wc;
+
+            if ( ::GetClassInfo(NULL, WC_TABCONTROL, &wc) )
+            {
+                gs_wndprocNotebook =
+                    wx_reinterpret_cast(WXFARPROC, wc.lpfnWndProc);
+                wc.lpszClassName = wxT("_wx_SysTabCtl32");
+                wc.style &= ~(CS_HREDRAW | CS_VREDRAW);
+                wc.hInstance = wxGetInstance();
+                wc.lpfnWndProc = wxNotebookWndProc;
+                s_clsNotebook.Register(wc);
+            }
+            else
+            {
+                wxLogLastError(_T("GetClassInfoEx(SysTabCtl32)"));
+            }
+        }
+
+        // use our custom class if available but fall back to the standard
+        // notebook if we failed to register it
+        if ( s_clsNotebook.IsRegistered() )
+        {
+            // it's ok to use c_str() here as the static s_clsNotebook object
+            // has sufficiently long lifetime
+            className = s_clsNotebook.GetName().c_str();
+        }
+    }
+#endif // USE_NOTEBOOK_ANTIFLICKER
+
+    if ( !CreateControl(parent, id, pos, size, style | wxTAB_TRAVERSAL,
+                        wxDefaultValidator, name) )
+        return false;
+
+    if ( !MSWCreateControl(className, wxEmptyString, pos, size) )
+        return false;
+
+#if wxUSE_UXTHEME
+    if ( HasFlag(wxNB_NOPAGETHEME) ||
+            wxSystemOptions::IsFalse(wxT("msw.notebook.themed-background")) )
+    {
+        SetBackgroundColour(GetThemeBackgroundColour());
+    }
+    else // use themed background by default
+    {
+        // create backing store
+        UpdateBgBrush();
+    }
+
+    // comctl32.dll 6.0 doesn't support non-top tabs with visual styles (the
+    // control is simply not rendered correctly), so we disable themes
+    // if possible, otherwise we simply clear the styles.
+    // It's probably not possible to have UXTHEME without ComCtl32 6 or better, but lets
+    // check it anyway.
+    const int verComCtl32 = wxApp::GetComCtl32Version();
+    if ( verComCtl32 == 600 )
+    {
+        // check if we use themes at all -- if we don't, we're still okay
+        if ( wxUxThemeEngine::GetIfActive() && (style & (wxBK_BOTTOM|wxBK_LEFT|wxBK_RIGHT)))
+        {
+            wxUxThemeEngine::GetIfActive()->SetWindowTheme((HWND)this->GetHandle(), L"", L"");
+            SetBackgroundColour(GetThemeBackgroundColour());    //correct the background color for the new non-themed control
+        }
+    }
+#endif // wxUSE_UXTHEME
+
+    // Undocumented hack to get flat notebook style
+    // In fact, we should probably only do this in some
+    // curcumstances, i.e. if we know we will have a border
+    // at the bottom (the tab control doesn't draw it itself)
+#if defined(__POCKETPC__) || defined(__SMARTPHONE__)
+    if (HasFlag(wxNB_FLAT))
+    {
+        SendMessage(GetHwnd(), CCM_SETVERSION, COMCTL32_VERSION, 0);
+        if (!m_hasBgCol)
+            SetBackgroundColour(*wxWHITE);
+    }
+#endif
+    return true;
+}
+
+WXDWORD wxNotebook::MSWGetStyle(long style, WXDWORD *exstyle) const
+{
+    WXDWORD tabStyle = wxControl::MSWGetStyle(style, exstyle);
+
+    tabStyle |= WS_TABSTOP | TCS_TABS;
+
+    if ( style & wxNB_MULTILINE )
+        tabStyle |= TCS_MULTILINE;
+    if ( style & wxNB_FIXEDWIDTH )
+        tabStyle |= TCS_FIXEDWIDTH;
+
+    if ( style & wxBK_BOTTOM )
+        tabStyle |= TCS_RIGHT;
+    else if ( style & wxBK_LEFT )
+        tabStyle |= TCS_VERTICAL;
+    else if ( style & wxBK_RIGHT )
+        tabStyle |= TCS_VERTICAL | TCS_RIGHT;
+
+    // ex style
+    if ( exstyle )
+    {
+        // note that we never want to have the default WS_EX_CLIENTEDGE style
+        // as it looks too ugly for the notebooks
+        *exstyle = 0;
+    }