How to convert X/Y pos to lParam? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

How to convert X/Y pos to lParam?

14 Jun 2021, 04:19

Code: Select all

OnMessage(0x200, "WM_MOUSEMOVE")

Gui, Show, w200 h100
return



WM_MOUSEMOVE(wParam, lParam) {
   MouseGetPos,X, Y
   LP := GetlParam(X, Y)
   FileAppend, lParam: %lParam% ========== LP: %LP%`n,*
}

GetLParam(LoWord, HiWord ) {
    return (HiWord << 16) | (LoWord & 0xffff)
}
How to convert a X/Y position to the same value returned in the lParam from the message WM_MOUSEMOVE?

LP value is different from lParam
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 04:55

WM_MOUSEMOVE's lParam wrote:The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper-left corner of the client area.
default coordmode mouse wrote:If this command is not used, all commands except those documented otherwise (e.g. WinMove and InputBox) use coordinates that are relative to the active window.
use CoordMode Mouse, Client
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 05:22

Code: Select all

WM_MOUSEMOVE(wParam, lParam) {

   CoordMode, Mouse, Client
   MouseGetPos,X, Y
   LP := GetlParam(X, Y)
   FileAppend, lParam: %lParam% ========== LP: %LP%`n,*

}
The values of LP and lParam still different


-Edit2- The values are not the same when the mouse is over a control like a listbox
Last edited by c7aesa7r on 14 Jun 2021, 05:54, edited 3 times in total.
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 05:54

@swagfag

Code: Select all

Gui, Add, Listbox, r5 w100, 1|2|3|4|5
Gui, Show, w200 h200
Return

WM_MOUSEMOVE(wParam, lParam) {
   DPARAM := LPARAM

   CoordMode, Mouse, Client
   MouseGetPos,X, Y
   LP := GetlParam(X, Y)
   FileAppend, lParam: %lParam% Lp: %LP%`n,*

}
Do you get the same value when the mouse is over the ListBox?
just me
Posts: 9442
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 06:07

Code: Select all

CoordMode, Mouse, Client
MouseGetPos, X, Y
is relative to the client area of the (parent) window, whereas lParam is relative to the client area of the control (child).
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 06:13

How i could get the lParam when the mouse is over a control then?
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 06:50

seems like u already got the code that does that

Code: Select all

CoordMode, Mouse, Client
   MouseGetPos,X, Y
   LP := GetlParam(X, Y)
   
 GetLParam(LoWord, HiWord ) {
    return (HiWord << 16) | (LoWord & 0xffff)
}
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 10:32

@swagfag

Code: Select all

gui,add,listbox, r5 w100, 1|2|3|4|5
gui, show, w200 h200
Return

WM_MOUSEMOVE(wParam, lParam) {
   
   CoordMode, Mouse, Client
   MouseGetPos,X, Y, Win, Control
   GuiControlGet, Hwnd, Hwnd, %Control%

   If (Control == "ListBox1") {

      lParam2 := x & 0xFFFF | (y & 0xFFFF) << 16
      
      FileAppend, lParam: %lParam% lParam2 %lparam2%`n,*
   }


}
Im using the lParam value with this sendmessage:

Code: Select all

SendMessage, ITEMFROMPOINT:=0x01A9, 0, %lParam%, , ahk_id %Hwnd%
Item := ErrorLevel
To get the current listbox item under the mouse. I don't know why , in my code (not this example above), it only return the correct ListBox item when i use the value from lParam, lParam2 return an incorrect item
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 11:50

because the
LB_ITEMFROMPOINT message's lparam wrote:... -coordinate of a point, relative to the upper-left corner of the client area of the list box.
ur constructed lParam2 contains coordinates relative to the GUI window's client area. in other words, ure trying to use the coordinates from a different frame of reference
c7aesa7r
Posts: 209
Joined: 02 Jun 2016, 21:09

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 13:59

I dont understand how to get the correct value of it
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: How to convert X/Y pos to lParam?  Topic is solved

14 Jun 2021, 15:55

Offset.

Code: Select all

#SingleInstance force

gui,add,listbox, r5 w100, 1|2|3|4|5
gui, show, w200 h200

OnMessage(0x200,"WM_MOUSEMOVE")

return
GuiClose:
	ExitApp

WM_MOUSEMOVE(wParam, lParam) {
	CoordMode, Mouse, Client
	MouseGetPos,X, Y, Win, Control
	GuiControlGet, Hwnd, Hwnd, %Control%
	GuiControlGet,pos,pos,% hwnd
	
   If (Control == "ListBox1") 
      ToolTip, % LBEX_ItemFromPoint(Hwnd, x-posx , y-posy)
}


;https://www.autohotkey.com/boards/viewtopic.php?t=4755
; ======================================================================================================================
; ItemFromPoint   Gets the index of the item nearest the specified point in a list box.
; Parameters:     X  -  The X-coordinate, relative to the upper-left corner of the client area of the list box.
;                 Y  -  The Y-coordinate, relative to the upper-left corner of the client area of the list box..
; Return values:  The return value contains the index of the nearest item in the LOWORD. The HIWORD is zero if the
;                 specified point is in the client area of the list box, or one if it is outside the client area.
; ======================================================================================================================
LBEX_ItemFromPoint(HLB, X, Y) {
   Static LB_ITEMFROMPOINT := 0x01A9
   X &= 0xFFFF
   Y &= 0xFFFF
   SendMessage, % LB_ITEMFROMPOINT, 0, % (X | (Y << 16)), , % "ahk_id " . HLB
   Return ((ErrorLevel & 0xFFFF) + 1) | (ErrorLevel & 0xFFFF0000)
}

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: How to convert X/Y pos to lParam?

14 Jun 2021, 17:22

and what was the point of doing all that...
if ure hovering over the listbox, the onmessage provided lparam already contains ur mouse coordinates encoded in the frame of reference of the listbox. simply pass that value as the sendmessage payload

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 109 guests