GUI COMMANDS: COMPLETE RETHINK

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
jeeswg
Posts: 6902
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

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 ;incorrect
DllCall("SendMessage", Ptr,hCtl, UInt,0xB0, UIntP,vPos1, UIntP,vPos2, Ptr) ;EM_GETSEL ;fixed
MsgBox, % vPos1 " " vPos2
return
Last edited by jeeswg on 17 Feb 2019, 17:10, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9423
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

DllCall("SendMessage", "Ptr", hCtl, "UInt", 0xB0, "UIntP", vPos1, "UIntP", vPos2) ; EM_GETSEL
User avatar
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
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

; 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] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jeeswg
Posts: 6902
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/librar ... s.85).aspx
EM_GETSEL message (Windows)
https://msdn.microsoft.com/en-us/librar ... s.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.
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
jNizM
Posts: 3183
Joined: 30 Sep 2013, 01:33
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] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jeeswg
Posts: 6902
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

"kernel32\VirtualQueryEx",Ptr,Ptr,Ptr,UPtr,UPtr
"psapi\GetMappedFileName",Ptr,Ptr,Ptr|Str,UInt,UInt
"kernel32\IsWow64Process",Ptr,Ptr|IntP,Int
"kernel32\OpenProcess",UInt,Int,UInt,Ptr
"kernel32\VirtualAllocEx",Ptr,Ptr,UPtr,UInt,UInt,Ptr
"kernel32\WriteProcessMemory",Ptr,Ptr,Ptr,UPtr,UPtr,Int
"kernel32\ReadProcessMemory",Ptr,Ptr,Ptr,UPtr,UPtr,Int
"kernel32\VirtualFreeEx",Ptr,Ptr,UPtr,UInt,Int
"kernel32\CloseHandle",Ptr,Int
"shell32\SHAddToRecentDocs",UInt,Ptr|Str,Ptr
"user32\InvalidateRect",Ptr,Ptr,Int,Int
"kernel32\AttachConsole",UInt,Int
"kernel32\FreeConsole",Int
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/librar ... s.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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
Helgef
Posts: 4709
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

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

Code: Select all

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: 3183
Joined: 30 Sep 2013, 01:33
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] v2.0.5 | [WIN] 11 Pro (Version 22H2) | [GitHub] Profile
User avatar
jeeswg
Posts: 6902
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.
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
jeeswg
Posts: 6902
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

;==================================================

JEE_ClipboardEnumFormats(vSep=",")
{
	DllCall("OpenClipboard", Ptr,0)
	vOutput := ""
	while vFormat := DllCall("EnumClipboardFormats", UInt,vFormat?vFormat:0)
		vOutput .= vFormat vSep
	DllCall("CloseClipboard")
	vOutput := SubStr(vOutput, 1, -StrLen(vSep))
	return vOutput
}

;==================================================

;e.g. vDropEffect := JEE_ClipboardGetDropEffect()
;e.g. vIsCopied := (vDropEffect & 1)
;e.g. vIsCut := (vDropEffect & 2) >> 1
;DROPEFFECT_LINK := 4, DROPEFFECT_MOVE := 2, DROPEFFECT_COPY := 1
;copied = 5, cut = 2, none = 0 (no files on clipboard = 0)

JEE_ClipboardGetDropEffect()
{
	static vPreferredDropEffect := DllCall("RegisterClipboardFormat", Str,"Preferred DropEffect")
	if !DllCall("IsClipboardFormatAvailable", UInt,vPreferredDropEffect)
		return 0
	if DllCall("OpenClipboard", Ptr,0)
	{
		hDropEffect := DllCall("GetClipboardData", UInt,vPreferredDropEffect, UPtr)
		pDropEffect := DllCall("GlobalLock", Ptr,hDropEffect, UPtr)
		vDropEffect := NumGet(pDropEffect+0, 0, "UChar")
		DllCall("GlobalUnlock", Ptr,hDropEffect)
		DllCall("CloseClipboard")
	}
	return vDropEffect
}

;==================================================

