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: 2043
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: 4580
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
Remaining with AHK 1.1.25.02 until v2 will become beta.
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

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.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 2043
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: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

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.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 2043
Joined: 19 Dec 2016, 01:58
Location: UK

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

03 Apr 2017, 14:01

I'm writing a script to convert/correct DllCall lines, and am creating a list of dll functions and parameters, e.g.

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



I was a little unsure on the RECT parameter for InvalidateRect, although I saw that user just me went with Ptr.

For example:
DwmIsCompositionEnabled function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/aa969518(v=vs.85).aspx

What is the correct parameter for DwmIsCompositionEnabled:
I see 'BOOL' so assume it's Int.
Perhaps it's a pointer to a BOOL, so I assume it's Ptr.
If I want to use the 'P'/'*' direct to variable approach, perhaps it's IntP.

How do I determine the 'non-P/*' parameter type, and how do I determine the 'P/*' parameter type.
Cheers.
Last edited by jeeswg on 03 Apr 2017, 14:51, edited 1 time in total.
Helgef
Posts: 2098
Joined: 17 Jul 2016, 01:02
Contact:

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

03 Apr 2017, 14:19

I do this,

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

h:=DllCall("Dwmapi.dll\DwmIsCompositionEnabled", "Int*", enabled) ; Return 0 on ok
msgbox, % h " " enabled

This, seems to work too,

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

VarSetCapacity(enabled,4,0)
h:=DllCall("Dwmapi.dll\DwmIsCompositionEnabled", "Ptr", &enabled) ; Return 0 on ok
msgbox, % h " " NumGet(enabled,0,"Int")


Cheers.
User avatar
jNizM
Posts: 2243
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

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

04 Apr 2017, 01:10

BOOL * -> A pointer to a value
like helgef wrote it can be both ways

"ptr" NumGet(..., "int") or
"int*"

same for e.g. _Out_ ULONG *pcbResult
it can be "uint*", cbResult
or "ptr", &cbResult NumGet(..., "uint")
[AHK] 1.1.26.01 x64 Unicode | [WIN] 10 Pro (Version 1703) x64
My GitHub Profile | Donations are appreciated if I could help you
User avatar
jeeswg
Posts: 2043
Joined: 19 Dec 2016, 01:58
Location: UK

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

04 Apr 2017, 06:15

Thank you both.

In the two '_Out_' parameter examples below, the first one makes more sense, but I believe both have the same parameter type:

Ptr and IntP.

