Understanding lParam / wParam - WM_MOVE message Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Understanding lParam / wParam - WM_MOVE message

13 Sep 2019, 04:03

I'm trying to get into fully wrapping my brain around windows messages. I'm starting with WM_MOVE, lParam.

https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-move

How exactly are the x/y coordinates stored in lParam? Are they just single 2-character hex bytes smashed together to get a total of 4 characters?

I know the "right" way to approach this to also consider endianness. Do we mostly assume when using VarSetCapacity(), NumGet(), NumPut() that most endianness goes left-to-right?

I'm trying to come up with the right questions... and I'm not sure if I'm actually doing that, so I'm not sure if I'm missing something critical.

I've read through this page, regarding structures in AutoHotkey, and it totally makes sense. But properly converting decimal to hex, and hex to decimal, and retrieving high order/low order bytes and words is still a bit confusing, and sounds like something i need to understand for the sake of the computer I'm about to test this on.

Any help or reference linking would be appreciated. I am a novice in understanding math using binary / bytes etc, and the operators that make it all happen.
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Understanding lParam / wParam - WM_MOVE message  Topic is solved

26 Sep 2019, 17:25

endianness on wikipedia should cover most of this

abridged, windows is little endian. u store numbers starting from their Least significant byte until their Most significant byte, eg 0x12345678 would get stored at a particular address in memory as 0x78, 0x56, 0x34, 0x12, in that order. 0xHhHh is the HIWORD in 0xHhHhLlLl, 0xLlLl - the LOWORD. if u use NumGet with the correct type (eg, DWORD(ahk UInt)), it will handle the endianness reordering automatically for u.

of course, u are free to fetch bytes(UChar) one at a time urself, too, but then u have to make sure u bitshift them into place correctly. a naive approach(reading them off as they appear in memory and mashing them together, as u put it) would leave u with the wrong number, 0x78563412, and wrong coordinates(if u simply use the macro on the number) 0xL1L2H2H1
Odlanir
Posts: 659
Joined: 20 Oct 2016, 08:20

Re: Understanding lParam / wParam - WM_MOVE message

27 Sep 2019, 03:30

I use this to get coords from lParam:

Code: Select all

PointFromLParam(lParam) {
	static point := {}
	point.x := lParam & 0xFFFF
	point.y := lParam >> 16
	return point
}
____________________________________________________________________________
Windows 10 Pro 64 bit - Autohotkey v1.1.30.01 64-bit Unicode
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: Understanding lParam / wParam - WM_MOVE message

27 Sep 2019, 15:26

Some examples, covering most points:

Code: Select all

;q:: ;joining and splitting words (Short) to/from longs (Int)

;split a number:
vNum := 0xAABBCCDD
vHiWord := HIWORD(vNum)
vLoWord := LOWORD(vNum)
MsgBox, % Format("0x{:X}", vHiWord) ;0xAABB
MsgBox, % Format("0x{:X}", vLoWord) ;0xCCDD

;'concatenate' numbers:
vNum := MAKELONG(vLoWord, vHiWord)
MsgBox, % Format("0x{:X}", vNum) ;0xAABBCCDD

;store a number as binary data, view the bytes:
VarSetCapacity(vData, 4)
NumPut(vNum, &vData, 0, "UInt")
vHex := ""
Loop 4
	vUChar := NumGet(&vData, A_Index-1, "UChar")
	, vHex .= Format("{:02X}", vUChar) " "
MsgBox, % vHex ;DD CC BB AA
return

'==================================================

;MakeXXX macros (MAKEWORD, MAKELONG etc) - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=6&t=68367

MAKELONG(l, h)
{
	return (l & 0xffff) | (h & 0xffff) << 16
}
LOWORD(l)
{
	return l & 0xffff
}
HIWORD(l)
{
	return (l >> 16) & 0xffff
}

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: Understanding lParam / wParam - WM_MOVE message

28 Sep 2019, 03:43

Wow guys! Thanks for this! I'll dive into Wikipedia and try to educate myself. Thanks for the knowledge, explanation, and AutoHotkey examples. That will help me tie things together in my brain.

Thanks again!

EDIT: @jeeswg & @Odlanir
I have been looking for the equivelant of these functions for a while! Huge thanks!
Makes me wish I knew enough to be able to write them myself ... they seem really simple. I just haven't yet wrapped my brain around operators that aren't the basics + - / *
I'm trying!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, mikeyww, Nerafius, scriptor2016 and 85 guests