Results 1 to 11 of 11

Thread: Invalid use of AddressOf operator

  1. #1

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Invalid use of AddressOf operator

    Hi Guys,

    This is part of my code to create a drag image of the treeview item being dragged:

    Code:
    Public Sub TreeView_StartDrag( _
       ByVal hWndTreeView As Long, _
       Optional ByVal x As Long = 20, _
       Optional ByVal y As Long = 20)
    Dim tPoint As POINTL
    Dim hItem As Long
    
       ' Get the selected node
       hItem = SendMessage(hWndTreeView, TVM_GETNEXTITEM, TVGN_DROPHILITE, ByVal 0&)
       
       ' Get a ImageList with the drag image
       m_lIL = SendMessage(hWndTreeView, TVM_CREATEDRAGIMAGE, 0, ByVal hItem)
       
       ' Start the image dragging
       ImageList_BeginDrag m_lIL, 0, x, y
       ImageList_DragEnter 0, 0, 0
       
       ' Start the timer
       m_lTimer = SetTimer(0, 0, 1, AddressOf pvTimerDragMove)
    
    End Sub
    
    Private Sub pvTimerDragMove( _
       ByVal hWnd As Long, _
       ByVal uMsg As Long, _
       ByVal idEvent As Long, _
       ByVal dwTime As Long)
    Dim tPoint As POINTL
       
       ' Get the cursor position
       GetCursorPos tPoint
    
       ' Move the image to the new cursor position
       ImageList_DragMove tPoint.x, tPoint.y
       
    End Sub
    I get an invalid use of AddressOf operator on the line I have highlighted in red. Please help

  2. #2
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Invalid use of AddressOf operator

    You can only use AddressOf to point to something in a .Bas module. pvTimerDragMove must be in a Module as opposed to a Form

  3. #3

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Invalid use of AddressOf operator

    Thanks Doogle,

    That fixed the problem.

    I am using the code from this site:

    http://www.mvps.org/emorcillo/en/cod...ropimage.shtml

    but it isn't creating the drag image. could someone please test this code. I would post my project but I have stored procedures for populating my treeview.

  4. #4

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Invalid use of AddressOf operator

    Guys, these to lines always return 0.

    Code:
    hItem = SendMessage(hWndTreeView, TVM_GETNEXTITEM, TVGN_DROPHILITE, ByVal 0&)
       
       ' Get a ImageList with the drag image
       m_lIL = SendMessage(hWndTreeView, TVM_CREATEDRAGIMAGE, 0, ByVal hItem)
    hitem and m_lIL are always zero

  5. #5
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Invalid use of AddressOf operator

    Have you looked at Err.LastDllError after the first sendmessage fails. It may give you a hint as to what's wrong.

  6. #6

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Invalid use of AddressOf operator

    Hi Doogle,

    It returns 0.

  7. #7
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Invalid use of AddressOf operator

    So it's not 'failing' in that sense, looking at the documentation for the message (http://msdn2.microsoft.com/en-us/lib...22(VS.85).aspx) the remarks say
    This message will return NULL if the item being retrieved is the root node of the tree.
    Perhaps that's the problem(?)

  8. #8

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Invalid use of AddressOf operator

    these are the values I assign to those variables:

    Code:
    Const TVM_CREATEDRAGIMAGE = &H1100& + 18
    Const TVM_GETNEXTITEM = &H1100& + 10
    Const TVGN_DROPHILITE = &H8

  9. #9
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Invalid use of AddressOf operator

    Thpse values look ok to me. If they were incorrect I suspect you'd see a non-zero Err.LastDllError. Is the drop target the roor of the treeview?

  10. #10

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Invalid use of AddressOf operator

    No it isn't. Those variables need to take on a value greater than zero once the dragging begins. That doesn't happen. I'm assuming that is why no image gets created.

  11. #11

    Thread Starter
    PowerPoster Nitesh's Avatar
    Join Date
    Mar 2007
    Location
    Death Valley
    Posts
    2,556

    Re: Invalid use of AddressOf operator

    Hey Guys, I think I fixed it ,

    I added this into my module:

    Code:
    Private Const TVGN_CARET = 9
    and changed this line to the following:

    Code:
    hitem = SendMessage(hWndTreeView, TVM_GETNEXTITEM, TVGN_CARET, ByVal 0&)
    seems right. Can anyone verify that I am right please.

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