|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Visual Basic
Common Dialog Routines TaskDialog: Displaying the Vista Task Dialog from VB |
||
Posted: | Tuesday September 09, 2008 | |
Updated: | Monday December 26, 2011 | |
Applies to: | VB6 | |
Developed with: | VB6, Windows Vista | |
OS restrictions: | Windows Vista | |
Author: | VBnet - Randy Birch | |
Related: |
MessageBoxEx: Displaying an API-created Message Box |
Prerequisites |
Modified vb6.exe using the instructions at Manifests: Make the VB IDE use Windows Vista Styles. |
|
Compared to alert messages in Vista, VB's MsgBox and Windows generic MessageBox and MessageBoxEx APIs are pretty dull. This page shows how to show the new Vista TaskDialog, together with a few interesting undocumented flags you can use to customize the out-of-the-box appearance of the TaskDialog. Like a MsgBox or MessageBox, a basic TaskDialog has five key components:
But there are also a number of key differences between a TaskDialog and a standard API MessageBox:
TaskDialog is a fancy MessageBox, and since Vista users have expectations as to the look and feel of applications, it makes sense to use the latest GUI features whenever possible. If developing an app to support multiple operating systems, then you will need to be able to depreciate gracefully to MessageBox or even VB's MsgBox if the system is not Vista. I have posted a couple of ways to determine OS versions on the site; do a search for IsVista. TaskDialog has a big brother, one who weight lifts and is on serious steroids. TaskDialogIndirect is the brute that allows custom sizing, custom images, custom button captions, as well as other (option/check) buttons, a "don't show this again" button, and an expanding down arrow "more information" button. A series of TaskDialogIndirect demos is in development. |
BAS Module Code |
None. But see the Comments section below to use this demo in a compiled state. |
|
Form Code |
To a form containing just a command button (Command1), add the following code. The results are output to the debug window: |
|
Option Explicit '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved. ' Some pages may also contain other copyrights by the author. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Distribution: You can freely use this code in your own ' applications, but you may not reproduce ' or publish this code on any web site, ' online service, or distribute as source ' on any media without express permission. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' 'taskdialog icons defined under Vista. All text 'on white dialog background 'exclamation point in a yellow 'yield' triangle (same image as IDI_EXCLAMATION) Private Const TD_WARNING_ICON As Long = -1 'round red circle containg 'X' (same as IDI_HAND) Private Const TD_ERROR_ICON As Long = -2 'round blue circle containing 'i' (same image as IDI_ASTERISK) Private Const TD_INFORMATION_ICON As Long = -3 'Vista's security shield Private Const TD_SHIELD_ICON As Long = -4 'icons defined under Windows that can also be used. 'Text on white dialog background 'miniature picture of an application window Private Const IDI_APPLICATION = 32512& 'round blue circle containing '?' Private Const IDI_QUESTION = 32514& 'other undefined icon constants that present 'the icon and dialog text in a different format (my constants) 'same image as TD_SHIELD_ICON; main message text on gradient blue background Private Const TD_SHIELD_GRADIENT_ICON As Long = -5 'exclamation point in yellow Shield shape; main message text on gradient orange background Private Const TD_SHIELD_WARNING_ICON As Long = -6 'X contained within Shield shape; main message text on gradient red background Private Const TD_SHIELD_ERROR_ICON As Long = -7 'Shield shape containing green checkmark; main message text on gradient green background Private Const TD_SHIELD_OK_ICON As Long = -8 'same image as TD_SHIELD_ICON; main message text on medium gray background Private Const TD_SHIELD_GRAY_ICON As Long = -9 'no icon; text on white background Private Const TD_NO_ICON As Long = 0 'taskdialog common button flags Private Const TDCBF_OK_BUTTON As Long = &H1& 'return value 1 (IDOK) Private Const TDCBF_YES_BUTTON As Long = &H2& 'return value 6 (IDYES) Private Const TDCBF_NO_BUTTON As Long = &H4& 'return value 7 (IDNO) Private Const TDCBF_CANCEL_BUTTON As Long = &H8& 'return value 2 (IDCANCEL) Private Const TDCBF_RETRY_BUTTON As Long = &H10& 'return value 4 (IDRETRY) Private Const TDCBF_CLOSE_BUTTON As Long = &H20& 'return value 8 (IDCLOSE) Private Declare Function TaskDialog Lib "comctl32.dll" _ (ByVal hwndParent As Long, _ ByVal hInstance As Long, _ ByVal pszWindowTitle As Long, _ ByVal pszMainInstruction As Long, _ ByVal pszContent As Long, _ ByVal dwCommonButtons As Long, _ ByVal pszIcon As Long, _ pnButton As Long) As Long Private Sub Command1_Click() Dim sDlgTitle As String Dim sMainPrompt As String Dim sContent As String Dim dwButtons As Long Dim dwIcon As Long Dim pnButton As Long Dim success As Long sDlgTitle = "VBnet TaskDialog Demo" sMainPrompt = "The license key you entered for this program was invalid. Please try again." sContent = "To re-enter your license key select Retry." dwButtons = TDCBF_RETRY_BUTTON Or TDCBF_CANCEL_BUTTON dwIcon = MakeIntResource(TD_ERROR_ICON) success = TaskDialog(Me.hWnd, _ 0&, _ StrPtr(sDlgTitle), _ StrPtr(sMainPrompt), _ StrPtr(sContent), _ dwButtons, _ dwIcon, _ pnButton) Debug.Print "success = "; success Debug.Print "user action = "; pnButton End Sub Private Function MakeIntResource(ByVal dwVal As Long) As Long MakeIntResource = &HFFFF& And dwVal End Function |
Comments |
Remember that to use this dialog in a compiled application, you MUST:
|
|
|
|
|||||
|
|||||
|
|||||
Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved. |