Xtreme Visual Basic Talk

Xtreme Visual Basic Talk (http://www.xtremevbtalk.com/)
-   .NET Interface and Graphics (http://www.xtremevbtalk.com/-net-interface-and-graphics/)
-   -   Set Windows/Desktop working area (http://www.xtremevbtalk.com/-net-interface-and-graphics/327076-set-windows-desktop.html)

charlie 05-28-2014 07:20 AM

Set Windows/Desktop working area
 
1 Attachment(s)
Hi all!
It's been several years since I posted my last thread in this forum! Last time here I was with VB6 :) I've been following the .NET forum, but now it's time to ask the experts! ;)

Well, I'm making an application which will communicate with another one running in an IE. The current version of the application is AlwaysOnTop but users are complaining everyday because the app is "over" IE and "it disturbs the view". :whoops:

What I'm trying to achieve is the app keeps staying AlwaysOnTop (done!) and it will position on top of the desktop. The application is like a bar, like Windows Taskbar (a bit bigger). But the "thing" is: when this app is running, the available desktop area must be "fit" outside the app. I mean, the app is on top of the screen and IE and any other application/window, when it get meximized, must be "below" the app. I don't know if someone will understand what I'm trying to explain... I'm attaching an image (an image is worth 1000 words).

The point is: how to make my app to hace the same behavior as Windows Taskbar for maximizing other applications. Whan maximizing applications, they don't cover Windows Taskbar. That is what I want.

I've been looking for it but I don't know how to achieve this.
By the way, I'm using VB 2010.

Thank you very very much!

Goggy 06-03-2014 12:15 AM

Not perfect but a start
 
Code:

Public Class AppBar

        Inherits System.Windows.Forms.Form

        Private Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
        End Structure
        Private Structure APPBARDATA
            Public cbSize As Integer
            Public hWnd As IntPtr
            Public uCallbackMessage As Integer
            Public uEdge As Integer
            Public rc As RECT
            Public lParam As IntPtr
        End Structure
        Private Enum ABMsg As Integer
            ABM_NEW = 0
            ABM_REMOVE = 1
            ABM_QUERYPOS = 2
            ABM_SETPOS = 3
            ABM_GETSTATE = 4
            ABM_GETTASKBARPOS = 5
            ABM_ACTIVATE = 6
            ABM_GETAUTOHIDEBAR = 7
            ABM_SETAUTOHIDEBAR = 8
            ABM_WINDOWPOSCHANGED = 9
            ABM_SETSTATE = 10
        End Enum
        Private Enum ABNotify As Integer
            ABN_STATECHANGE = 0
            ABN_POSCHANGED
            ABN_FULLSCREENAPP
            ABN_WINDOWARRANGE
        End Enum
        Private Enum ABEdge As Integer
            ABE_LEFT = &H0
            ABE_TOP = &H1
            ABE_RIGHT = &H2
            ABE_BOTTOM = &H3
        End Enum

        Private Declare Function SHAppBarMessage Lib "shell32.dll" Alias "SHAppBarMessage" (ByVal dwMessage As Integer, <MarshalAs(UnmanagedType.Struct)> ByRef pData As APPBARDATA) As Integer
        Private Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Integer) As Integer
        Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Integer
        Private Declare Function GetCursorPos Lib "user32.dll" (ByRef lpPoint As Point) As Boolean

        Private BarIsRegistered As Boolean = False
        Private BarIsPinned As Boolean = False
        Private BarIsFocused As Boolean = False

        Private CallBack As Integer
        Private DockedEdge As ABEdge

        Private m_MinimumWindowSize As Integer = &HC8 ' System.Windows.Forms.SystemInformation.CaptionHeight + &H1F
        Private m_NormalWindowSize As Integer = &HC8
        Private m_DockedScreen As Integer = &H0

        Private Const WM_MOUSEHOVER As Integer = &H2A1
        Private Const WM_MOUSELEAVE As Integer = &H2A3

        Private Const CaptionButtonSize As Integer = &H18

        Private Event Focus_Changed(ByVal HasFocus As Boolean)

        ''' <summary>
        ''' Gets or sets the minimum size of the window.
        ''' </summary>
        ''' <value>
        ''' The minimum size of the window.
        ''' </value>
        Public Property MinimumWindowSize() As Integer
            Get
                Return m_MinimumWindowSize
            End Get
            Set(ByVal value As Integer)
                m_MinimumWindowSize = value
            End Set
        End Property
        ''' <summary>
        ''' Gets or sets the size of the normal window.
        ''' </summary>
        ''' <value>
        ''' The size of the normal window.
        ''' </value>
        Public Property NormalWindowSize() As Integer
            Get
                Return m_NormalWindowSize
            End Get
            Set(ByVal value As Integer)
                m_NormalWindowSize = value
            End Set
        End Property
        ''' <summary>
        ''' Gets or sets the docked screen.
        ''' </summary>
        ''' <value>
        ''' The docked screen.
        ''' </value>
        Public Property DockedScreen() As Integer
            Get
                Return m_DockedScreen
            End Get
            Set(ByVal value As Integer)
                m_DockedScreen = value
            End Set
        End Property
#Region "Form events"
        ''' <summary>
        ''' Raises the <see cref="E:System.Windows.Forms.Form.Closing" /> event.
        ''' </summary>
        ''' <param name="e">A <see cref="T:System.ComponentModel.CancelEventArgs" /> that contains the event data.</param>
        Protected Overrides Sub OnClosing(e As System.ComponentModel.CancelEventArgs)
            MyBase.OnClosing(e)
            RegisterBar()
        End Sub
        ''' <summary>
        ''' Raises the <see cref="E:System.Windows.Forms.Form.Load" /> event.
        ''' </summary>
        ''' <param name="e">An <see cref="T:System.EventArgs" /> that contains the event data.</param>
        Protected Overrides Sub OnLoad(e As System.EventArgs)
            MyBase.OnLoad(e)
            ' Set the priority to above normal to run the program in a nice speed.
            Threading.Thread.CurrentThread.Priority = Threading.ThreadPriority.AboveNormal
            DockedEdge = ABEdge.ABE_LEFT

            Select Case DockedEdge
                Case ABEdge.ABE_LEFT, ABEdge.ABE_RIGHT
                    Me.Width = m_NormalWindowSize
                Case Else
                    Me.Height = m_NormalWindowSize
            End Select

            RegisterBar()

            Me.Invalidate()
            Me.SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        End Sub
        ''' <summary>
        ''' Raises the <see cref="E:System.Windows.Forms.Form.ResizeEnd" /> event.
        ''' </summary>
        ''' <param name="e">A <see cref="T:System.EventArgs" /> that contains the event data.</param>
        Protected Overrides Sub OnResizeEnd(e As System.EventArgs)
            MyBase.OnResizeEnd(e)
            ABSetPos(DockedEdge)
        End Sub
        ''' <summary>
        ''' </summary>
        ''' <param name="m">The Windows <see cref="T:System.Windows.Forms.Message" /> to process.</param>
        Protected Overloads Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
            If m.Msg = CallBack Then
                Select Case m.WParam.ToInt32()
                    Case CInt(ABNotify.ABN_POSCHANGED)
                        ABSetPos(DockedEdge)
                        Exit Select
                End Select
            End If
            MyBase.WndProc(m)
        End Sub
#End Region
#Region "Application Bar Routines"
        ''' <summary>
        ''' Registers the bar.
        ''' </summary>
        Private Sub RegisterBar()
            Dim abd As New APPBARDATA

            abd.cbSize = Marshal.SizeOf(abd)
            abd.hWnd = Me.Handle

            If Not BarIsRegistered Then
                CallBack = RegisterWindowMessage("AppBarMessage")
                abd.uCallbackMessage = CallBack

                Dim ret As Integer = SHAppBarMessage(CType(ABMsg.ABM_NEW, Integer), abd)
                BarIsRegistered = True

                ABSetPos(DockedEdge)
            Else
                SHAppBarMessage(ABMsg.ABM_REMOVE, abd)
                BarIsRegistered = False
            End If
        End Sub
        ''' <summary>
        ''' Abs the set position.
        ''' </summary>
        ''' <param name="Edge">The edge.</param>
        Private Sub ABSetPos(ByRef Edge As ABEdge)
            Dim abd As New APPBARDATA()
            Dim Screen As Screen = Screen.AllScreens(DockedScreen)
            abd.cbSize = Marshal.SizeOf(abd)
            abd.hWnd = Me.Handle
            abd.uEdge = Edge

            If abd.uEdge = CInt(ABEdge.ABE_LEFT) OrElse abd.uEdge = CInt(ABEdge.ABE_RIGHT) Then
                abd.rc.top = Screen.Bounds.Top
                abd.rc.bottom = Screen.WorkingArea.Height
                If abd.uEdge = CInt(ABEdge.ABE_LEFT) Then
                    abd.rc.left = Screen.Bounds.Left
                    abd.rc.right = m_MinimumWindowSize
                Else
                    abd.rc.right = Screen.WorkingArea.Width
                    abd.rc.left = abd.rc.right - m_MinimumWindowSize
                End If
            Else
                abd.rc.left = Screen.Bounds.Left
                abd.rc.right = Screen.WorkingArea.Width
                If abd.uEdge = CInt(ABEdge.ABE_TOP) Then
                    abd.rc.top = Screen.Bounds.Top
                    abd.rc.bottom = Me.Size.Height
                Else
                    abd.rc.bottom = Screen.WorkingArea.Height
                    abd.rc.top = abd.rc.bottom - Me.Size.Height
                End If
            End If
            ' Query the system for an approved size and position.
            SHAppBarMessage(CInt(ABMsg.ABM_QUERYPOS), abd)
            ' Adjust the rectangle, depending on the edge to which the
            ' appbar is anchored.
            Select Case abd.uEdge
                Case CInt(ABEdge.ABE_LEFT)
                    abd.rc.right = abd.rc.left
                Case CInt(ABEdge.ABE_RIGHT)
                    abd.rc.left = abd.rc.right
                Case CInt(ABEdge.ABE_TOP)
                    abd.rc.bottom = abd.rc.top
                Case CInt(ABEdge.ABE_BOTTOM)
                    abd.rc.top = abd.rc.bottom
            End Select
            ' Pass the final bounding rectangle to the system.
            SHAppBarMessage(CInt(ABMsg.ABM_SETPOS), abd)
            ' Move and size the appbar so that it conforms to the
            ' bounding rectangle passed to the system.
            MoveWindow(abd.hWnd.ToInt32, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, 1)
        End Sub
#End Region
    End Class


charlie 06-03-2014 01:23 AM

Thanks Googy!! It worked! :)


All times are GMT -6. The time now is 11:34 AM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Optimisation provided by DragonByte SEO v2.0.15 (Lite) - vBulletin Mods & Addons Copyright © 2017 DragonByte Technologies Ltd.
All site content is protected by the Digital Millenium Act of 1998. Copyright©2001-2011 MAS Media Inc. and Extreme Visual Basic Forum. All rights reserved.
You may not copy or reproduce any portion of this site without written consent.