Click here to Skip to main content
11,632,715 members (86,392 online)
Click here to Skip to main content
Add your own
alternative version

WPF Common TaskDialog for Vista and XP

, 30 Dec 2007 CPOL 143.7K 2.3K 114
WPF custom TaskDialog that renders the same on Vista and XP. This custom dialog simplifies programming by providing a simple interface for developers that is not Operating System dependent. This solution does not use the Windows API for rendering.
customdialogsample-12-30-2007.zip
CustomDialogSample
CommonDialog
CustomDialogInformation.png
CustomDialogQuestion.png
CustomDialogShield.png
CustomDialogStop.png
CustomDialogWarning.png
My Project
Settings.settings
CustomDialogSample
My Project
Settings.settings
customdialogsample.zip
CustomDialogInformation.png
CustomDialogQuestion.png
CustomDialogShield.png
CustomDialogStop.png
CustomDialogWarning.png
Settings.settings
Settings.settings
CustomDialogSample.suo
Imports System
Imports System.Runtime.InteropServices
Imports System.Windows.Interop

Friend Class VistaAeroAPI

#Region " Private Declarations "

    Private Declare Sub DwmExtendFrameIntoClientArea Lib "dwmapi.dll" (ByVal hWnd As IntPtr, ByRef margins As MARGIN_STRUCT)
    Private Declare Function DwmIsCompositionEnabled Lib "dwmapi" (ByRef pfEnabled As Long) As Long

    Private Structure MARGIN_STRUCT

        Dim Left As Integer
        Dim Right As Integer
        Dim Top As Integer
        Dim Bottom As Integer

        Sub New(ByVal intLeft As Integer, ByVal intRight As Integer, ByVal intTop As Integer, ByVal intBottom As Integer)
            Left = intLeft
            Right = intRight
            Top = intTop
            Bottom = intBottom
        End Sub

        Sub New(ByVal t As Thickness)
            Left = CType(t.Left, Integer)
            Right = CType(t.Right, Integer)
            Top = CType(t.Top, Integer)
            Bottom = CType(t.Bottom, Integer)
        End Sub

    End Structure

#End Region

#Region " Methods "

    ''' <summary>
    ''' Makes any WPF window a full Aero Glass window
    ''' </summary>
    ''' <param name="window">Pass the window object.  (Me)</param>
    ''' <returns>Boolan</returns>
    ''' <remarks>Very cool</remarks>
    Friend Shared Function ExtendGlassFrame(ByVal window As Window) As Boolean
        Return ExtendGlassFrame(window, New Thickness(-1))
    End Function

    ''' <summary>
    ''' Makes any WPF window an Aero Glass window
    ''' </summary>
    ''' <param name="window">Pass the window object.  (Me)</param>
    ''' <param name="margin">Set margins to extend the glass into or to make the window all glass pass : New Thickness(-1)</param>
    ''' <returns>Boolan</returns>
    ''' <remarks>Very cool</remarks>
    Friend Shared Function ExtendGlassFrame(ByVal window As Window, ByVal margin As Thickness) As Boolean

        Dim lngReply As Long
        Dim lngResult As Long = DwmIsCompositionEnabled(lngReply)

        If lngResult <> 0 OrElse lngReply <> 1 Then
            Return False
        End If

        Dim hwnd As IntPtr = New WindowInteropHelper(window).Handle

        If hwnd = IntPtr.Zero Then
            Throw New InvalidOperationException("The Window must be shown before extending glass.")
        End If

        window.Background = Brushes.Transparent
        HwndSource.FromHwnd(hwnd).CompositionTarget.BackgroundColor = Colors.Transparent

        Dim margins As New MARGIN_STRUCT(margin)
        DwmExtendFrameIntoClientArea(hwnd, margins)

        Return True
    End Function

    Friend Shared Function IsDwmIsCompositionEnabled() As Boolean

        Dim lngReply As Long
        Dim lngResult As Long = DwmIsCompositionEnabled(lngReply)

        If lngResult <> 0 OrElse lngReply <> 1 Then
            Return False

        Else
            Return True
        End If

    End Function

#End Region

End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Karl Shifflett
Architect Gayle Manufacturing Company
United States United States
Karl loves .NET, WPF, WCF, ASP.NET, VB.NET and C#.

Awards:

  • December 2008 VB.NET Code Project Article Award
  • 2009 Code Project MVP
  • 2008 Code Project MVP
  • 2008 Microsoft MVP - Client App Dev
  • December 2007 VB.NET Code Project Article Award
  • Gold Medal Winner at IBM's 1998 PROIV Programming Contest in Las Vegas
Click here to check out my Blog

Click here to learn about Mole 2010 debugging tool for Visual Studio 2010

Click here to read about XAML Power Toys

Just a grain of sand on the worlds beaches.


You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150728.1 | Last Updated 30 Dec 2007
Article Copyright 2007 by Karl Shifflett
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid