+ if (pParent)
+ hWndParent = GetHwndOf(pParent);
+ else
+ hWndParent = GetHwnd();
+ hWndClient = hWndParent;
+ }
+ ::WinQueryWindowPos(hWndClient, &vSwp);
+ ::WinQueryWindowPos(hWnd, &vSwpOwner);
+
+ if (nPageSize > 1 && nRange > 0)
+ {
+ nRange1 += (nPageSize - 1);
+ }
+
+ vInfo.cb = sizeof(SBCDATA);
+ vInfo.posFirst = 0;
+ vInfo.posLast = (SHORT)nRange1;
+ vInfo.posThumb = nPos;
+
+ if (nOrient == wxHORIZONTAL )
+ {
+ ulStyle |= SBS_HORZ;
+ if (m_hWndScrollBarHorz == 0L)
+ {
+ //
+ // Since the scrollbars are usually created before the owner is
+ // sized either via an OnSize event directly or via sizers or
+ // layout constraints, we will initially just use the coords of
+ // the parent window (this is usually a frame client window). But
+ // the bars themselves, are children of the parent frame (i.e
+ // siblings of the frame client. The owner, however is the actual
+ // window being scrolled (or at least the one responsible for
+ // handling the scroll events). The owner will be resized later,
+ // as it is usually a child of a top level window, and when that
+ // is done its scrollbars will be resized and repositioned as well.
+ //
+ m_hWndScrollBarHorz = ::WinCreateWindow( hWndParent
+ ,WC_SCROLLBAR
+ ,(PSZ)NULL
+ ,ulStyle
+ ,vSwp.x
+ ,vSwp.y
+ ,vSwp.cx - 20
+ ,20
+ ,hWnd
+ ,HWND_TOP
+ ,60000
+ ,&vInfo
+ ,NULL
+ );
+ }
+ else
+ {
+ //
+ // The owner (the scrolled window) is a child of the Frame's
+ // client window, usually. The scrollbars are children of the
+ // frame, itself, and thus are positioned relative to the frame's
+ // origin, not the frame's client window origin.
+ // The starting x position is the same as the starting x position
+ // of the owner, but in terms of the parent frame.
+ // The starting y position is 20 pels below the origin of the
+ // owner in terms of the parent frame.
+ // The horz bar is the same width as the owner and 20 pels high.
+ //
+ if (nRange1 >= nThumbVisible)
+ {
+ ::WinSetWindowPos( m_hWndScrollBarHorz
+ ,HWND_TOP
+ ,vSwp.x + vSwpOwner.x
+ ,(vSwp.y + vSwpOwner.y) - 20
+ ,vSwpOwner.cx
+ ,20
+ ,SWP_MOVE | SWP_SIZE | SWP_SHOW | SWP_ACTIVATE | SWP_ZORDER
+ );
+ ::WinSendMsg( m_hWndScrollBarHorz
+ ,SBM_SETSCROLLBAR
+ ,(MPARAM)nPos
+ ,MPFROM2SHORT(0, (SHORT)nRange1)
+ );
+ ::WinSendMsg( m_hWndScrollBarHorz
+ ,SBM_SETTHUMBSIZE
+ ,MPFROM2SHORT( (SHORT)nThumbVisible
+ ,(SHORT)nRange1
+ )
+ ,(MPARAM)0
+ );
+ }
+ else
+ ::WinShowWindow(m_hWndScrollBarHorz, FALSE);
+ }
+ }
+ else
+ {
+ ulStyle |= SBS_VERT;
+ if (m_hWndScrollBarVert == 0L)
+ {
+ //
+ // Since the scrollbars are usually created before the owner is
+ // sized either via an OnSize event directly or via sizers or
+ // layout constraints, we will initially just use the coords of
+ // the parent window (this is usually a frame client window). But
+ // the bars themselves, are children of the parent frame (i.e
+ // siblings of the frame client. The owner, however is the actual
+ // window being scrolled (or at least the one responsible for
+ // handling the scroll events). The owner will be resized later,
+ // as it is usually a child of a top level window, and when that
+ // is done its scrollbars will be resized and repositioned as well.
+ //
+ m_hWndScrollBarVert = ::WinCreateWindow( hWndParent
+ ,WC_SCROLLBAR
+ ,(PSZ)NULL
+ ,ulStyle
+ ,vSwp.x + vSwp.cx - 20
+ ,vSwp.y + 20
+ ,20
+ ,vSwp.cy - 20
+ ,hWnd
+ ,HWND_TOP
+ ,60001
+ ,&vInfo
+ ,NULL
+ );
+ }
+ else
+ {
+ //
+ // The owner (the scrolled window) is a child of the Frame's
+ // client window, usually. The scrollbars are children of the
+ // frame, itself and thus are positioned relative to the frame's
+ // origin, not the frame's client window's origin.
+ // Thus, the x position will be frame client's x (usually a few
+ // pels inside the parent frame, plus the width of the owner.
+ // Since we may be using sizers or layout constraints for multiple
+ // child scrolled windows, the y position will be the frame client's
+ // y pos plus the scrolled windows y position, yielding the y
+ // position of the scrollbar relative to the parent frame (the vert
+ // scrollbar is on the right and starts at the bottom of the
+ // owner window).
+ // It is 20 pels wide and the same height as the owner.
+ //
+ if (nRange1 >= nThumbVisible)
+ {
+ ::WinSetWindowPos( m_hWndScrollBarVert
+ ,HWND_TOP
+ ,vSwp.x + vSwpOwner.x + vSwpOwner.cx
+ ,vSwp.y + vSwpOwner.y
+ ,20
+ ,vSwpOwner.cy
+ ,SWP_ACTIVATE | SWP_MOVE | SWP_SIZE | SWP_SHOW
+ );
+ ::WinSendMsg( m_hWndScrollBarVert
+ ,SBM_SETSCROLLBAR
+ ,(MPARAM)nPos
+ ,MPFROM2SHORT(0, (SHORT)nRange1)
+ );
+ ::WinSendMsg( m_hWndScrollBarVert
+ ,SBM_SETTHUMBSIZE
+ ,MPFROM2SHORT( (SHORT)nThumbVisible
+ ,(SHORT)nRange1
+ )
+ ,(MPARAM)0
+ );
+ }
+ else
+ ::WinShowWindow(m_hWndScrollBarVert, FALSE);
+ }