JEE_ClipboardGetPaths(vSep="`n")
{
	;CF_HDROP := 0xF
	if !DllCall("IsClipboardFormatAvailable", UInt,0xF)
		return ""
	if !DllCall("OpenClipboard", Ptr,0)
		return ""
	if !hDrop := DllCall("GetClipboardData", UInt,0xF)
	{
		DllCall("CloseClipboard")
		return ""
	}

	;==============================
	;same as JEE_DropGetPaths:
	vOutput := ""
	vCount := DllCall("shell32\DragQueryFile" (A_IsUnicode?"W":"A"), Ptr,hDrop, UInt,-1, Ptr,0, UInt,0, UInt)
	Loop, % vCount
	{
		vSize := DllCall("shell32\DragQueryFile" (A_IsUnicode?"W":"A"), Ptr,hDrop, UInt,A_Index-1, Ptr,0, UInt,0, UInt) + 1
		VarSetCapacity(vPath, vSize*(A_IsUnicode?2:1), 0)
		DllCall("shell32\DragQueryFile" (A_IsUnicode?"W":"A"), Ptr,hDrop, UInt,A_Index-1, Str,vPath, UInt,vSize, UInt)
		vOutput .= vPath vSep
	}
	DllCall("shell32\DragFinish", "Ptr", hDrop)
	;==============================

	DllCall("CloseClipboard")
	return SubStr(vOutput, 1, -StrLen(vSep))
}

;==================================================

JEE_ClipboardGetText()
{
	;CF_LOCALE := 0x10 ;CF_UNICODETEXT := 0xD
	;CF_OEMTEXT := 0x7 ;CF_TEXT := 0x1
	if !DllCall("IsClipboardFormatAvailable", UInt,0xD)
		return ""
	if !DllCall("OpenClipboard", Ptr,0)
		return ""
	if !hBuf := DllCall("GetClipboardData", UInt,0xD)
	{
		DllCall("CloseClipboard")
		return ""
	}

	pBuf := DllCall("GlobalLock", Ptr,hBuf, Ptr)
	vSize := DllCall("GlobalSize", Ptr,hBuf)
	VarSetCapacity(vOutput, vSize, 0)
	DllCall("msvcrt\memcpy", Ptr,&vOutput, Ptr,pBuf, UPtr,vSize)
	VarSetCapacity(vOutput, -1)

	DllCall("GlobalUnlock", Ptr,hBuf)
	DllCall("CloseClipboard")
	return vOutput
}

;==================================================

JEE_ClipboardSetPaths(vPaths, vDropEffect=0x5)
{
	;DROPEFFECT_LINK := 4, DROPEFFECT_MOVE := 2, DROPEFFECT_COPY := 1
	(SubStr(vDropEffect, 1, 2) = "cu") ? (vDropEffect := 0x2) : "" ;cut
	(SubStr(vDropEffect, 1, 2) = "co") ? (vDropEffect := 0x5) : "" ;copy

	;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
	hDrop := DllCall("GlobalAlloc", UInt,0x42, UPtr,20+(StrLen(vPaths)+2)*2, Ptr)
	pDrop := DllCall("GlobalLock", Ptr,hDrop, Ptr)

	;DROPFILES struct
	NumPut(20, pDrop+0, 0, "UInt")
	NumPut(1, pDrop+16, 0, "UInt")

	;e.g. CF_HDROP with 3 paths: 'path1 null path2 null path3 null null'
	vOffset := 20
	Loop, Parse, vPaths, `n, `r
		if !(A_LoopField = "")
			vOffset += StrPut(A_LoopField, pDrop+vOffset, StrLen(A_LoopField)+1, "UTF-16")*2

	hWnd := A_ScriptHwnd ? A_ScriptHwnd : WinExist("ahk_pid " DllCall("GetCurrentProcessId", UInt))

	;CF_HDROP := 0xF
	DllCall("GlobalUnlock", Ptr,hDrop)
	DllCall("OpenClipboard", Ptr,hWnd)
	DllCall("EmptyClipboard")
	DllCall("SetClipboardData", UInt,0xF, Ptr,hDrop)

	if (vDropEffect = 0)
	{
		DllCall("CloseClipboard")
		return
	}

	hDropEffect := DllCall("GlobalAlloc", UInt,0x42, UPtr,4, Ptr)
	pDropEffect := DllCall("GlobalLock", Ptr,hDropEffect)
	DllCall("RtlFillMemory", Ptr,pDropEffect, UPtr,1, UChar,vDropEffect)
	DllCall("GlobalUnlock", Ptr,hDropEffect)

	vFormat := DllCall("RegisterClipboardFormat", Str,"Preferred DropEffect")
	DllCall("SetClipboardData", UInt,vFormat, Ptr,hDropEffect)
	DllCall("CloseClipboard")
	return
}

