MsgBox2 - customizable msgbox - 2020/07/31 AHK v1

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

MsgBox2 - customizable msgbox - 2020/07/31 AHK v1

04 Feb 2020, 17:41

AHK v2 version/discussion has been moved to this thread.

Thanks to @robodesign for LOTS of collaboration, testing, and feedback. This is definitely a joint project.
Thanks to @just me for making TaskDialog which gave me some ideas in a few places I got stuck.

I probably won't be doing too much to update this script, but I am maintaining the AHK v2 version. Please see the following posts by other users who have contributed updated versions of this code:



User @robodesign has made another version of this library in this post.

User @warapic217 has made an updated version here.



This class replaces, enhances, and combines the Msgbox and InputBox commands. Now you have a quick and simple solution to add as many custom buttons as you want to a Msgbox. Or you can configure this to have input controls, including any combination of an Edit box, DropDownList, ComboBox, CheckBox, or ListBox. Each of these controls can be populated and have a value pre-selected. This class actually halts the current function or thread to wait for input from the user as expected by a MsgBox / InputBox command.

After the user interacts with or closes the dialog, the following properties are populated:

Code: Select all

.list             row number selected in ListBox
.listText         text of row number selected in Listbox
.dropList         row number selected in DropDownList
.dropListText     text of row number selected in DropDownList
.combo            row number selected in ComboBox
.comboText        text of row number selected in ComboBox
.check            value of Checkbox (1 or 0 / true or false)
.button           text of the button clicked
.ClassNN          ClassNN of the button clicked
msgbox2 demo.png
msgbox2 demo.png (8.51 KiB) Viewed 4812 times

===========================================================================
Changes:
===========================================================================

:arrow: Download on GitHub
Last edited by TheArkive on 25 Jul 2021, 06:23, edited 33 times in total.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function

04 Feb 2020, 18:19

Can I set modal by hwnd? If yes, then I'll make use of it.

This looks very promising.

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function

04 Feb 2020, 18:30

robodesign wrote:
04 Feb 2020, 18:19
Can I set modal by hwnd? If yes, then I'll make use of it.
You mean specify "modal:HWND" as the parent to disable? Yes.

You can specify "modal:" to use the hwnd of the GUI that launched the thread, or you can use "modal:HWND", and specify your own window as the parent.

Note that if other timers are running in the background, those are NOT stopped or paused when the modal dialog comes up.

EDIT: I made some extensive help docs. Please read them carefully so you can understand all the features. Of course, if you have questions please ask!

EDIT2: I'm actually working on colors now!
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function

04 Feb 2020, 18:38

Okay, great. I'll try it tomorrow morning. Thank you for your work!

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function

04 Feb 2020, 21:25

robodesign wrote:
04 Feb 2020, 18:38
Okay, great. I'll try it tomorrow morning. Thank you for your work!

Best regards, Marius.
As another sidenote, without a GUI, MsgBox2() will pause the currently running thread / function just like a regular MsgBox function from AHK, which isn't technically "modal".

I'm just trying to say, it might be best to not specify "modal:" if it isn't needed (for anyone who tries using this library).
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 12:56

Hello!

I have this call:

