slightly-improved dialogs

Discuss the future of the AutoHotkey language
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

slightly-improved dialogs

06 Mar 2018, 19:00

- The idea here is to create slightly-improved versions of the AutoHotkey dialogs (MsgBox/InputBox/ToolTip) that support a custom font and various simple commonly-asked for features, and to also recreate Progress and SplashImage. The Borders function simply puts coloured borders around a square/rectangle (e.g. a window/control/GUI element).

1 MsgBox [big font]
2 InputBox (+ InputBox multi) [big font/multiple fields]
3 Progress [i.e. SplashText] [no additional features]
4 SplashImage [option to use IE control]
5 ToolTip [big font]
6 Borders [show coloured borders around a rectangle]

see also:
7 Find dialog [custom Find dialog with whole word/RegEx options]
Find dialog with whole word and RegEx support - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=50262

- I'm implementing the functions here in AutoHotkey v2, although I had intended ultimately to create them using my own custom GUI functions, because that way you can specify the class name (needed for all of them), no icon (e.g. MsgBox, Find dialog), and you don't cause #Persistent, and they can be used in AutoHotkey v1/v2.
- I mentioned some of my plans here:
GUI COMMANDS: COMPLETE RETHINK - Page 2 - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=25893&p=190491#p190491

- Some points on functionality.
- I have various queries relating to the GUI functionality, in the script's to-do list.
- One idea for #Persistent could be something like object reference counts, the user can choose to increment the 'GUI count' by 1, and decrement it when finished, as a way to ensure the script remains open at least while the GUI is displaying. If the 'GUI count' ever reaches 0, the script can then close at the next appropriate point.
- Some properties that could be useful: HwndParent (or ParentHwnd), .B/.R for bottom/right, being able to set the control colours as built-in (the one 'complex' feature I would recommend adding in), specific menu item IDs.
- Having used AutoHotkey v2 GUIs for the first time in this project (apart from in my control zoo), I repeatedly noticed the benefits of this idea:
For convenience, it should be possible to pass a Gui object to a WinTitle parameter instead of "ahk_id " Gui.Hwnd.
I would suggest that it work in general for all WinXXX functions, if you pass any object which has a key 'hWnd'.

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

oWin := {hWnd:hWnd}
vWinTitle := WinGetTitle(oWin)
vWinTitle := WinGetTitle("ahk_id " oWin.hWnd)
vWinTitle := WinGetTitle("ahk_id " hWnd)

- I'm looking for any similar/related scripts for comparison. [EDIT: See the list in a post lower down.] Although the focus here is strictly very minor oft-asked-for features.
Last edited by jeeswg on 08 Jun 2018, 05:46, edited 2 times in total.
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

Re: slightly-improved dialogs

06 Mar 2018, 19:47

First attempt which currently only covers InputBox.

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


[EDIT:] Added to 'NOTES' re. 'Close' event.
Last edited by jeeswg on 07 Mar 2018, 05:56, edited 1 time in total.
User avatar
nnnik
Posts: 2899
Joined: 30 Sep 2013, 01:01
Location: Germany

Re: slightly-improved dialogs

07 Mar 2018, 02:42

I think this would be better off in the Scripts forum.
Recommends AHK Studio
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

Re: slightly-improved dialogs

27 Mar 2018, 23:49