I might have thought if you literally see 'BOOL' then that means you can definitely put 'Int', but it seems as though that is not the case. (I.e. that would mean that you have to be careful, you can't just look at the raw parameter type, e.g. BOOL, that is specified, and use that.)

Is _Out_ BOOL *pfEnabled actually incorrect, or nonstandard? There have been some errors in these definitions.

BOOL WINAPI IsWow64Process(
_In_ HANDLE hProcess,
_Out_ PBOOL Wow64Process
);

HRESULT WINAPI DwmIsCompositionEnabled(
_Out_ BOOL *pfEnabled
);

Anyhow, I intend to produce a list with parameters for around 100 dll functions, and then people will be able double-check them. Although if someone else is working on something similar already, it would be nice to compare results.
User avatar
jeeswg
Posts: 2043
Joined: 19 Dec 2016, 01:58
Location: UK

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

22 Apr 2017, 21:07

Some clipboard/hDrop functions:

JEE_ClipboardEnumFormats
JEE_ClipboardGetDropEffect
JEE_ClipboardGetPaths
JEE_ClipboardGetText
JEE_ClipboardSetPaths
JEE_ClipboardSetText
JEE_DropCreate
JEE_DropGetPaths

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

just me
Posts: 4580
Joined: 02 Oct 2013, 08:51
Location: Germany

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

23 Apr 2017, 02:15

Did explorer cut or copy?

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


I didn't call my version JUSTME_ClipboardGetDropEffect(). Why do you call yours JEE_ClipboardGetDropEffect()? I get the impression that you are collecting existing code from the forums and just add your JEE_ prefix.

Also, I still don't see any contents actually related to the topic "GUI COMMANDS: COMPLETE RETHINK" here.
Remaining with AHK 1.1.25.02 until v2 will become beta.
User avatar
jeeswg
Posts: 2043
Joined: 19 Dec 2016, 01:58
Location: UK

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

23 Apr 2017, 09:25

The GUI Rethink aims to replace the GuiXXX commands. If I'm to replace the entirety of the GuiXXX commands, I have to replace every single bit of functionality that they have. But, there are a lot of functions I feel AutoHotkey ought to have that I'm also writing, for example interacting with and getting/setting the text of external listviews and treeviews.

I didn't call my version JUSTME_ClipboardGetDropEffect(). Why do you call yours JEE_ClipboardGetDropEffect()?

Doesn't that question answer itself to an extent, a lot of the time, functions have a natural name, so it causes confusion, where different functions by different authors have exactly the same name. I've had enough problems with variations of the COM and Acc libraries for example.

Sometimes in LaTeX, for example, there are so many functions from so many libraries, that it's very hard to know what's your own function or variable, and what someone else's is, thus using a marker is useful. Plus, it becomes easier to find your own functions/variables in code that can become very complex. Similar logic applies to AutoHotkey, especially if the person is a beginner, unfamiliar with what's an AHK standard function, and what's a custom function. Having a prefix is also useful to avoid using #Include, and to aid text searching, and script correction. Frankly, if I didn't include a prefix, *I'd* forget which functions I'd written and which I hadn't.

I get the impression that you are collecting existing code from the forums and just add your JEE_ prefix.

I wish that were even possible. Good luck finding the other ones. JEE_Clipboard(Get/Set)Text for example, was particularly awkward, I used various bits of C++ code as a template.

Whenever I look for relevant code on the AHK forums, at best, it's often x32-only, and messy, with inconsistent syntax, capitalisation, and spelling mistakes, and written in an unnecessarily unclear or long-winded manner, with poor commenting, inconsistent indentation, and somewhat forgivably, mistakes relating to English being their second language. Plus sometimes there are bugs. You have to know what you're doing, you can never just copy and paste.

My JEE_ClipboardGetDropEffect was quite similar to yours, it is the only function I've written so far, that feels very close to someone else's, although that was coincidental, for a start, the name of the function does pretty much write itself. I might point out that the function only has *9* lines of code. I decided to throw in one line I wouldn't have included, the 'static' line, to make it look even more similar and see if anyone reacted to the function similarities, I'll explain why below. Btw it is my intention at a future date to add more 'local' and 'static' lines to all my functions.

Occasionally in forums I have hinted that I might only half-know or half-understand something, to see how people would respond. Unfortunately sometimes users took the bait, and it helped me understand to be cautious with those people. (I tend to give people the benefit of the doubt, and, like they do on the news, clarify a term, in case the poster or the wider audience doesn't fully understand it.) Your reaction is completely fair and legitimate however. So apologies for the little test with the 'static' line, which was not aimed at you in particular.

The 'understanding' test I alluded to above, is not so much a morality test, but an attitude test. If a user is too quick to dismiss things that other people say, or underestimate other people's abilities, or not be supportive of beginners or users generally, then they will be tiresome to deal with. You can try to be extra careful when conversing with such people, to avoid them wrecking the flow of a conversation with pointless and unwarranted insults, but ultimately it is better to avoid dealing with such people, wherever possible. It is unfortunate when people are like that, because on the whole you might like them.
User avatar
jeeswg
Posts: 2043
Joined: 19 Dec 2016, 01:58
Location: UK

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

16 Sep 2017, 11:15

Based on, but hardly easy to recreate as a stand-alone form from:
[Class] WinClip - direct clipboard manipulations - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/74670-class-winclip-direct-clipboard-manipulations/
format - How do I insert formatted text using AutoHotkey? - Stack Overflow
https://stackoverflow.com/questions/13222689/how-do-i-insert-formatted-text-using-autohotkey/13224970#13224970

Set clipboard to HTML and paste. E.g. test on Excel.

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



Set clipboard to RTF and paste. E.g. test on WordPad.

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

User avatar
jeeswg
Posts: 2043
Joined: 19 Dec 2016, 01:58
Location: UK

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

16 Sep 2017, 13:28

@just me: Yes, to produce my clipboard functions, all it took was a copy and paste job. E.g. I copied C++ code and then magically out it came as AHK.

I have a script written in, guess what language (it begins with 'a'), and when it's on it records the webpages I look at. So from 22nd April:

Spoiler


One key moment in my copy-and-paste journey, was when I realised that everything would work as long as I could obtain the size of an hMem, and it turned out there was a GlobalSize function.

So seeing this post re. GlobalSize, by nnnik was nice, because is signified the end of the long journey I'd been on. Or at least that part of it, there may have been more after.
Clipboard Class - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/93705-clipboard-class/

Btw I'm not sure if anybody else ever wrote functions to get/set clipboard text, or get paths, because AutoHotkey can already do this for you. Although I believe some reasons for my interest in this were situations where programs are ANSI only or where to emulate a program, you need to know if the clipboard has no text on it, cf. AutoHotkey has an unusual but useful quirk, that if there is no text on the clipboard, if will return a list of file paths if found.

Return to “Ask For Help”

Who is online

Users browsing this forum: Bill, PhilippeBruno and 62 guests