Results 1 to 5 of 5

Thread: [RESOLVED] How to Position API Scrollbar (by ShowScrollBar)

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Resolved [RESOLVED] How to Position API Scrollbar (by ShowScrollBar)

    Actually, I want to use VB's H/VScrollbar control, But there's a famous limit 32767 (there're some solution but complicated). I have to use VBAccelerator's API scrollbar. But it brings new issue: I can't position the scrollbar in code, it automatically position aside/bottom of container UserControl. In result, I can't use DrawEdge API to set my styles for UC's edge (I want to some offsets for BorderStyle such as 3 pixel).

    Question:
    1. How to solve 32767 issue by simply way. I need Long value instead of Integer.
    2. If we use API scrollbar, how to position it?

    Refer to sample @ http://www.vbforums.com/showthread.p...=1#post4663499

    Edited:
    In my UC,I found:
    1. UserControl.ScaleWidth and UserControl.ScaleHeight is similar with C# ClientSize.
    2. If don't have API VScrollbar (hidden),ScaleX(UserControl.Width,vbTwips,vbPixels)= UserControl.ScaleWidth (Unit: Pixel)
    3. If have API VScrollbar (Shown),ScaleX(UserControl.Width,vbTwips,vbPixels)= UserControl.ScaleWidth (Unit: Pixel) + GetSystemMetrics(SM_CXVSCROLL) 'SM_CXVSCROLL=2 : The width of a vertical scroll bar, in pixels.

    Got Same result for API HScrollbar.
    Last edited by Jonney; Dec 5th, 2014 at 10:12 AM.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Position API Scrollbar (by ShowScrollBar)

    Well, the 32767 limit can be extended to 65535, max unsigned value of an integer.

    These functions created on the fly and can be optimized/recoded as needed
    Code:
    Private Function pvVBScrollBarMax(VBsb As Object, Optional newMax As Variant) As Long
        If IsMissing(newMax) Then
            pvVBScrollBarMax = VBsb.Max And &HFFFF&
        ElseIf (CLng(newMax) And &H8000&) = 0& Then
            VBsb.Max = newMax
        Else
            VBsb.Max = CInt(newMax And &H7FFF) Or &H8000
        End If
    End Function
    Private Function pvVBScrollBarValue(VBsb As Object, Optional newValue As Variant) As Long
        If IsMissing(newValue) Then
            pvVBScrollBarValue = VBsb.Value And &HFFFF&
        ElseIf (CLng(newValue) And &H8000&) = 0& Then
            VBsb.Value = newValue
        Else
            VBsb.Value = CInt(newValue And &H7FFF) Or &H8000
        End If
    End Function
    To set a scrollbar's max or value property: pass the 2nd parameter as number between 0 & 65535. Ignore the return value
    To get the scrollbar's max or value property: do not include the 2nd parameter. Return value is long

    For a simple test, add a horizontal scrollbar and put this code in a button's click event
    Code:
        Dim x As Long, lMax As Long
        Do
            lMax = pvVBScrollBarMax(HScroll1) + 300
            pvVBScrollBarMax HScroll1, lMax
        Loop Until lMax + 300 > 65535
        pvVBScrollBarValue HScroll1, lMax
        Debug.Print pvVBScrollBarValue(HScroll1)
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to Position API Scrollbar (by ShowScrollBar)

    Quote Originally Posted by LaVolpe View Post
    Well, the 32767 limit can be extended to 65535, max unsigned value of an integer.

    These functions created on the fly and can be optimized/recoded as needed
    Code:
    Private Function pvVBScrollBarMax(VBsb As Object, Optional newMax As Variant) As Long
        If IsMissing(newMax) Then
            pvVBScrollBarMax = VBsb.Max And &HFFFF&
        ElseIf (CLng(newMax) And &H8000&) = 0& Then
            VBsb.Max = newMax
        Else
            VBsb.Max = CInt(newMax And &H7FFF) Or &H8000
        End If
    End Function
    Private Function pvVBScrollBarValue(VBsb As Object, Optional newValue As Variant) As Long
        If IsMissing(newValue) Then
            pvVBScrollBarValue = VBsb.Value And &HFFFF&
        ElseIf (CLng(newValue) And &H8000&) = 0& Then
            VBsb.Value = newValue
        Else
            VBsb.Value = CInt(newValue And &H7FFF) Or &H8000
        End If
    End Function
    To set a scrollbar's max or value property: pass the 2nd parameter as number between 0 & 65535. Ignore the return value
    To get the scrollbar's max or value property: do not include the 2nd parameter. Return value is long

    For a simple test, add a horizontal scrollbar and put this code in a button's click event
    Code:
        Dim x As Long, lMax As Long
        Do
            lMax = pvVBScrollBarMax(HScroll1) + 300
            pvVBScrollBarMax HScroll1, lMax
        Loop Until lMax + 300 > 65535
        pvVBScrollBarValue HScroll1, lMax
        Debug.Print pvVBScrollBarValue(HScroll1)
    I need 2^32 Long type. 65535 is not enough for my case.

  4. #4
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to Position API Scrollbar (by ShowScrollBar)

    The problem with positioning is that you are using APIs that create scrollbars for a window, not a detached scrollbar. Window scrollbars are positioned at bottom and/or right of the window. You can't adjust the position.

    You can still use a VB scrollbar, but you would keep the actual max & current values in variables. The scrollbar position would be an approximate of the actual value. The max & current values of the scrollbar would be ratios of the current & max variable values. There would no longer be a 1:1 ratio.

    Another option is to create the scrollbar via APIs, i.e., CreateWindowEx. But that requires subclassing the scrollbar and handling many of the messages.

    Edited: Oh, hey, here's an idea for your UC
    Add a picturebox, borderless, that will be used for the VB Accelerator scrollbar. Add a scrollbar to that picbox's hWnd, now position the picbox where you want after sizing it as needed
    Last edited by LaVolpe; Dec 5th, 2014 at 11:28 AM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2010
    Posts
    1,103

    Re: How to Position API Scrollbar (by ShowScrollBar)

    Quote Originally Posted by LaVolpe View Post
    The problem with positioning is that you are using APIs that create scrollbars for a window, not a detached scrollbar. Window scrollbars are positioned at bottom and/or right of the window. You can't adjust the position.

    You can still use a VB scrollbar, but you would keep the actual max & current values in variables. The scrollbar position would be an approximate of the actual value. The max & current values of the scrollbar would be ratios of the current & max variable values. There would no longer be a 1:1 ratio.

    Another option is to create the scrollbar via APIs, i.e., CreateWindowEx. But that requires subclassing the scrollbar and handling many of the messages.

    Edited: Oh, hey, here's an idea for your UC
    Add a picturebox, borderless, that will be used for the VB Accelerator scrollbar. Add a scrollbar to that picbox's hWnd, now position the picbox where you want after sizing it as needed
    Your three solutions are very good. I choose the last.
    Thank you,Sir.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width