;==================================================

JEE_ClipboardSetText(vText)
{
	;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
	hBuf := DllCall("GlobalAlloc", UInt,0x42, UPtr,(StrLen(vText)+2)*2, Ptr)
	pBuf := DllCall("GlobalLock", Ptr,hBuf, Ptr)
	StrPut(vText, pBuf, StrLen(vText)+1, "UTF-16")

	;CF_LOCALE := 0x10 ;CF_UNICODETEXT := 0xD
	;CF_OEMTEXT := 0x7 ;CF_TEXT := 0x1
	hWnd := A_ScriptHwnd ? A_ScriptHwnd : WinExist("ahk_pid " DllCall("GetCurrentProcessId", UInt))
	DllCall("GlobalUnlock", Ptr,hBuf)
	DllCall("OpenClipboard", Ptr,hWnd)
	DllCall("EmptyClipboard")
	DllCall("SetClipboardData", UInt,0xD, Ptr,hBuf)
	DllCall("CloseClipboard")
	return
}

;==================================================

;e.g. hDrop := JEE_DropCreate(vPaths)

;where vPaths is an LF/CRLF-separated list
;JEE_HDropSetPaths
JEE_DropCreate(vPaths, vPosX=0, vPosY=0)
{
	;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
	vWidth := A_IsUnicode?2:1
	hDrop := DllCall("GlobalAlloc", UInt,0x42, UPtr,20+(StrLen(vPaths)+2)*vWidth, Ptr)
	pDrop := DllCall("GlobalLock", Ptr,hDrop)

	;DROPFILES struct
	NumPut(20, pDrop+0, 0, "UInt")
	NumPut(vPosX, pDrop+4, 0, "UInt")
	NumPut(vPosY, pDrop+8, 0, "UInt")
	NumPut(A_IsUnicode?1:0, pDrop+16, 0, "UInt")

	;e.g. CF_HDROP with 3 paths: 'path1 null path2 null path3 null null'
	vOffset := 20
	Loop, Parse, vPaths, `n, `r
		if !(A_LoopField = "")
		{
			DllCall("RtlMoveMemory", UInt,pDrop+vOffset, Str,A_LoopField, UInt,StrLen(A_LoopField)*vWidth)
			vOffset += (StrLen(A_LoopField)+1)*vWidth
		}

	DllCall("GlobalUnlock", Ptr,hDrop)
	return hDrop
}

;==================================================

JEE_DropGetPaths(hDrop, vSep="`n")
{
	vOutput := ""
	vCount := DllCall("shell32\DragQueryFile" (A_IsUnicode?"W":"A"), Ptr,hDrop, UInt,-1, Ptr,0, UInt,0, UInt)
	Loop, % vCount
	{
		vSize := DllCall("shell32\DragQueryFile" (A_IsUnicode?"W":"A"), Ptr,hDrop, UInt,A_Index-1, Ptr,0, UInt,0, UInt) + 1
		VarSetCapacity(vPath, vSize*(A_IsUnicode?2:1), 0)
		DllCall("shell32\DragQueryFile" (A_IsUnicode?"W":"A"), Ptr,hDrop, UInt,A_Index-1, Str,vPath, UInt,vSize, UInt)
		vOutput .= vPath vSep
	}
	DllCall("shell32\DragFinish", "Ptr", hDrop)
	return SubStr(vOutput, 1, -StrLen(vSep))
}

