In this post: Create your own Flip Task Bar with live thumbnails using Vista Desktop Window Manager DWM, I showed Fox code on creating your own Flip Task bar

 

Here is the VB.Net version that does the same thing…

File->New->Project->Visual Basic->Windows->Windows Forms Application

View->Code

 

Paste and run the code below.

 

 

See also Programming the Windows Vista DWM in C#

 

 

Imports System

Imports System.Text

Imports System.Runtime.InteropServices

Public Class Form1

      Dim ThumbWidth = 300

      Dim ThumbHeight = ThumbWidth * My.Computer.Screen.Bounds.Height / My.Computer.Screen.Bounds.Width

      Dim WithEvents cmdQuit As New Button

      Dim WithEvents cmdRefresh As New Button

      Dim WithEvents oSlider As New TrackBar

      Dim WithEvents oTimer As New Timer

 

      Delegate Function EnumWindowsCallback(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean

      Declare Ansi Function EnumChildWindows Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal MyCallBack As EnumWindowsCallback, ByVal lParam As Integer) As Boolean

 

      Declare Ansi Function GetWindowTextA Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal Str As StringBuilder, ByVal lSize As Integer) As Integer

      Declare Function GetWindowLongA Lib "user32.dll" (ByVal hwnd As IntPtr, ByVal num As Integer) As Integer

 

      Declare Function DwmRegisterThumbnail Lib "dwmapi.dll" (ByVal hWndDest As IntPtr, ByVal hWndSrc As IntPtr, ByRef dwThumb As IntPtr) As Integer

      Declare Function DwmUpdateThumbnailProperties Lib "dwmapi.dll" (ByVal hThumb As IntPtr, ByRef dwmp As DWM_PROPERTIES) As Integer

      Declare Function DwmUnregisterThumbnail Lib "dwmapi.dll" (ByVal hThumb As IntPtr) As Integer

 

      <StructLayout(LayoutKind.Sequential)> _

      Structure POINT

            Dim x As Integer

            Dim y As Integer

      End Structure

      <StructLayout(LayoutKind.Sequential)> _

      Structure Rect

            Sub New(ByVal _left As Integer, ByVal _top As Integer, ByVal _right As Integer, ByVal _bottom As Integer)

                  Left = _left

                  Right = _right

                  Top = _top

                  Bottom = _bottom

            End Sub

            Dim Left As Integer

            Dim Top As Integer

            Dim Right As Integer

            Dim Bottom As Integer

      End Structure

 

      <StructLayout(LayoutKind.Sequential)> _

      Structure DWM_PROPERTIES

            Dim dwFlags As Integer

            Dim rcDest As Rect

            Dim rcSrc As Rect

            Dim opacity As Byte

            Dim fVisible As Boolean

            Dim fSourceClientAreaOnly As Boolean

      End Structure

 

      Const DWM_TNP_VISIBLE = 8

      Const DWM_TNP_RECTDESTINATION = 1

      Const DWM_TNP_OPACITY = 4

 

      Const GWL_STYLE = -16

      Const WS_VISIBLE = &H10000000

      Const WS_BORDER = &H800000

      Class MyWindowItem

            Implements IDisposable

 

            Public hWnd As Integer

            Public Title As String

            Public Tid As IntPtr

            Public oPictureBox As MyPictureBox

            Public oLabel As Label

            Sub New(ByVal _hWnd As Integer, ByVal _title As String)

                  hWnd = _hWnd

                  Title = _title

            End Sub

 

            Public Sub Dispose1() Implements System.IDisposable.Dispose

                  If Tid <> 0 Then

                        DwmUnregisterThumbnail(Tid)

                        Tid = 0

                  End If

                  If oPictureBox IsNot Nothing Then

                        Form1.Controls.Remove(oPictureBox)

                  End If

                  If oLabel IsNot Nothing Then

                        Form1.Controls.Remove(oLabel)

                  End If

            End Sub

            Protected Overrides Sub finalize()

                  Dispose1()

                  MyBase.Finalize()

            End Sub

      End Class

      Dim WindowList As New SortedList

      Dim nNewWindowsFound As Integer

      Dim nTotalWindowsFound As Integer

 

      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

            Me.Width = My.Computer.Screen.Bounds.Width

            Me.Height = 180

            Me.Left = 0

            Me.Top = 0

            Me.MinimizeBox = False ' no minimize box, so it stays up if user minimizes all

            With cmdQuit

                  .Text = "&Quit"

            End With

            With cmdRefresh

                  .Text = "&Refresh"

                  .Left = 100

            End With

            With oSlider

                  .Left = 200

                  .Minimum = 1

                  .Maximum = 100

                  .Value = 50

                  .LargeChange = 10

                  .SmallChange = 2

                  .Height = 400

            End With

            Me.Controls.Add(cmdQuit)

            Me.Controls.Add(cmdRefresh)

            Me.Controls.Add(oSlider)

            oTimer.Interval = 2000

            oTimer.Enabled = True

      End Sub

 

      Sub GetHWnds(Optional ByVal fForce As Boolean = True)

            If Not fForce Then

                  nNewWindowsFound = 0

                  nTotalWindowsFound = 0

                  Dim nOrigWindowCount = WindowList.Count

                  EnumChildWindows(0, AddressOf MyCallBack, 0)

                  If 0 = nNewWindowsFound And nOrigWindowCount = nTotalWindowsFound Then  ' no new windows found or none deleted

                        Return

                  End If

            End If

 

            Dim indx As Integer

            Dim cWind As MyWindowItem

            For indx = 0 To WindowList.Count - 1

                  cWind = WindowList.GetByIndex(indx)

                  cWind.Dispose1()

            Next

            WindowList.Clear()

            nNewWindowsFound = 0

            EnumChildWindows(0, AddressOf MyCallBack, 0)

            Dim tid As Integer = 0

            Dim i = 0

            Dim x = 0

            Dim y = 20

            Dim nRatio = Me.oSlider.Value / Me.oSlider.Maximum

            For indx = 0 To WindowList.Count - 1

                  cWind = WindowList.GetByIndex(indx)

                  Dim oMyPictureBox As New MyPictureBox

                  Me.Controls.Add(oMyPictureBox)

                  With oMyPictureBox

                        .Left = x

                        .Top = y

                        .Height = ThumbHeight * nRatio

                        .Width = ThumbWidth * nRatio

                        .GetThumb(cWind)

                        .Visible = True

                  End With

                  cWind.oPictureBox = oMyPictureBox

                  Dim oLbl As New Label

                  With oLbl

                        .Left = x

                        .Top = y + ThumbHeight * nRatio

                        .Width = ThumbWidth * nRatio

                        .Height = 20

                        .Text = cWind.Title

                        .Visible = True

                  End With

                  cWind.oLabel = oLbl

                  Me.Controls.Add(oLbl)

                  x += Me.ThumbWidth * nRatio

                  If x + Me.ThumbWidth * nRatio > My.Computer.Screen.Bounds.Width Then

                        x = 0

                        y += Me.ThumbHeight * nRatio + 20

                  End If

            Next

      End Sub

 

      Function MyCallBack(ByVal hWnd As IntPtr, ByVal lParam As Integer) As Boolean

            If Me.Handle <> hWnd Then     '' if it's not our form

                  Dim nStyle = GetWindowLongA(hWnd, GWL_STYLE)

                  If (nStyle And (WS_VISIBLE + WS_BORDER)) = (WS_VISIBLE + WS_BORDER) Then

                        Dim Caption As New StringBuilder("", 500)

                        GetWindowTextA(hWnd, Caption, Caption.Capacity)

                        Dim c As String = Caption.ToString

                        nTotalWindowsFound += 1

                        If Not WindowList.ContainsKey(hWnd.ToString) Then

                              WindowList.Add(hWnd.ToString, New MyWindowItem(hWnd, Caption.ToString))

                              nNewWindowsFound += 1

                        End If

                  End If

            End If

            Return True

      End Function

 

      Private Sub cmdQuit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdQuit.Click

            Me.Close()

      End Sub

 

      Private Sub cmdRefresh_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdRefresh.Click

            GetHWnds()

      End Sub

 

      Private Sub Form1_Shown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shown

            GetHWnds()

      End Sub

 

      Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.SizeChanged

      End Sub

 

      Private Sub oSlider_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles oSlider.ValueChanged

            GetHWnds()

      End Sub

 

      Private Sub oTimer_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles oTimer.Tick

            GetHWnds(False)

      End Sub

      Class MyPictureBox

            Inherits PictureBox

            Const WS_MINIMIZE = &H20000000

            Const SW_RESTORE = &H9

            Dim oMyWindow As MyWindowItem

            Sub GetThumb(ByVal _oMyWindow As MyWindowItem)

                  oMyWindow = _oMyWindow

                  DwmRegisterThumbnail(Me.Parent.Handle, oMyWindow.hWnd, oMyWindow.Tid)

                  Dim dwmp As New DWM_PROPERTIES

                  dwmp.opacity = 255

                  dwmp.fVisible = True

                  dwmp.rcDest = New Rect(Left, Top, Right, Bottom)

                  '        dwmp.rcSrc = New Rect(0, 0, 200, 200)

                  dwmp.dwFlags = DWM_TNP_VISIBLE + DWM_TNP_RECTDESTINATION + DWM_TNP_OPACITY

                  DwmUpdateThumbnailProperties(oMyWindow.Tid, dwmp)

            End Sub

            <StructLayout(LayoutKind.Sequential)> _

            Structure WindowPlacement

                  Dim length As Integer

                  Dim flags As Integer

                  Dim showcmd As Integer

                  Dim ptMinPosition As POINT

                  Dim ptMaxPosition As POINT

                  Dim rcNormalPosition As Rect

            End Structure

            '        Declare Ansi Function GetWindowPlacement Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef wp As WindowPlacement) As Integer

            <DllImport("user32.dll", SetLastError:=True)> Shared Function GetWindowPlacement(ByVal hWnd As IntPtr, ByRef wp As WindowPlacement) As Integer

            End Function

 

            Declare Ansi Function SetWindowPlacement Lib "user32.dll" (ByVal hwnd As IntPtr, ByRef wp As WindowPlacement) As Boolean

            Declare Function SetForegroundWindow Lib "user32.dll" (ByVal hWnd As IntPtr) As Integer

 

            Sub MyClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click

                  Dim nStyle = GetWindowLongA(oMyWindow.hWnd, GWL_STYLE)

                  If (nStyle And WS_MINIMIZE) = (WS_MINIMIZE) Then

                        Dim pPlacement As New WindowPlacement

                        pPlacement.length = 11 * 4

                        If GetWindowPlacement(oMyWindow.hWnd, pPlacement) > 0 Then

                              pPlacement.showcmd = SW_RESTORE

                              SetWindowPlacement(oMyWindow.hWnd, pPlacement)

                        Else

                              Dim n = Marshal.GetLastWin32Error()

                              Console.WriteLine(n)

                        End If

                  End If

                  SetForegroundWindow(oMyWindow.hWnd)

            End Sub

      End Class

End Class

 

 

 

End of code