Click here to Skip to main content
12,759,698 members (33,069 online)
Click here to Skip to main content

Stats

163.6K views
2.5K downloads
116 bookmarked
Posted 28 Dec 2007

WPF Common TaskDialog for Vista and XP

, 30 Dec 2007 CPOL
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.
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 Infragistics
United States United States

I’m a passionate Platform Architect at Infragistics.


I’m a long-time WPF-Prism fanatic who enjoys writing developer tools and line of business applications.


My current front end passions are: XAML platforms (Xamarin.Forms, Xamarin, UWP, and WPF), Electron, ES2015 (ES6), Node.js, Aurelia, and AngularJS (Angular 1.5.x).


For the back end I use what is appropriate for the project: SQL Server and ASP.NET WebAPI, MongoDB, Express, Azure, Firebase, etc.


I am very pragmatic software engineer and strive to write simple, maintainable, and testable code. Simple code allows for solving complex problems in a maintainable way.


My Blog


My Github Repros


My YouTube Videos


Just a grain of sand on the worlds beaches.


You may also be interested in...

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