;==================================================
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
just me
Posts: 9423
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

ClipboardGetDropEffect() {
   Static PreferredDropEffect := DllCall("RegisterClipboardFormat", "Str" , "Preferred DropEffect")
   DropEffect := 0
   If DllCall("IsClipboardFormatAvailable", "UInt", PreferredDropEffect) {
      If DllCall("OpenClipboard", "Ptr", 0) {
         hDropEffect := DllCall("GetClipboardData", "UInt", PreferredDropEffect, "UPtr")
         pDropEffect := DllCall("GlobalLock", "Ptr", hDropEffect, "UPtr")
         DropEffect := NumGet(pDropEffect + 0, 0, "UChar")
         DllCall("GlobalUnlock", "Ptr", hDropEffect)
         DllCall("CloseClipboard")
      }
   }
   Return DropEffect
}
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.
User avatar
jeeswg
Posts: 6902
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.
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
jeeswg
Posts: 6902
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/7467 ... pulations/
format - How do I insert formatted text using AutoHotkey? - Stack Overflow
https://stackoverflow.com/questions/132 ... 0#13224970

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

Code: Select all

q::
FormatTime, vDate
vHtml := "<b>" vDate "</b>"
JEE_ClipboardSetHtml(vHtml, "e")
;vRtf := "{\rtf{\b " vDate "}}"
;JEE_ClipboardSetRtf(vRtf)
SendInput, ^v
return

;==================================================

;vOpt: e (empty clipboard before setting contents)
JEE_ClipboardSetHtml(vHtml, vOpt:="", vSourceUrl:="")
{
	vFormat := DllCall("user32\RegisterClipboardFormat", Str,"HTML Format", UInt)
	vEnc := "UTF-8"
	vSizeHtml := StrPut(vHtml, vEnc) - 1 ;subtract null
	vSizeSource := 2 + 10 + StrPut(vSourceUrl, vEnc) - 1 ;subtract null
	vStartHTML := Format("{:010}", 105 + vSizeSource)
	vEndHTML := Format("{:010}", vStartHTML + vSizeHtml + 76)
	vStartFragment := Format("{:010}", vStartHTML + 38)
	vEndFragment := Format("{:010}", vStartFragment + vSizeHtml)

	vData1 := "Version:0.9"
	. "`r`n" "StartHTML:" vStartHTML
	. "`r`n" "EndHTML:" vEndHTML
	. "`r`n" "StartFragment:" vStartFragment
	. "`r`n" "EndFragment:" vEndFragment
	. "`r`n" "SourceURL:" vSourceUrl
	. "`r`n" "<html>"
	. "`r`n" "<body>"
	. "`r`n" "<!--StartFragment-->"
	. "`r`n" vHtml
	. "`r`n" "<!--EndFragment-->"
	. "`r`n" "</body>"
	. "`r`n" "</html>"

	vSize := StrPut(vData1, vEnc)
	VarSetCapacity(vData2, vSize, 0)
	StrPut(vData1, &vData2, vSize, vEnc)

	;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
	hBuf := DllCall("kernel32\GlobalAlloc", UInt,0x42, UPtr,vSize, Ptr)
	pBuf := DllCall("kernel32\GlobalLock", Ptr,hBuf, Ptr)
	;DllCall("kernel32\RtlMoveMemory", Ptr,pBuf, Ptr,&vData2, UPtr,vSize)
	DllCall("msvcrt\memcpy", Ptr,pBuf, Ptr,&vData2, UPtr,vSize, "Cdecl Int")

	hWnd := A_ScriptHwnd ? A_ScriptHwnd : WinExist("ahk_pid " DllCall("kernel32\GetCurrentProcessId", UInt))
	DllCall("kernel32\GlobalUnlock", Ptr,hBuf)
	DllCall("user32\OpenClipboard", Ptr,hWnd)
	if InStr(vOpt, "e")
		DllCall("user32\EmptyClipboard")
	DllCall("user32\SetClipboardData", UInt,vFormat, Ptr,hBuf, Ptr)
	DllCall("user32\CloseClipboard")
}
Set clipboard to RTF and paste. E.g. test on WordPad.