- @nnnik: Part of the focus of this thread, is re. recreating Progress and SplashImage in AHK v2. It had been stated that they should be reborn as custom functions instead of built-in functions.
- (I don't mind if 0% of my code is used, I just hope to try and identify some of the problems, and some of the solutions, and hopefully speed up the eventual release of the finalised code.)
- The aim is more to discuss some of the programming issues through examples, rather than to make pretty GUIs. Maybe at some future point, the thread can be moved, but, as I see it, right now, it wouldn't be appropriate.
- The project is almost complete, just that I want to double-check the Progress/SplashImage functions, and convert the Find dialog to AHK v2.

- I found some key GUI links, that I thought I might share:

[MSDN: MsgBox]
[details for AHK's MsgBox command]
MessageBox function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx
[MsgBox plus icon, mentioned in: 'MsgBox with custom icon (from resource)']
MessageBoxIndirect function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms645511(v=vs.85).aspx
[MsgBox sounds][this overlaps with AHK's SoundPlay function]
MessageBeep function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms680356(v=vs.85).aspx

[MSDN: AdjustWindowRectEx]
[from the source code for Progress/SplashImage]
[calculate window size based on client size and window style/ex. style (and vice versa)]
AdjustWindowRectEx function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms632667(v=vs.85).aspx
[apparently AdjustWindowRectEx can do both client size to/from window size based on window style/ex. style]
What is the inverse of AdjustWindowRect and AdjustWindowRectEx? – The Old New Thing
https://blogs.msdn.microsoft.com/oldnewthing/20131017-00/?p=2903
[AdjustWindowRectEx example]
measure Menu/ToolTip/GUI dimensions before showing - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=28291

[MSDN: work area]
[from the source code for Progress/SplashImage]
[SPI_GETWORKAREA: get screen size minus (horizontal/vertical) taskbar size]
SystemParametersInfo function (Windows)
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx
This functionality is built-in in AutoHotkey as SysGet-MonitorWorkArea, see here:
AutoHotkey via DllCall: AutoHotkey functions as custom functions - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=7&t=37871

[Alguimist]
MagicBox - Message Box Generator - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=20983

[berban]
InputBox() - easy & powerful InputBox implementation - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/70407-inputbox-easy-powerful-inputbox-implementation/

[Coco]
Class: InputBoxEx - Customizable InputBox - Scripts and Functions - AutoHotkey Community
https://autohotkey.com/board/topic/88377-class-inputboxex-customizable-inputbox/
Help with InputBoxEx - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=1352
EntryForm() - easy, custom InputBox, data entry forms - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=4559

[Flipeador]
AHKv2: Diálogos para seleccionar Icono, Fuente, Color y Más! [23/07/17] - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=42&t=10802

[jeeswg]
ToolTips: set border colour (custom font/colour ToolTips) (borders around windows/controls) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=36959
no-frills SplashImage - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=45295
no-frills Progress/SplashText/ToolTip alternative - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=45341
slightly-improved dialogs - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=37&t=45220
Find dialog with whole word and RegEx support - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=50262

[just me]
ToolTipEx - custom fonts and colors in ToolTips - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=4350

[lexikos]
ToolTipFont / ToolTipColor - options for the ToolTip command - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=4777
MsgBox with custom icon (from resource) - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=6&t=29374

- I'd be interested as to whether the system-wide text for the MsgBox buttons could be changed/retrieved. And also text like 'New Folder' and 'Copy of'. I had done some searching in the past but had not found anything.
- In the AutoHotkey source code, Progress and SplashImage are both defined within one function called Splash() within script2.cpp.
Last edited by jeeswg on 08 Jun 2018, 05:49, edited 5 times in total.
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

Re: slightly-improved dialogs

26 May 2018, 22:57

- What would be better re. recreating SplashImage: using a Static control (closer to what a user would do) or drawing the image each time the window is activated (closer to the AHK v1 source code)?
- There are examples of both here:
no-frills SplashImage - AutoHotkey Community
https://autohotkey.com/boards/viewtopic.php?f=5&t=45295
- [EDIT:] For the custom SplashImage function below I've used a Static control.
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

Re: slightly-improved dialogs

08 Jun 2018, 06:44

- I now have a full set of examples for slightly-improved dialogs.

1 MsgBox [big font]
2 InputBox (+ InputBox multi) [big font/multiple fields]
- The custom functions demonstrate the functionality that I wanted.
- (In theory I would have recreated MsgBox's Windows 7 appearance exactly, down to the pixels, but the numbers appeared wildly unpredictable.)

3 Progress [i.e. SplashText] [no additional features]
4 SplashImage [option to use IE control]
- The custom functions are virtually identical appearance-wise to the originals, although I would be happy for them to be even closer. The same applies to InputBox.

5 ToolTip [big font]
6 Borders [show coloured borders around a rectangle]
- I'm quite happy with these functions.

- Some general points:
- One issue that emerged was the need for consistency re. '0xABCDEF' v. 'ABCDEF'. The former allows hex or dec to be used, so no conversion is needed, and it allows the use of double quotes to be avoided.
- I experienced a major problem relating to Critical and Thread-Priority. If I set Critical or Thread-Priority, and then called the InputBox function, I was unable to close the InputBox. I don't know if there is a solution to this problem. There is an example of it amongst the examples below.

- Re. Progress/SplashImage:
- I judge Progress(/SplashText) and SplashImage to be sufficiently useful, non-trivial to implement, and long (thus inconvenient for inclusion at the bottom of a script or in the documentation), to be worth keeping as built-in functions. Having them as somehow 'semi-official' but not built-in, suggests that they are official, but that a random barrier has been put in place to burden newbies and spawn support threads in the forums. If they were to be 'kept' in some form, ideally they'd be as easy to use as MsgBox or InputBox.
- I find them to be versatile general purpose workhorse functions, useful for writing and sharing quick scripts, displaying large/custom fonts, and notifying me of events. If they were semi-deprecated, I'd end up with multiple incompatible snippets of code, and spending a disproportionate amount of time writing small GUI scripts for personal use and for sharing. If I felt that I wanted to keep using the P and S functions in some form, but that they weren't standard for sharing on the forum, I could also waste time converting code every time I wanted to share something. If anyone has any instincts for keeping them, they could consider any changes/additions to further increase their attractiveness.

Examples.

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


Functions.

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

Helgef
Posts: 2990
Joined: 17 Jul 2016, 01:02
Contact:

Re: slightly-improved dialogs

08 Jun 2018, 14:01

Big work :o :thumbup: .
If I set Critical or Thread-Priority, and then called the InputBox function, I was unable to close the InputBox.

Critical wrote:Prevents the current thread from being interrupted by other threads, or enables it to be interrupted.
Gui events spawns new thread.
I don't know if there is a solution to this problem.
Turn off critical. For thread priority it seems you cannot restore it afterwards, but it should be rare. Alternatively you can create your dialogs in new threads, then you do not need to consider the settings in the calling thread. Or just do nothing, no one wants a msgbox/inputbox/... in a critical thread anyways. And it is not a problem, it is a feature of threads ;).

Your functions depend on a number of global variables not supplied with the functions, that is annoying.

Quick tips, gui and gui control event callbacks gets passed the object for which the event occured, eg, Gui_Close(Gui). And gui control objects can get their parent gui via the gui property, eg, myGui := myCtrl.gui. In gui event threads, the last found window is set to the gui for which the event occured.

Cheers, and thanks for sharing.
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

Re: slightly-improved dialogs

09 Jun 2018, 07:45

- Some other general points:
- If in AHK v1/v2, you could overwrite a built-in function, but have the ability to still refer to that built-in function, that would be incredibly useful.
- Sometimes MsgBox/InputBox get hidden under other windows. I believe that this happens more in Windows 7 than it did in Windows XP.
- All of these dialog functions would benefit from a timeout option e.g. Progress/SplashImage/ToolTip. E.g. display a Progress ('SplashText') window for 3 seconds. I.e. sometimes a function gets interrupted, and the dialog remains on the screen permanently. And some options prevent a SetTimer event, to hide the dialog, from taking place.
- (Creating custom GUI functions in both AHK v1 and v2, that you can use in your libraries without automatically causing persistence. The built-in dialog functions don't cause persistence.)

Big work :o :thumbup: .
- Cool compliment, cheers.
no one wants a msgbox/inputbox/... in a critical thread anyways.
- The main script that I use more than any other, every day, which displays an InputBox with multiple choices, requires Critical/Thread-Priority be set. I may have done this to protect variables being overwritten by other subroutines.
- Anyhow, I might rewrite it to avoid the use of Critical/Thread-Priority, however, I think it's important to point out that built-in GUI functions appear to have an advantage here over custom functions.
Your functions depend on a number of global variables not supplied with the functions, that is annoying.
- Yeah, I've fixed this in the new version below. I did think of it at one point but forgot, I'd been really focused on the Progress/SplashImage functions which took 3 months to finally finish, but which didn't need special variables.
- I've also added in support for & (accelerator keys) in MsgBoxNew. Something that I noticed was missing just now when running the test script.
User avatar
jeeswg
Posts: 4485
Joined: 19 Dec 2016, 01:58
Location: UK

Re: slightly-improved dialogs

09 Jun 2018, 08:06

Update.

Examples.

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


Functions.

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


Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: kczx3 and 2 guests