msgResult := MsgBox2("Are you sure you want to delete this image file ?`n`n" OutFileName "`n`n" OutDir "\", appTitle ": Confirmation", "icon:question,modal:" PVhwnd)

I get the error: Gui does not exist with given name. I feed a HWND of the Gui, not the Gui Label/Name. Can I use a hwnd? This is very important for me .

Owner/modal must be able to receive a hwnd.

The library is really good . I will probably use it if i can feed it hwnds.

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 13:13

robodesign wrote:
05 Feb 2020, 12:56
Hello!

I have this call:

msgResult := MsgBox2("Are you sure you want to delete this image file ?`n`n" OutFileName "`n`n" OutDir "\", appTitle ": Confirmation", "icon:question,modal:" PVhwnd)

I get the error: Gui does not exist with given name. I feed a HWND of the Gui, not the Gui Label/Name. Can I use a hwnd? This is very important for me .

Owner/modal must be able to receive a hwnd.

The library is really good . I will probably use it if i can feed it hwnds.

Best regards, Marius.
Can you replicate the error in a short script so I can troubleshoot? Your syntax looks ok, but I need to see the context of how it is used.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 13:17

I updated the example code in the OP. I made MainHwnd a Global var (shouldn't be required, must makes a demo easier), and I passed the hWnd to the options in Example #4. Still working fine for me ... Hope you can post your code so I can help...
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 17:07

I'll test this tomorrow. Thank you.

The window is created within another thread. That's why I need to use a hwnd. By coincidence, the hwnd I pass is a global variable.

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 17:49

robodesign wrote:
05 Feb 2020, 17:07
I'll test this tomorrow. Thank you.

The window is created within another thread. That's why I need to use a hwnd. By coincidence, the hwnd I pass is a global variable.

Best regards, Marius.
Oh, is it from another script entirely? Is the parent created by the same script that uses the MsgBox2() library?

Or are you trying to make the parent another window that comes from a different running script, or not even an AHK window?

The only reason I can think of that might explain why it's failing is, maybe, if you use Gui, MyGuiName:New. This would basically create the same window, but destroy the old one, then the hWnd would change, potentially causing this kind of problem.

Can you post your code so I can see how to possible make MsgBox2() work? Or i might need to update MsgBox2() to be more functional :P
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 19:45

There are two threads created in AHK-H. They communicate between them. The first one created the window and in the other one I create the message box. So, I want to get it lock the window from the first thread.

I hope my explanation was clear enough.

The threads act as separate scripts, but AHK-H provides auxiliary functions that help with communication.

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

05 Feb 2020, 20:10

robodesign wrote:
05 Feb 2020, 19:45
There are two threads created in AHK-H...
Ooooh, i see. I don't actually use AHK_H. I'm not sure what needs to be done to make my script compatible with AHK_H. I'm happy to try stuff, but I need a direction....

How would you use AHK_H Gui command to modify properties or visual look of a Gui window from one thread to another?
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

06 Feb 2020, 08:53

You don't have such functions. The only functions you have are to get /set variables from the main thread, or from the child thread. And... To stop /start /kill thread. Or to call a specific function from the given thread. Nothing else.

You have to identify the +disabled GUI associated windows styles and set them by yourself to a specific hwnd / window.

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

06 Feb 2020, 09:19

@robodesign I'm actually trying to setup AutoHotkey v2 and/or AutoHotkey_H v2 now ... trying to figure it out.
burque505
Posts: 1736
Joined: 22 Jan 2017, 19:37

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

19 Apr 2020, 09:45

@TheArkive, just ran across this, really nice work, thank you.
Regards,
burque505
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

20 Apr 2020, 01:47

@robodesign,

could you post some example code of using different threads? I'd like to take a crack at fixing this up to work.
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

20 Apr 2020, 08:37

Yes.

I'll do so. Today.

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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

20 Apr 2020, 09:34

@robodesign, thanks. I have AutoHotkey_H ... just not sure how to use it yet.

Edit: Are you using AhkThread, AhkExported, ExeThread, NewThread, or ThreadObj? I may be able to figure this out, i just need some context for how you use this code...
robodesign
Posts: 934
Joined: 30 Sep 2017, 03:59
Location: Romania
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

20 Apr 2020, 09:59

I use: interfaceThread := ahkthread("#Include *i Lib\module-interface.ahk")

This creates a new script thread. That script includes the ahk file found on the hdd. I do not like to have in the main ahk file the whole script of the other thread, hence i use include.

Let me know if you progress. Are you on IRC or Discord? We can talk there, if you have further questions.

To call function from newly created thread use:
initGUI := interfaceThread.ahkFunction("BuildGUI")
or [if you do not want to wait]
initGUI := interfaceThread.ahkPostFunction("BuildGUI")

To get vars:
varName:= interfaceThread.ahkgetvar.varName

To assign vars:
interfaceThread.ahkassign("varName", varValue)




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.
User avatar
TheArkive
Posts: 1027
Joined: 05 Aug 2016, 08:06
Location: The Construct
Contact:

Re: MsgBox2 - custom msgbox, usable as inline function, modal emulation, custom buttons, custom font

20 Apr 2020, 12:46

@robodesign
Ok thanks. I'll play around with this and try to find the error you experienced. Can I just create a simple GUI and run in another thread for testing? Should I use AHK_H v1 or v2?

Edit:. I'll look you up on discord or #ahk irc channel when I have questions 👍

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 100 guests