Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

[VB6] TaskDialogIndirect Simple Implementation

$
0
0
So I really liked the implementations of TaskDialog that I've seen, and wanted to take it a bit further. TaskDialogIndirect offers a far greater number of options:



This is the first version; a basic implementation of the standard features.

What IS Supported
-Custom Buttons (either CommandLink style or regular style)
-Radio Buttons
-All fields the text fields available
-Verify checkbox
-Hyperlinks (these are launched with ShellExecute)
-Custom icons: see notes at bottom of post

What Is NOT Supported
All of these are in the works for the full implementation.
-Support for ProgressBar
-Autoclose/Timer feedback
-Feedback for user actions in the dialog
-Changing text icons while displayed


The sample project attached calls the dialog shown in the picture above.

The main function is ShowTaskDialogEx:
Code:

Public Function ShowTaskDialogEx(hWnd As Long, _
                                hInstance As Long, _
                                dwFlags As TASKDIALOG_FLAGS, _
                                dwButtons As TDBUTTONS, _
                                sTitle As String, _
                                pszIconMain As TDICONS, _
                                sMainInstr As String, _
                                sContent As String, _
                                cButtons As Long, _
                                uBtns() As TASKDIALOG_BUTTON, _
                                nDefBtn As Long, _
                                cRadButtons As Long, _
                                uRadioBtns() As TASKDIALOG_BUTTON, _
                                nDefRadioBtn As Long, _
                                sVerifyText As String, _
                                sExpandedInfo As String, _
                                sExpandedControlText As String, _
                                sCollapsedControlText As String, _
                                hIconFooter As TDICONS, _
                                sFooter As String, _
                                cxWidth As Long, _
                                out_radio As Long, _
                                out_verify As Long) As TDBUTTONS

hWnd: Parent hWnd; can just be 0& usually.
hInstance: If/when it's required is unclear; so best to just pass App.hInstance to it
dwFlags: See MSDN. All flags can be used, but some would require additional code.
dwButtons: If you're using the standard buttons, set them here using Or to combine multiple buttons. Standard buttons cannot be used by themselves with the CommandLink style.
sTitle: The title of the dialog.
pszIconMain: Specify a value from TDICONS, or an hIcon (see notes)
sMainInstr: Main instruction text
sContent: Text appearing below the main instruction
cButtons: If you're using custom buttons, the number of them, or zero if not used.
uBtns(): The array of custom buttons. Redim(0) and don't set any members if not used, but the empty structure still needs to be passed.
nDefBtn: The button selected by default. Set to the buttons ID, or 0 if unused.
cRadButtons: The number of radio buttons, or 0 if none.
uRadioBtns(): The array of radio buttons. Redim(0) and don't set any members if not used, but the empty structure still needs to be passed.
nDefRadioBtn: The default radio button selected, by ID. 0 if unused.
sVerifyText: The text of the checkbox. If blank, the checkbox is not displayed. Unchecked by default; to make it checked by default use the TDF_VERIFICATION_FLAG_CHECKED flag.
sExpandedInfo: Extra info displayed when the expand button is click. Appears below Content by default; can be made to appear below footer with the TDF_EXPAND_FOOTER_AREA flag, and can be shown by default with the TDF_EXPANDED_BY_DEFAULT flag.
sExpandedControlText: The text for the expand button in its expanded state.
sCollapsedControlText: The text for the expand button in its collapsed state.
hIconFooter: Specify a value from TDICONS, or an hIcon (see notes)
sFooter: The footer text.
cxWidth: Specify a custom width. Set to 0& to have the ideal width determined automatically.

out_radio: Must be passed ByRef; this variable is filled with the ID of the radio button selected (or zero if they're not used).
out_verify: Must be passed ByRef; this variable is 0 if the verification box was unchecked, and 1 if it was checked.

Return value: The ID of the button selected, or 0 if the dialog was cancelled. This will either be a TDICONS value, or the user-supplied ID of the custom button.


Notes:

No subclassing required!

If you don't want to use the radio buttons, the empty structure still needs to be there. Change Redim uRBN(2) to (0), and change cRadButtons to 0.

For custom icons, you must set the TDF_USE_HICON_MAIN flag (and/or TDF_USE_HICON_FOOTER to use one in the footer), then supply an hIcon. Any icon source can be turned into an hIcon, just search for examples. I personally use a method adapted from clsMenuImage. You add the icon to the app's resource file as a custom resource in the VB Resource Editor (NOT as an icon), and then use the technique outlined here. This isn't included in the sample project; it's left to the user to supply the method of getting an hIcon.

As noted above, if you're using TDF_USE_COMMAND_LINKS then you must supply custom buttons. The dialog does not appear at all and the function returns all zeros if you set that flag and don't supply custom buttons. You can, however, use both, by specifying both dwButtons and a uBTN array; but you can't supply custom buttons AND command links.

When using command links, new lines are separated by vbLf alone, instead of vbCrLf. The latter results in the font not being smaller after the first line.

Requirements
TaskDialogIndirect is only supported on Vista and higher.

A CommonControls Manifest is required, both for the compiled project and for VB6.exe to run the code from the IDE, for 6.0 common controls. Like any other such project, it must be started from Sub Main() with an InitCommonControlsEx call.

----------------------------------------------------
In addition to feedback on this, I'd like ideas on how to approach the full implementation. I was thinking of switching over to a class module, that way I could fire events on notifications or the timer, and then update things with property lets. How to approach the progress bar in a way that's useful in general is a particular challenge.
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>