Any help converting this to expression syntax?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
evilC
Posts: 4823
Joined: 27 Feb 2014, 12:30

Any help converting this to expression syntax?

21 Jul 2017, 05:25

I found some code in bug.n that provides a WinMove equivalent that works properly with AeroSnap, however the code uses assume-global and horrid syntax - I am trying to re-write it.

However, I am stuck on this line, I cannot work out what the logic actually means:

Code: Select all

If Not wndId Window_getPosEx(wndId, wndX, wndY, wndW, wndH) And (Abs(wndX - x) < 2 And Abs(wndY - y) < 2 And Abs(wndW - width) < 2 And Abs(wndH - height) < 2)
    Return, 0
It's the If Not wndId Window_getPosEx bit at the start which is totally baffling me. WTF is this saying??

https://github.com/fuhsjr00/bug.n/blob/ ... w.ahk#L247
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Any help converting this to expression syntax?

21 Jul 2017, 05:32

For me it looks like this in ahk ^^

Code: Select all

if !(wndId := Window_getPosEx(wndId, wndX, wndY, wndW, wndH))
&&  (Abs(wndX - x) < 2)
&&  (Abs(wndY - y) < 2)
&&  (Abs(wndW - width) < 2)
&&  (Abs(wndH - height) < 2)
    return 0
btw.. his coding style is horrible ^^
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Any help converting this to expression syntax?

21 Jul 2017, 05:39

His coding style is horrible ^^

Code: Select all

Window_getPosEx(hWindow, ByRef X = "", ByRef Y = "", ByRef Width = "", ByRef Height = "", ByRef Offset_X = "", ByRef Offset_Y = "") {
	; ...
	return &RECTPlus
}

Code: Select all

Window_move(wndId, x, y, width, height) {
	if !(wndId) ????????? Window_getPosEx(wndId, wndX, wndY, wndW, wndH)    ; <- this makes no sense
	&&  (Abs(wndX - x) < 2)
	&&  (Abs(wndY - y) < 2)
	&&  (Abs(wndW - width) < 2)
	&&  (Abs(wndH - height) < 2)
		return 0
}

Code: Select all

if !(wndId)
??  Window_getPosEx(wndId, wndX, wndY, wndW, wndH)    ; <- should be ! (not addr)
&&  (Abs(wndX - x) < 2)
&&  (Abs(wndY - y) < 2)
&&  (Abs(wndW - width) < 2)
&&  (Abs(wndH - height) < 2)
or better this way:

Code: Select all

Window_getPosEx(wndId, wndX, wndY, wndW, wndH)

if !(wndId)
&&  (Abs(wndX - x) < 2)
&&  (Abs(wndY - y) < 2)
&&  (Abs(wndW - width) < 2)
&&  (Abs(wndH - height) < 2)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
Contact:

Re: Any help converting this to expression syntax?

21 Jul 2017, 05:47

This is what I expect

Code: Select all

addr := Window_getPosEx(wndId, wndX, wndY, wndW, wndH)

if !(wndId)
&& !(addr)
&&  (Abs(wndX - x) < 2)
&&  (Abs(wndY - y) < 2)
&&  (Abs(wndW - width) < 2)
&&  (Abs(wndH - height) < 2)
[AHK] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Any help converting this to expression syntax?

21 Jul 2017, 06:02

Code: Select all

wndId Window_getPosEx(wndId, wndX, wndY, wndW, wndH)
is not an assignment for wndId, but it might be auto-concatenated.
just me
Posts: 9451
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Any help converting this to expression syntax?

21 Jul 2017, 10:18

Well, I think the bug.n's code is somewhat buggy. Window_getPosEx() returns an address evaluating to True in every case. (Also, the returned address is somewhat useless because it's an address of a local var and the first TCHAR of its stringbuffer is set to NULL when the function returns.)

Neither

Code: Select all

Not wndId Window_getPosEx(wndId, wndX, wndY, wndW, wndH)
nor

Code: Select all

!(wndId) && !(addr)
will ever evaluate to True.

If you change Window_getPosEx() to return True/False depending on the result of the DllCalls, this might make sense:

Code: Select all

	if (!(wndId) || !(addr) ||  (Abs(wndX - x) < 2) ||  (Abs(wndY - y) < 2) &&  (Abs(wndW - width) < 2) &&  (Abs(wndH - height) < 2))
		return 0

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Anput, ArkuS and 114 guests