Leaders dynamic_sysop Posted May 18, 2003 Leaders Posted May 18, 2003 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. Quote
*Gurus* divil Posted May 18, 2003 *Gurus* Posted May 18, 2003 The x coordinate will be l Mod 65536, the y coordinate will be l \ 65536. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Leaders dynamic_sysop Posted May 18, 2003 Author Leaders Posted May 18, 2003 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. Quote
*Experts* Bucky Posted May 19, 2003 *Experts* Posted May 19, 2003 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 Quote "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 dynamic_sysop Posted May 19, 2003 Author Leaders Posted May 19, 2003 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 ) Quote
*Gurus* divil Posted May 19, 2003 *Gurus* Posted May 19, 2003 l was referring to the LParam passed to your code. You should be doing this: Case WM_LBUTTONDOWN x = uMsg.LParam Mod 65536 y = uMsg.LParam \ 65536 Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Leaders dynamic_sysop Posted May 19, 2003 Author Leaders Posted May 19, 2003 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 Quote
Leaders dynamic_sysop Posted May 19, 2003 Author Leaders Posted May 19, 2003 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? Quote
Administrators PlausiblyDamp Posted May 19, 2003 Administrators Posted May 19, 2003 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
*Gurus* divil Posted May 20, 2003 *Gurus* Posted May 20, 2003 How is your SendMessage function declared? And yes, you should be using .ToInt32, not .ToString on the lParam. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Leaders dynamic_sysop Posted May 20, 2003 Author Leaders Posted May 20, 2003 <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: Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.