Results 1 to 21 of 21

Thread: Detect when a user clicks on a listview scrollbar code problem?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Detect when a user clicks on a listview scrollbar code problem?

    HI everyone again.

    I have made some changes to the project posted in http://vbnet.mvps.org/index.html?cod...api/index.html.

    For my attached project i just want to display a message when the user move down the list or drag the thumb control (I think
    thats the name for the little list position indicator?) down/up to scroll at a
    faster rate.

    The problem here is when the user drags the Thumb control of the listview scrollbar,
    what is happening is that the message box is posted several times and i dont know how to make it appear only one time.(i'm a novice in the API).

    Thanks for your help.
    Attached Files Attached Files

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Can someone give-me some help on this API code?

    Thanks

  3. #3
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Every time the user moves the scrollbar you're going to get a message. That's what it's supposed to be doing.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  4. #4
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    add a module level boolean.

    Once you've shown your message once (use Debug.Print for testing - not a MsgBox) set the boolean to True. Now three messages are sent after the scrolling has finished (and not during), they are WM_NCHITTEST, WM_NCMOUSEMOVE and WM_SETCURSOR. Listen for one of those and set the Boolean back to false.

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Hi Al42.

    What i want is:
    - when the user drags the thumbnail of the listview scrollbar i only want to make appear the msgbox one time.

    And this is not happening , because when i drag the thumbnail that message is displayed over and over, did you tryed this?

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Hi bushmobile.

    I didnt understand. i'm a API novice.

  7. #7
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    add a module level boolean, now in the WndProc listen for one of the messages i suggested:
    Code:
             Case WM_VSCROLL
                 Debug.Print "Fired"
                 bBoolean = True
             Case WM_NCMOUSEMOVE
                 bBoolean = False
    you'll have to look up the definition for WM_MOUSEMOVE

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    How can i add a module boolean?
    Is this just like adding a module?

    look up the definition for WM_MOUSEMOVE, why this?

    I'm not understand, this?

  9. #9
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    by module-level variable I mean one that can be accessed anywhere in the module.

    regarding WM_NCMOUSEMOVE - in the same way that you have WM_VSCROLL declared at the top of the form, you will also have to find out what WM_NCMOUSEMOVE should be declared as.

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Ok ,and why i have to look up the definition for WM_MOUSEMOVE?

  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    because the window messages that WndProc receives are just numbers - WM_VSCROLL doesn't mean anything to the computer - it only means something because you've declared it as &H115.

  12. #12

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Hi again bushmobile.

    i'm confused. For what reason do i have to declare a boolean variable, to skip a part of the code?

  13. #13
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    whoops, my bad - I forgot to make use of it:
    Code:
             Case WM_VSCROLL
                 If Not bBoolean Then
                     Debug.Print "Fired"
                     bBoolean = True
                 End If

  14. #14

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Quote Originally Posted by bushmobile
    whoops, my bad - I forgot to make use of it:
    Code:
             Case WM_VSCROLL
                 If Not bBoolean Then
                     Debug.Print "Fired"
                     bBoolean = True
                 End If
    Hi again Bushmobile.

    I have tried and i cant make the code to work.

    I have attached the project, take a look and please make it work.

    Thanks a lot.
    Attached Files Attached Files

  15. #15
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    a) you've got a glaring syntax error
    b) you haven't included any code for WM_NCMOUSEMOVE (or defined it)

    subclassing is a nightmare to debug because it'll fall over if you make any mistakes. When in the IDE run the project using Ctrl+F5, not F5 - so that it'll get checked for any silly compilation errors (which will show you a) immediately)

  16. #16

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Do i have to define the WM_NCMOUSEMOVE as a hexadecimal constante if yes why?

  17. #17
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    no it doesn't make a difference, Hex is just a way of representing a number - the computer sees only binary

  18. #18

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Ok it´s working, But i think I didn't explain the problem in the correct way.

    What the code is doing now is that the msgbox is displayed one time and then
    if i click again in the listview scrollbar nothing happens.
    But what i want is to display the message every time the user clicks or drags the thumnail of the scrollbar.
    I think that i have to reset the boolean variable some here in the code, right?

  19. #19
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: Detect when a user clicks on a listview scrollbar code problem?

    I think what you want is to show the last value when the user lets go of the button.

    Off the top of my head, save the value (in the same variable) every time you get a WM_VSCROLL message and,when you get the WM_NCMOUSEMOVE message, display the msgbox with the saved value.
    The most difficult part of developing a program is understanding the problem.
    The second most difficult part is deciding how you're going to solve the problem.
    Actually writing the program (translating your solution into some computer language) is the easiest part.

    Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.

    Please Help Us To Save Ana

  20. #20
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Detect when a user clicks on a listview scrollbar code problem?

    your WndProc should look like:
    Code:
    Friend Function WindowProc(hwnd As Long, msg As Long, wParam As Long, lParam As Long) As Long
        If hwnd = ListView1.hwnd Then
            Select Case msg
                Case WM_VSCROLL
                    If Not bBoolean Then
                        Debug.Print "Fired"
                        bBoolean = True
                    End If
                Case WM_NCMOUSEMOVE
                    bBoolean = False
            End Select
        End If
        WindowProc = CallWindowProc(GetProp(hwnd, "OldWindowProc"), hwnd, msg, wParam, lParam)
    End Function

  21. #21

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2006
    Posts
    292

    Re: Detect when a user clicks on a listview scrollbar code problem?

    Thanks a lot Bushmobile for your precious help.

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