Code: Select all

q::
FormatTime, vDate
vRtf := "{\rtf{\b " vDate "}}"
JEE_ClipboardSetRtf(vRtf, "e")
;vHtml := "<b>" vDate "</b>"
;JEE_ClipboardSetHtml(vHtml)
SendInput, ^v
return

;==================================================

;vOpt: e (empty clipboard before setting contents)
JEE_ClipboardSetRtf(vRtf, vOpt:="")
{
	vFormat := DllCall("user32\RegisterClipboardFormat", Str,"Rich Text Format", UInt)
	vSize := StrPut(vRtf, "CP0")
	VarSetCapacity(vData, vSize, 0)
	StrPut(vRtf, &vData, vSize, "CP0")

	;GMEM_ZEROINIT := 0x40, GMEM_MOVEABLE := 0x2
	hBuf := DllCall("kernel32\GlobalAlloc", UInt,0x42, UPtr,vSize, Ptr)
	pBuf := DllCall("kernel32\GlobalLock", Ptr,hBuf, Ptr)
	;DllCall("kernel32\RtlMoveMemory", Ptr,pBuf, Ptr,&vData, UPtr,vSize)
	DllCall("msvcrt\memcpy", Ptr,pBuf, Ptr,&vData, UPtr,vSize, "Cdecl Int")

	hWnd := A_ScriptHwnd ? A_ScriptHwnd : WinExist("ahk_pid " DllCall("kernel32\GetCurrentProcessId", UInt))
	DllCall("kernel32\GlobalUnlock", Ptr,hBuf)
	DllCall("user32\OpenClipboard", Ptr,hWnd)
	if InStr(vOpt, "e")
		DllCall("user32\EmptyClipboard")
	DllCall("user32\SetClipboardData", UInt,vFormat, Ptr,hBuf, Ptr)
	DllCall("user32\CloseClipboard")
}
[EDIT:] Edited the functions to add the clipboard function to the clipboard, but to not empty the clipboard, unless specified.

[EDIT:] A link to functions for removing clipboard formats and storing the clipboard contents to a clp file.
clipboard: remove individual clipboard formats + save to clp file - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=39522
Last edited by jeeswg on 06 Nov 2017, 13:39, edited 2 times in total.
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
jeeswg
Posts: 6902
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/9370 ... ard-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.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: GUI COMMANDS: COMPLETE RETHINK

24 Dec 2017, 19:42

Jeeswg, I'm curious as to where you are at with this. Will the end result be a new GUI builder or designer?
User avatar
jeeswg
Posts: 6902
Joined: 19 Dec 2016, 01:58
Location: UK

Re: GUI COMMANDS: COMPLETE RETHINK

24 Dec 2017, 21:15

- The official end of the project will be when I create my Edit control-based Notepad clone. Although it's quite likely that I'll then create a Notepad clone with a Scintilla control. And possibly other GUI projects.

- Three things that I recently dealt with:
- Getting Scintilla controls to work in AHK x64.
Scintilla controls: SciLexer.dll x64/x32 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=41663
- Creating Common File Dialogs and Common Item Dialogs with an extra ComboBox. The work is mostly due to qwerty12, although I have had a few victories on this front. I have a working script for this, with all the bells and whistles, but I want to improve it before submitting.
FileSelectFile, add controls to the Open/Save As dialog - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=29934
- My library for getting/setting text in controls. This GUI project requires recreating all of the functionality of the AHK GUI commands, and this is the hardest bit, getting/setting text. The functionality actually goes beyond what many of the current commands can do.
GUIs via DllCall: get/set internal/external control text - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=40514

