Introduction
This is a reboot of the Dlg library which was released by majkinetor in 2007. It has been been rewritten to include new features, new dialogs, and to support x64.
Dlg2 Library
Key features:
Common dialogs. Create and interact with many of the Microsoft Windows common dialogs. Use of the common dialogs gives the user a consistent experience across different programs.
Help Button. The Help button is supported for many of the common dialogs. Yes, you will have to write a custom handler function to respond to the help request but everything else is included.
What's New in Version 1.0?
There are few bug fixes, some new features and improvements, and a few new functions. In addition, the general library documentation has been moved to the _Dlg2.Doc.ahk file. Natural Docs v2.3 is used to generate HTML documentation from this file and from the function documentation. See the Release Notes for more information.
The Code
The pertinent files are as follows:
Project: Dlg2.zip
This project archive includes the Dlg2 library, example scripts, and project documentation.
Documentation: Starting with v1.0, the project documentation is included in the project archive file (above).
Compatibility
Starting with v0.3, this project is designed to work on on recent versions of AutoHotkey v1.1+: ANSI, Unicode, and Unicode 64-bit. It is not compatible with AutoHotkey v2.0+ (yet).
Issues/Considerations
Like most, I only have one machine to test this software on (currently Windows 10 Pro). If you experience any problems with this library on your version of AutoHotkey v1.1+ and/or your version of Windows, please let me know. I will try to correct the problem.
Release Notes
v1.0 Requirements:
This version of the library is designed to run on a recent versions of AutoHotkey v1.1+: ANSI, Unicode, and Unicode 64-bit. Future versions (if any, except bug fixes) will require AutoHotkey v2.0+.
Possible script breakers:
• Dlg_ChooseFont. The function now returns an AutoHotkey object (tests as TRUE) if successful, otherwise FALSE. The previous version returned TRUE or FALSE. If a script specifically tests if TRUE (1) is returned (Ex: If Dlg_ChooseFont(...)=True) then it must be modified to instead check if the return value tests as TRUE (Ex: if Dlg_ChooseFont(...) ). For most developers, no modifications are necessary.
Bug fixes, updates, enhancements, etc.:
• Dlg_ChooseColor. There are several updates/enhancements. 1) The p_Flags parameter has been modified so that flag "names" can be used in (Ex: "AnyColor") and can contain multiple values (Ex: "AnyColor|ShowHelp"). 2) The r_Color parameter has been modified so that a supported color name can be specified on input. Ex: "Blue". The standard 6-digit hexadecimal RGB color value is returned on output. See the function documentation for more information.
• Dlg_ChooseFont. There are several updates/enhancements. 1) The p_Flags parameter has been modified so that flag names can be used (Ex: "FixedPitchOnly") and can contain multiple values (Ex: "TTOnly|FixedPitchOnly|NoVertFonts"). See the function documentation for more information. 2) Added support for the CF_INACTIVEFONTS flag. If this flag is included, hidden fonts will be included in the list of fonts (Windows 7+). 3) Additional information including a LOGFONT structure is returned when a font is selected. See the function documentation for more information.
• Dlg_GetSysColor. The function was rewritten to match the same function in the Fnt library. There are no script breaking changes but new options, formats, and parameters have been added. See the function documentation for more information.
• Dlg_FindReplaceText. Updated the p_Flags parameter to also allow space delimiters when flag names are used. This change makes this function act the same as other functions in this library that allow the use of string flag values. Ex: "Down MatchCase".
• Dlg_MessageBox. There are several updates/enhancements. 1) The p_Type parameter has been modified so that type "names" can be used (Ex: "OKCancel") and can contain multiple values (Ex: "YesNo|IconExclamation|Help"). 2) Added custom MB_RETURNSTRING type value. If this custom flag is added to the p_Type parameter, a string value is returned (Ex: "Try Again") instead of the standard Message Box return value (Ex: 11). See the function documentation for more information.
• Dlg_OpenSaveFile. There are several updates/enhancements. 1) The OFN_ENABLEHOOK flag is sometimes added to trigger a workaround for an old Microsoft bug if the OFN_ALLOWMULTISELECT flag has been added but not if the OFN_HIDEREADONLY flag has also been added. This bug appears in all versions of Windows since Windows XP. 2) Updated the r_Flags parameter to also allow "|" (pipe) delimiters when flag names are used. This change makes this function act the same as other functions in this library that allow the use of string flag values. Ex: NoChangeDir|HideReadOnly". 3) A trailing "\" character is automatically added to the specified path in the p_Root parameter if needed. This emulates how the AutoHotkey FileSelectFile command works. 4) If the p_Filter parameter contains a filter string, an "All Files (*.*)" filter is automatically added to the end of the filter string if it does not already contains a "(*.*)" pattern. This emulates how the AutoHotkey FileSelectFile command works.
• Documentation. The general library documentation has been moved from the top of the Dlg2.ahk library file to a new _Dlg2.doc.ahk file. Natural Docs v2.3 is used to generate HTML documentation from this file and from the function documentation. This HTML document is in a new format that is different from the previous version of this project.
• Examples. Updated examples.
New functions:
• Dlg_ConvertColor. This function performs several color conversions and formats the return value. This function was added to improve consistency and add functionality for the functions in this library but it is also available for general use. See the function documentation for more information.
• Dlg_GetWindowTextColor. Get the window text color (usually Black) for the current theme.
New add-on files:
• Dlg2_Constants.ahk. This add-on file includes common Microsoft constants that may or may not be used in the Dlg2 library. Although this file is in an AutoHotkey format, it is for documentation purposes only. It should never be included as-is.
v0.3 (Preview) Requirements:
This and future versions of this library are designed to run on all recent versions of AutoHotkey v1.1+: ANSI, Unicode, and Unicode 64-bit.
Possible script breakers:
• Dlg_GetScriptDebugWindow retired. If needed, use the A_ScripthWnd system variable instead.
New Functions:
• Dlg_GetSysColor [Internal function]. Retrieves system colors.
Bug fixes, Changes, and Enhancements:
• Dlg_ChooseFont There are several bug fixes. 1) Fixed to correctly return font weights other than normal (400) or bold (700). 2) For the p_Effects=True option, if no color option is specified on input, bug fixed so that the actual default text color is preselected instead of assuming Black. On output, "Default" is set as the color on the color option (Ex: "cDefault") if the default text color is selected. This change keeps subsequent "gui Font" commands from setting a custom color, or if a custom color was previously set, to reset the text color to the system default text color. 3) Fixed so that the SizeMin option value cannot be greater than the SizeMax value (r_Options parameter). Debug message dumped if this occurs but the function will not fail.
• Dlg_OnHelpMsg. Bug fix. Function was not sending the handle to the dialog to the help handler when the Help button was pressed on the Open and Save dialog. This is a Microsoft inconsistency that occurs on Vista+. Fixed by sending the handle to the active window if the handle to the dialog is not provided by the FINDMSGSTRING message.
• Dlg_FindReplaceText. Fixed bug (never happened IRL) when the user entered the maximum allowable number of find/replace characters causing AutoHotkey to crash.
• Dlg_Convert2Hex [Internal function]. Function retired. Not needed with AutoHotkey v1.1+.
• Updated structures documentation.
v0.2 (Preview)
• Bug fix: Dlg_OpenSaveFile fixed for x64.
• Update for Dlg_ChooseFont: For the r_Options parameter, color "names" can also be used on input (Ex: cBlue) instead of only a 6-digit hex RGB color value. However, a 6-digit hex RGB color value is always set on output. Ex: c0000FF
v0.1 (Preview)
• First release.
Last edited by jballi on 12 Nov 2023, 16:15, edited 6 times in total.
I think that AHK 1.0 support isn't needed for scripts posted in this forum. majkinators's original script will run on AHK 1.0 forever. On the other hand, support of AHK 1.0 is preventing you from using the advanced features of AHK 1.1 and makes things unnecessary complex.
just me wrote:I think that AHK 1.0 support isn't needed for scripts posted in this forum. majkinators's original script will run on AHK 1.0 forever. On the other hand, support of AHK 1.0 is preventing you from using the advanced features of AHK 1.1 and makes things unnecessary complex.
Interesting observations but I couldn't disagree more.
This is an AutoHotkey forum, not a AutoHotkey v1.1+ forum. Yes, we want to encourage new users to use AutoHotkey v1.1+ but excluding AutoHotkey Basic users would be excluding a majority (yes, I said majority) of all AutoHotkey users.
Yes, there are a few AutoHotkey v1.1+ features that this library could have used to simplify a few areas but this library makes simple Windows API calls. Using advanced AHK v1.1+ features (classes, objects, etc.) would unnecessarily complicate this library, not the reverse. Some of the complexity of the library comes from supporting both 32-bit and 64-bit structure mapping. This complexity doesn't go away with AutoHotkey v1.1+.
I use AutoHotkey v1.1+ for a few projects but I, like many, still primarily use AutoHotkey Basic. Why? Because AutoHotkey Basic is wicked fast and it ain't broke. I will eventually become an AutoHotkey v1.1+ exclusive user (I've been saying this for a few years now) but for now, I use both. This library was written for all AutoHotkey users, not for the minority that use AutoHotkey v1.1+. As users convert to AutoHotkey v1.1+, as I hope they will, this library will still work (I hope).
If you read through the documentation, you'll see that the Dlg2 iteration of the library ends support for AutoHotkey Basic. Future iterations will require COM. Yes, COM is somewhat supported in AutoHotkey Basic via the COM library but the built-in support for COM in AutoHotkey v1.1+ makes this a no-brainer.
I don't have a 64-bit machine so I have not been able to do a full range of testing. Curiosity question: Has anyone running the x64 version of AutoHotkey had a chance to give this a try and if so, could you let me know what happened - good and bad. Thanks.
Win8.1/64bit - tried a quick test of both Example - Find and Replace.ahk and Example - General.ahk and it seems to work correctly, not extensively tested but clicked a few options for each test.
Guest wrote:Win8.1/64bit - tried a quick test of both Example - Find and Replace.ahk and Example - General.ahk and it seems to work correctly, not extensively tested but clicked a few options for each test.
Good to know. Thank you for taking the time to give it a try/see.
jballi wrote: This is an AutoHotkey forum, not a AutoHotkey v1.1+ forum.
You are absolutly correct !!!!1!!
The domain was created to continue support for autohotkey users not autohotkey version x.xx. I am comletely against this domain forcing version choice. That is a mistake made elsewhere. This domain is about freedom of choice. We endorse the newest software. And while it has many programmerr centric niceties, enhancement that also benifet new script writers. The use of these enhancements is also a choice. A choice I strongly intend to defend.
We are troubled on every side‚ yet not distressed; we are perplexed‚
but not in despair; Persecuted‚ but not forsaken; cast down‚ but not destroyed;
Telegram is the best way to reach me https://t.me/ttnnkkrr
If you have forum suggestions please submit a Check Out WebWriter
jballi wrote: This is an AutoHotkey forum, not a AutoHotkey v1.1+ forum.
You are absolutly correct !!!!1!!
The domain was created to continue support for autohotkey users not autohotkey version x.xx. I am comletely against this domain forcing version choice. That is a mistake made elsewhere. This domain is about freedom of choice. We endorse the newest software. And while it has many programmerr centric niceties, enhancement that also benifet new script writers. The use of these enhancements is also a choice. A choice I strongly intend to defend.
v0.3
Minor release to fix a few minor bugs that have been on the books for a while. See the Release Notes section in the first post for the details.
This version of the library requires AutoHotkey v1.1+. The previous version of the library (v0.2) is still available. It will run on any version of AutoHotkey, including AutoHotkey Basic. Note that the bugs fixed in v0.3 have not been applied to the v0.2 version of the library but all of the bugs are minor and they do not affect ordinary use.
jballi wrote:v0.3
Minor release to fix a few minor bugs that have been on the books for a while. See the Release Notes section in the first post for the details.
This version of the library requires AutoHotkey v1.1+. The previous version of the library (v0.2) is still available. It will run on any version of AutoHotkey, including AutoHotkey Basic. Note that the bugs fixed in v0.3 have not been applied to the v0.2 version of the library but all of the bugs are minor and they do not affect ordinary use.
guest3456 wrote:may want to do an if (A_AhkVersion < 1.1) check
There is really no need for this type of release. v0.2 will run on all versions of AutoHotkey, including AutoHotkey Basic. v0.3 includes commands not supported by AutoHotkey Basic and so the script won't even run if using AutoHotkey Basic. If the script won't run, then it can't check the version of AutoHotkey. Thanks for your feedback.
The library seems to be working just fine in Windows 10 , which is really good .
However , i have a slight annoyance: When I calll the Open/Save dialog with p_Type := "O" and r_Flags set to "AllowMultiSelect FileMustExist NoChangeDir HideReadOnly"... I get a non-resizable open file dialog and it is the old style. It is just «allowmultiselect» that causes this. I do not mind a lot it is the old kind of dialog, but can I have it resizable?
Thank you.
EDIT: I identified the problem: OFN_ENABLEHOOK causes it to «recede» to the old kind of open/save file dialog. Is it important ? Can I just comment it ?
The Dlg_OFNHookCallback function is called if the OFN_ENABLEHOOK flag is included. This function was written to work around a bug in Windows XP and it probably occurs in other OS versions. The bug: The wrong value for the "Open As Read-Only" checkbox is sometimes returned if multiple files are selected. The workaround used by this function to read directly from the "Open As Read-Only" checkbox object at the time the user presses the "Open" or "Save" button.
In your example you use the HideReadOnly option which will hide the "Open As Read-Only" checkbox. So yes, in this example you can comment out the code that adds the OFN_ENABLEHOOK flag because there is no "Open As Read-Only" check box to worry about. And no, I haven't tested it. If you always plan to use the HideReadOnly option then we're done. However, if you don't use the HideReadOnly option in the future for any reason, then we're back to why the OFN_ENABLEHOOK flag was added in the first place.
Yes, it helps. By reading the code, I was able to figure out myself that you read the «read-only» checkbox using the hook, but of course ... I was not aware why you did it this way. Your explanations cleared it. And yes, I will always use HIDEREADONLY flag.
v1.0
Although this release comes with a major release number, i.e. v1.0, and there are hundreds of changes, this is a minor release. Most of the changes are to improve usability. See the Release Notes section of the first post for the details.
This version of the project only runs on a recent version of AutoHotkey v1.1+. AutoHotkey v2.0+ is not supported. With the exception of bug fixes, this will be the last release that uses AutoHotkey v1.1+. Future versions of this project (if any) will require AutoHotkey v2.0+.