convert Long to Mouse Co-ordinates?

dynamic_sysop

Senior Contributor
Joined
Oct 1, 2002
Messages
1,039
Location
Ashby, Leicestershire.
hi could someone tell me if it's possible to convert a Long to the co-ordinates of the mouse within an item ( eg: i have a listview subclassed in vb.net and when i click on an item in it , i want the co-ordinates like 10 = x , 15 = y )
when i view the lParam for mouse move i get this for the values...
Message: WM_MOUSEMOVE 512 - wParam 0 - lParam (mouse point on parent hWnd) 655361
the "655361" being the mouse co-ordinates , but in vb6 i'd get this
Message: WM_MOUSEMOVE 512 - wParam 0 - lParam (mouse point on parent hWnd) 327690
the "327" being x=8 , the "690" being y=10

i need to get the exact co-ords so that i can then carry out a HITTEST followed by a LVM_GETITEMTEXT
cheers.
 
Mod is a mathematical operator that does division and returns the
remainder. The \ is a division operator that returns a whole
number without the remainder.

So, if l is the Long (it should be an Integer, actually, since that is
32-bit), then...

Visual Basic:
Dim x, y As Integer

x = l Mod 65536
y = l \ 65536
 
the code to convert to the position returns this x = 0 y = 0 no matter where i click :-\
Code:
Public Sub sClass_WindowProcedure(ByRef uMsg As Message) Handles sClass.WindowProcedure
        Select Case uMsg.Msg
            Case WM_LBUTTONDOWN
                Dim l As Int32 ' <<< this i tried as integer and Long
                Dim x, y As Integer

                x = l Mod uMsg.LParam.ToInt32
                y = l \ uMsg.LParam.ToInt32
                Addit("x = " & x & " y = " & y)
                ' Addit("Message: WM_LBUTTONDOWN " & " : " & uMsg.Msg.ToString & " - wParam " & uMsg.WParam.ToInt32 & " - lParam " & uMsg.LParam.ToInt32 & " ")
            Case WM_MOUSEMOVE
                Addit("Message: WM_MOUSEMOVE " & uMsg.Msg.ToString & " - wParam " & uMsg.WParam.ToString & " - lParam (mouse point on parent hWnd) " & uMsg.LParam.ToString)
            Case WM_PAINT
                Addit("WM_PAINT " & uMsg.Msg.ToString & " - wParam " & uMsg.WParam.ToInt32 & " - lParam " & uMsg.LParam.ToInt32)
        End Select
    End Sub
when i receive the WM_LBUTTONDOWN or mouse move, i need the exact co-ordinates for the Hittest that i wish to carry out , but all i get back is zero's.
someone must have an idea how i can get the co-ords ( zero being left / top of the subclassed item ie: the listview , not the co-ords of the form )
 
l was referring to the LParam passed to your code. You should be doing this:

Visual Basic:
Case WM_LBUTTONDOWN
  x = uMsg.LParam Mod 65536
  y = uMsg.LParam \ 65536
 
cheers it works great ,this is really weird , when i posted the message to start with this is a snippet...
lParam (mouse point on parent hWnd) 655361
the lParam at the time of posting was 655361 , so when i saw you put 65536 i was putting the current lParam there , but it turns out 655361 & 65536 are 2 totally different things lol.
what are the chances of getting an lParam and posting it and then finding out the function you need to use to get the co-ordinates of the mouse are identical to that lParam apart from a 1 :-\ .
cheers for the help guys:D
 
1 other thing, i'm trying to use SendMessage to carry out the HITTEST
Code:
    Public Structure HITTESTINFO
        Dim pt As POINTAPI
        Dim flags As Long
        Dim iItem As Long
        Dim iSubItem As Long
    End Structure

   Public Sub sClass_WindowProcedure(ByRef uMsg As Message) Handles sClass.WindowProcedure
        Select Case uMsg.Msg
            Case WM_LBUTTONDOWN
                Dim hdr As HITTESTINFO
                Dim l As Integer
                Dim x, y As Integer
                With hdr
                    .pt.x = uMsg.LParam.ToString Mod 65536
                    .pt.y = uMsg.LParam.ToString \ 65536
                End With
                l = SendMessage(uMsg.HWnd.ToInt32, LVM_HITTEST, 0, hdr)
                Addit(l) '/// show the currently selected listitem number in a textbox
end sub

all i seem to get is the value "0" no matter which item i HITTEST
can i still use SendMessage or is there an alternative way?
 
Just out of interest why are you using the ToString operator in the two lines of code near the end?

Visual Basic:
.pt.x = uMsg.LParam.ToString Mod 65536
.pt.y = uMsg.LParam.ToString \ 65536
converting the LParam to a string can only introduce errors.
 
How is your SendMessage function declared?

And yes, you should be using .ToInt32, not .ToString on the lParam.
 
Code:
   <StructLayout(LayoutKind.Sequential)> _
       Public Structure HITTESTINFO
        Dim pt As POINTAPI
        Dim flags As Long
        Dim iItem As Long
        Dim iSubItem As Long
    End Structure
    <StructLayout(LayoutKind.Sequential)> _
        Public Structure LV_ITEM
        Dim mask As Long
        Dim iItem As Long
        Dim iSubItem As Long
        Dim state As Long
        Dim stateMask As Long
        Dim pszText As String
        Dim cchTextMax As Long
        Dim iImage As Long
        Dim lParam As Long
        Dim iIndent As Long
    End Structure
then i'm having to use SendMessage this way...
Code:
    Public Declare Function SendMessage Lib "user32" Alias "SendMessageW" (ByRef hWnd As Integer, ByRef wMsg As Integer, ByRef wParam As Integer, ByRef lParam As Object) As Integer
because if i use the "<dllimport("user32”)> _" and "Shared Function" method, i get an error in this line ....
Code:
  Protected Overrides Sub WndProc(ByRef uMsg As System.Windows.Forms.Message)
        RaiseEvent WindowProcedure(uMsg)
        MyBase.WndProc(uMsg)'//// ERROR HERE " NULL"
    End Sub
:confused:
 
Back
Top