Jump to content
Xtreme .Net Talk

Recommended Posts

  • Leaders
Posted

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.

  • Leaders
Posted
The x coordinate will be l Mod 65536, the y coordinate will be l \ 65536.

what would that equate to?

or should i say how do i do the above:-\ is l a long or an integer or something and is the "Mod" an expresion?

cheers.

  • *Experts*
Posted

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...

 

Dim x, y As Integer

x = l Mod 65536
y = l \ 65536

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • Leaders
Posted

the code to convert to the position returns this x = 0 y = 0 no matter where i click :-\

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 )

  • Leaders
Posted

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

  • Leaders
Posted

1 other thing, i'm trying to use SendMessage to carry out the HITTEST

   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?

  • Administrators
Posted

Just out of interest why are you using the ToString operator in the two lines of code near the end?

 

.pt.x = uMsg.LParam.ToString Mod 65536
.pt.y = uMsg.LParam.ToString \ 65536

converting the LParam to a string can only introduce errors.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Leaders
Posted

  <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...

   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 ....

 Protected Overrides Sub WndProc(ByRef uMsg As System.Windows.Forms.Message)
       RaiseEvent WindowProcedure(uMsg)
       MyBase.WndProc(uMsg)'//// ERROR HERE " NULL"
   End Sub

:confused:

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...