Page 2 of 2 FirstFirst 12
Results 16 to 24 of 24
  1. #16
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    There are about 12 APIs that only work in a particular bitness. GetWindowLongPtr is 64-bit only.



    However the code with slight modifications works equally well in both 32-bit & 64-bit if you use GetWindowLong instead.
    No need for conditional compilation so it is much simpler

    APIs
    Code:
    Declare PtrSafe Function GetWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal wCmd As Long) As LongPtr'Declare PtrSafe Function GetWindowLongPtr Lib "user32" Alias "GetWindowLongPtrA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr 'NOT USED - 64-bit ONLY
    Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long) As Long 'Colin R -works in both 32-bit & 64-bit
    Declare PtrSafe Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As LongPtr, ByVal lpClassName As String, ByVal nMaxCount As Long) As Long
    Declare PtrSafe Function GetScrollInfo Lib "user32" (ByVal hwnd As LongPtr, ByVal n As Long, lpScrollInfo As SCROLLINFO) As Long
    
    Declare PtrSafe Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, ByVal wParam As LongPtr, lParam As Any) As LongPtr


    Get_Scrollbar_handle code reverts to what it was originally:

    Code:
      
    ...              
                    ' scrollbar found, get style and verify it's the one we want
                    ' (horiz = 137573172, vert = 137573173)
                    sbStyle = GetWindowLong(hWndSB, GWL_STYLE) 'Colin R                
                   ...


    See v2 attached

    With the exception of the few 64-bit only APIs such as GetWindowsLongPtr & GetTickCount64, conditional compilation is only needed to ensure code also works in 2007 and earlier. In such cases, I use conditional compilation code like this:

    Code:
    'APIs updated for 64/32-bit - Colin Riddington 16/09/2021
    #If VBA7 Then     ' 32/64 Bit Windows API calls for VBA 7 (A2010 or later)
        Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
            (ByVal hWnd As LongPtr, ByVal nIndex As Long) As Long
        
        Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
            (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Private Declare PtrSafe Function SetWindowOpacity Lib "user32" Alias "SetLayeredWindowAttributes" _
            (ByVal hWnd As LongPtr, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
        
        Public Declare PtrSafe Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
    
    
    #Else
        Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" _
            (ByVal hWnd As Long, ByVal nIndex As Long) As Long
        
        Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" _
            (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
        
        Private Declare Function SetWindowOpacity Lib "user32" Alias "SetLayeredWindowAttributes" _
            (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long
        
        Public Declare Sub Sleep Lib "kernel32" (ByVal lngMilliSeconds As Long)
    
    #End If


    You're quite right that I missed the
    hWndSb variable earlier but it did still work in 32-bit A365.
    Remember 32-bit VBA7 can use LongPtr variable correctly (handled as Long in 32-bit & LongLong in 64-bit).

    Many thanks for doing the conversion. Its given me an idea for another issue that I want to explore.
    Details to follow ... if my idea works


    Attached Files Attached Files
    Last edited by isladogs; 06-27-2022 at 01:26 PM.
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  2. #17
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for all the help with this. I want to expand my class to handle auto-syncing changes in the first subform's scrollbar(s) to the secon subform's scrollbar(s). Since there are no events triggered when you change a form's scrollbar position, the only way I can think of is to use a timer, and do something in the OnTimer event, such as comparing the new values to the previous values. I was hoping to use an API timer, so as to keep the processing encapsulated in the class object, and not conflict with any other required timers on the subforms.

    Unfortunately, my knowledge of API timers is somewhat lacking in VBA. If VBA is single-threaded, does that mean nothing in the class will be processed while the API timer is running? If this was VB.Net or C#, I could use various methods for this, but it's not. What are my options?

    1: Figure out Windows API timers, run the timer from the class. Is this going to impact other things in the class from happening?

    2: Rely on the subform's timer. If the class is told to auto-sync, it would set the subform's TimerInterval. This would require code in the subform's OnTimer method to call a class method to do the actual synchronization.
    - I like this because the form timers just work without worrying about code blocking (I think?). Of course have to worry about killing the timer.
    - I DON'T like this because it messes with the encapsulation you get from using the class object, and requires code in the form instead of just invoking the class and letting it do all the work.

    I will try the second method, simply because it is easier to do, and is within my knowledge of how to accomplish the task. I would also like to sync our code bases but will wait for your new version.

  3. #18
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I forgot to provide a link to my article on various timers: Timer Comparison Tests (isladogs.co.uk).
    In that article, I compare the use of 6 different timers
    At least one of these should suit your needs

    There is unfortunately no way of circumventing the Access single thread issue
    See if you can deduce the answers to those questions yourself - you'll probably get there before me as I have several other things I'm working on

    One of them is related to this and to two listbox threads - I'll email you my draft website article as it may interest you

    But I'm also still working other things including further info for my recent web article Recover Deleted Database Objects (isladogs.co.uk)
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  4. #19
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    I've made a very simple change using a standard form timer to get the scrollbar positions & allow auto sync scrolling.
    i.e. the second subform (SLAVE) moves automatically with the first (MASTER)

    Click image for larger version. 

Name:	Capture.PNG 
Views:	20 
Size:	33.7 KB 
ID:	48138

    If you like that idea, you can remove all the buttons from the form if you wish

    Hope that helps

    NOTE - scrolling the SLAVE does NOT auto scroll the MASTER

    Attached:
    The example file GetSetScrollbars_CR_v3.accdb & a short video video clip AutoSyncSubforms.MP4 to demonstrate the effect
    Attached Files Attached Files
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  5. #20
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    Thanks for all the work, Colin.

    I've been also working on a couple of things on the project and not being diligent about checking this forum.
    I have incorporated a timer class in the project, which uses an API timer, so no more form timers are needed.
    Also modified the sample form for more simplicity, while still allowing testing all functionality.

    My code allows either subform to be the "master", depending on how you set the SyncDirection property.

    Unfortunately I missed your post about the various API calls. So I have not updated my declarations. I am attaching the latest version. Probably will need to revisit your API post and create a new version with proper declarations.

    GetSetScrollbarsWithTimer.zip

  6. #21
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    No worries. I've also been very busy on other projects.
    Not yet had time to study your latest upload. Hopefully tomorrow

    In the meantime, I've solved my own similar issues with using a mouse move event to 'select' a row (without clicking it) on a listbox with a vertical scrollbar.
    I couldn't adapt the Lebans code to work with a listbox but adapted code from another of his examples

    Some mouse flicker still to be resolved but if interested see this short video clip : https://youtu.be/Uw4CEHPzNVA
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  7. #22
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Hi Ron
    You might be interested in the article I uploaded yesterday which used a modified version of another piece of code by Stephen Lebans to handle mouse move events in listboxes with scrollbars
    Listbox Mouse Move Item Tooltips (isladogs.co.uk)
    Unfortunately, the mouse move code for use with scrollbars isn't as accurate as the original code using the Wizhook function but it works well enough for the purpose described in the article.

    I'm also intending to update the earlier article Synchronise SubForm Scrolling (isladogs.co.uk) to reference the solution based on GetSetScrollbarPosition.
    If its OK with you, I'll include a modified version of the code from this thread with acknowledgements given to your hard work
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

  8. #23
    RMittelman is offline Advanced
    Windows 10 Access 2016
    Join Date
    Dec 2010
    Location
    Simi Valley, CA
    Posts
    211
    I've made a few changes in the GetSetScrollbars class and main form, including refactoring code and declaring and setting Form objects for each subform in the main form. Also added code to prevent errors in main form code if either subform has not yet been created yet. Also fixed any code in first subform which references second subform but second subform has not yet been created.

    GetSetScrollbarsWithTimer.zip

  9. #24
    isladogs's Avatar
    isladogs is offline MVP / VIP
    Windows 10 Office 365
    Join Date
    Jan 2014
    Location
    Somerset, UK
    Posts
    5,954
    Thanks Ron
    I've downloaded it & will look at it properly in the next few days before I update my web article
    Colin, Access MVP, Website, email
    The more I learn, the more I know I don't know. When I don't know, I keep quiet!
    If I don't know that I don't know, I don't know whether to answer

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 53
    Last Post: 07-16-2022, 12:02 PM
  2. Replies: 4
    Last Post: 01-16-2018, 02:51 AM
  3. Replies: 0
    Last Post: 12-29-2016, 11:19 PM
  4. Replies: 2
    Last Post: 03-14-2014, 05:42 PM
  5. Vertical scrollbar issues with a subform
    By vange2013 in forum Forms
    Replies: 1
    Last Post: 11-27-2013, 09:13 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums