GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify)

Get help with using AutoHotkey and its commands and hotkeys
User avatar
jeeswg
Posts: 605
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify)

20 Mar 2017, 12:17

I've now fixed the NumGet issue. Glad you told me. It's only a 3-letter change to the documentation, and it's lacking the customary version number update reference, so I probably would never have noticed. Changing the default parameter for NumGet, that's quite a controversial change. Btw talking about changes, someone just asked me when AHK v2 is coming out, do you know?

Ironically, I was thinking I might replace that 3-liner you quoted, with a one-line DllCall to SendMessage, making NumGet irrelevant. But would the performance be better or worse? [EDIT: see below]

The two small Edit control functions, I'd recently shared on a post, I thought I'd add them here because they are the one bit of important Edit control functionality missing from the built-in ControlXXX commands. Plus it turns out they have subtle advantages over other similar attempts, attempts that I was unaware of. Anyhow, check out JEE_EditGetRangeAnchorActive which I'll be adding above soon. You won't find anything similar to that.

As for existing Edit control functions?
[link is broken]
GitHub - ahkscript/awesome-AutoHotkey: A curated list of awesome AutoHotkey libraries, library distributions, scripts, tools and resources.
https://github.com/ahkscript/awesome-AutoHotkey
[also has the NumGet issue]
Autohotkey-Scripts/Edit.ahk at master · dufferzafar/Autohotkey-Scripts · GitHub
https://github.com/dufferzafar/Autohotkey-Scripts/blob/master/lib/Edit.ahk

Btw do you have a recommended modern control for making spreadsheets, other than a listview? Cf. Edit v. Scintilla. Although code for a listview would be interesting.

==================================================

[EDIT:]

Code: [Select all] [Download] GeSHi © Codebox Plus

q:: ;Edit control - get start/end points of text selection
ControlGet, hCtl, Hwnd, , Edit1, A
DllCall("SendMessage", Ptr,hCtl, UInt,0xB0, UPtrP,vPos1, PtrP,vPos2) ;EM_GETSEL
MsgBox % vPos1 " " vPos2
Return
just me
Posts: 3960
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify)

21 Mar 2017, 09:05

jeeswg wrote:Ironically, I was thinking I might replace that 3-liner you quoted, with a one-line DllCall to SendMessage, making NumGet irrelevant. But would the performance be better or worse?
I spent some time with testing in the past. In all of my tests the DllCall performed at least as fast as SendMessage.

The only risk seems to be:
SendMessage uses the API function SendMessageTimeout(). By default, it will return after 5 (?) seconds if the recipient doesn't respond. DllCall will block your script in this case. But it seems to be safe if used to send messages to your own script.

Also, I'd prefer:

Code: [Select all] [Download] GeSHi © Codebox Plus

DllCall("SendMessage", "Ptr", hCtl, "UInt", 0xB0, "UIntP", vPos1, "UIntP", vPos2) ; EM_GETSEL
Except as noted otherwise all of my code is tested on Win 10 Pro (x64) using the current AHK version.
User avatar
jNizM
Posts: 1982
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify)

21 Mar 2017, 09:39

This might be useful too:

Select everything in an edit control

Code: [Select all] [Download] GeSHi © Codebox Plus

; https://msdn.microsoft.com/en-us/library/bb761661(v=vs.85).aspx  -  EM_SETSEL message
DllCall("user32\SendMessage", "ptr", hEdit, "uint", 0xB1, "uint", 0, "uint", -1)


AutoHotkey use SendMessageTimeout (with 2 sec timeout) internally for ControlGet
CONTROLGET_CMD_LINE (GitHub)
[AHK] 1.1.25.01 x64 Unicode
[WIN] 10 Pro (Version 1607 | Build 14393.693) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 605
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify)

21 Mar 2017, 09:41

Classic information re. SendMessage, thanks.

Yes, this is something I meant to ask about on my dll calls topic:
key dll issues: calls and structs - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=26406

"UPtrP", vPos1, "PtrP", vPos2 (what I have currently)
"UIntP", vPos1, "UIntP", vPos2 (what you're proposing, and something I'd considered)

Both worked on both AHK 32 and AHK 64 when I tested.

WPARAM=UPtr and LPARAM=Ptr, however, the variables should both be a UInt.

SendMessage function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms644950(v=vs.85).aspx
EM_GETSEL message (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/bb761598(v=vs.85).aspx

I would have thought logically, that EM_GETSEL knows (expects) that the variables will be a UInt, so the important thing would be that SendMessage, can handle the parameters sent to it, hence I thought UPtrP and PtrP were required, but I have no additional knowledge to help confirm/contradict this.

DllCall
https://autohotkey.com/docs/commands/DllCall.htm
Append an asterisk (with optional preceding space) to any of the above types to cause the address of the argument to be passed rather than the value itself (the called function must be designed to accept it).

...

The most common example is LPDWORD, which is a pointer to a DWORD. Since a DWORD is an unsigned 32-bit integer, use "UInt*" or "UintP" to represent LPDWORD. An asterisk should not be used for string types such as LPTSTR, pointers to structures such as LPRECT, or arrays; for these, "Str" or "Ptr" should be used, depending on whether you pass a variable or its address.


[EDIT:]
From reading you might think that: 'UIntP' can be thought of as 'Ptr (to a UInt)', however, if that were so, how to distinguish between 'Ptr (to a UInt)' and 'UPtr (to a UInt)'.

Assuming these are both correct:
DllCall("SendMessage", "Ptr", hCtl, "UInt", 0xB0, "UPtr", &vPos1, "Ptr", &vPos2) ; EM_GETSEL
DllCall("SendMessage", "Ptr", hCtl, "UInt", 0xB0, "UIntP", vPos1, "UIntP", vPos2) ; EM_GETSEL

In the 2nd there is nothing relating to the 'UPtr'/'Ptr' discrepancy.

(Btw, WPARAM=UPtr, LPARAM=Ptr, DWORD=UInt, but bringing in the 'P'/'*', e.g. 'UIntP', is more subtle than this.)
Last edited by jeeswg on 21 Mar 2017, 12:02, edited 6 times in total.
User avatar
jNizM
Posts: 1982
Joined: 30 Sep 2013, 01:33
GitHub: jNizM

Re: GUI COMMANDS: COMPLETE RETHINK (latest: get/set system fonts, ComboBox choose string notify)

21 Mar 2017, 09:44

msdn wrote:EM_GETSEL message

wParam
-> A pointer to a DWORD value that receives the starting position of the selection. This parameter can be NULL.
lParam
-> A pointer to a DWORD value that receives the position of the first unselected character after the end of the selection. This parameter can be NULL.


A pointer to a DWORD -> UintP / UInt*
This can be usefull for you (Windows Data Types for AHK)



just me wrote:The Edit messages have been used and even wrapped many times in the forums. Why should we need additional functions with a JEE_ prefix`?

Yeah.. you should stop using JEE_blabla.. You better give your function just a legible name what the function do. (But like so many times you will ignore this ^^)
[AHK] 1.1.25.01 x64 Unicode
[WIN] 10 Pro (Version 1607 | Build 14393.693) x64
My GitHub Profile | Donations are appreciated if I could help you

Return to “Ask For Help”

Who is online

Users browsing this forum: 4GForce, Quadzilla, Yahoo [Bot] and 39 guests