- I've basically got all the tools I need now to finish the Notepad clone, and it should be relatively simple, it's just that it's been ages since I worked on it, as I'd worked on all of these other issues.
- The GUIs via DllCall project is basically finished, from my perspective, but then, if I want to package something for other people, it'll be a slog of trying to perfect a suite of functions, including crucially, how I present a function that creates controls, and setting sensible defaults. Also, I never really planned to write functions for handling messages, and I don't know if this can or should be done. Although I might provide some examples.

- Some other links:
GUIs via DllCall: MsgBox - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=30688
GUIs via DllCall: control zoo - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=32106
GUIs via DllCall: list windows/child windows (controls) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=36405

- The GUI handling in AHK v2 isn't too bad. If support was added for specifying WNDCLASSEX details like class name and no icon, it might be good enough for most purposes, and so this project wouldn't be necessary. That said, this project is a good vehicle for people who want to learn how the Winapi works, for use with other programming languages.

- My more interesting GUI projects at the moment, I'm working on cloning/improving, using AHK v2, the AutoHotkey MsgBox (i.e. MessageBox Winapi function)/InputBox/ToolTip/SplashImage commands, and the Find dialog. Cloning the Progress command. Creating a function that puts coloured borders around a rectangle, which I call 'Borders'. I suppose I should look at the TrayTip command also, but I have no interest in this, and possibly nothing to improve, it might be left untouched. Anyhow, I don't use TrayTip.
- Some ideas. Key would be to add support for choosing your own font. For InputBox, I would allow the use of an array for the prompt/default text parameters, that way you could have a simple template for multiple input fields. The improved Find dialog supports whole word matching and RegEx. SplashImage would support animated gifs by using an Internet Explorer control, and possibly some additional image formats. There were other details (features) as well. Crucially though, if a template is written in AHK, then people can add in their much wanted MsgBox/InputBox improvements.
- Progress/SplashImage have been removed from AHK v2. Let's say I wanted to create these via AHK v2's GUI functions, I can't choose the class name (AutoHotkey2 cf. AutoHotkeyGUI), and so already, I couldn't just use my old Progress/SplashImage scripts without making changes. AFAIK there were other problems in trying to exactly recreate the functionality, perhaps relating to threads, or persistence. I remember suggestions that there would be no problems, so, if I recreate the functions, we can find out what the true situation is. Anyway, I like the functions for tests relating to images, or for showing big tooltips, or text using special fonts.
Last edited by jeeswg on 26 Dec 2017, 05:58, edited 1 time in total.
homepage | tutorials | wish list | fun threads | donate
WARNING: copy your posts/messages before hitting Submit as you may lose them due to CAPTCHA
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: GUI COMMANDS: COMPLETE RETHINK

26 Dec 2017, 04:52

Good to know. Thanks.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GUI COMMANDS: COMPLETE RETHINK

09 Dec 2018, 12:28

You speak of already 100 functions you created... but where's the link to them?

Sorry if I overlooked something .

Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
SOTE
Posts: 1426
Joined: 15 Jun 2015, 06:21

Re: GUI COMMANDS: COMPLETE RETHINK

13 Dec 2018, 20:39

robodesign wrote:
09 Dec 2018, 12:28
You speak of already 100 functions you created... but where's the link to them?

Sorry if I overlooked something .

Best regards, Marius.
I'm with you, where I think jeeswg's GUI project is very interesting. However, I'm already very impressed with how easy it is to build GUI applications in AutoHotkey. It's the easiest of any language I've seen so far. Unfortunately, AutoHotkey nor it's GUIs are cross-platform or cross-compiling. I will talk about some possibilities concerning that in a different post.

But GUI's via DllCall can possibly lead the way to making a more organized package, greater knowledge of the Windows OS, along with additional abilities.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: GUI COMMANDS: COMPLETE RETHINK

14 Dec 2018, 09:35

Yes, I agree. That's why I asked, I want to learn more...

His zoo control example includes some of his own functions, but... It's kinda convoluted, it's not a clear example.

Best regards, Marius
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: marypoppins_1, mikeyww, OrangeCat, RussF and 125 guests