Results 1 to 2 of 2

Thread: [2005] AppBar Modification

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2007
    Location
    Iowa
    Posts
    298

    [2005] AppBar Modification

    So I found this code on the internet yesterday, and it works okay, but I'm wanting to run it on a second monitor and this is way over my head.

    Can anyone help me out with this? Any ideas where to start or any at all would be great.

    Thanks!!!

    Code:
    #Region " AppBar "
        <StructLayout(LayoutKind.Sequential)> Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
        End Structure
        <StructLayout(LayoutKind.Sequential)> 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
        Enum ABMsg
            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
        Enum ABNotify
            ABN_STATECHANGE = 0
            ABN_POSCHANGED
            ABN_FULLSCREENAPP
            ABN_WINDOWARRANGE
        End Enum
        Enum ABEdge
            ABE_LEFT = 0
            ABE_TOP
            ABE_RIGHT
            ABE_BOTTOM
        End Enum
        Private fBarRegistered As Boolean = False
        <DllImport("SHELL32", CallingConvention:=CallingConvention.StdCall)> _
        Public Shared Function SHAppBarMessage(ByVal dwMessage As Integer, ByRef BarrData As APPBARDATA) As Integer
        End Function
        <DllImport("USER32")> _
        Public Shared Function GetSystemmetric(ByVal Index As Integer) As Integer
        End Function
        <DllImport("User32.dll", ExactSpelling:=True, CharSet:=System.Runtime.InteropServices.CharSet.Auto)> _
        Public Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal cX As Integer, ByVal cY As Integer, ByVal repaint As Boolean) As Boolean
        End Function
        <DllImport("User32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function RegisterWindowMessage(ByVal msg As String) As Integer
        End Function
        Private uCallBack As Integer
    
        Private Sub RegisterBar()
            Dim abd As New APPBARDATA
            Dim ret As Integer
            abd.cbSize = Marshal.SizeOf(abd)
            abd.hWnd = Me.Handle
            If Not fBarRegistered Then
                uCallBack = RegisterWindowMessage("AppBarMessage")
                abd.uCallbackMessage = uCallBack
    
                ret = SHAppBarMessage(ABMsg.ABM_NEW, abd)
                fBarRegistered = True
    
                ABSetPos()
            Else
                ret = SHAppBarMessage(ABMsg.ABM_REMOVE, abd)
                fBarRegistered = False
            End If
        End Sub
    
        Private Sub ABSetPos()
            Dim abd As New APPBARDATA
            abd.cbSize = Marshal.SizeOf(abd)
            abd.hWnd = Me.Handle
            abd.uEdge = ABEdge.ABE_TOP
    
            If abd.uEdge = ABEdge.ABE_LEFT OrElse abd.uEdge = ABEdge.ABE_RIGHT Then
                abd.rc.top = 0
                abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
                If abd.uEdge = ABEdge.ABE_LEFT Then
                    abd.rc.left = 0
                    abd.rc.right = Size.Width
                Else
                    abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
                    abd.rc.left = abd.rc.right - Size.Width
                End If
            Else
                abd.rc.left = 0
                abd.rc.right = SystemInformation.PrimaryMonitorSize.Width
                If abd.uEdge = ABEdge.ABE_TOP Then
                    abd.rc.top = 0
                    abd.rc.bottom = Size.Height
                Else
                    abd.rc.bottom = SystemInformation.PrimaryMonitorSize.Height
                    abd.rc.top = abd.rc.bottom - Size.Height
                End If
            End If
    
            'Query the system for an approved size and position.
            SHAppBarMessage(ABMsg.ABM_QUERYPOS, abd)
    
            'Adjust the rectangle, depending on the edge to which the appbar is anchored.
            Select Case abd.uEdge
                Case ABEdge.ABE_LEFT
                    abd.rc.right = abd.rc.left + Size.Width
                Case ABEdge.ABE_RIGHT
                    abd.rc.left = abd.rc.right - Size.Width
                Case ABEdge.ABE_TOP
                    abd.rc.bottom = abd.rc.top + Size.Height
                Case ABEdge.ABE_BOTTOM
                    abd.rc.top = abd.rc.bottom - Size.Height
            End Select
    
            'Pass the final bounding rectangle to the system.
            SHAppBarMessage(ABMsg.ABM_SETPOS, abd)
    
            'Move and size the appbar so that it conforms to the  bounding rectangle passed to the system.
            MoveWindow(abd.hWnd, abd.rc.left, abd.rc.top, abd.rc.right - abd.rc.left, abd.rc.bottom - abd.rc.top, True)
        End Sub
    
    #End Region
    
    
      
        Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
            RegisterBar()
        End Sub
    
    
    
    
        Private Sub frmFrontDeskNetPhone_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            RegisterBar()
    End Sub
    FormBorderStyle = FixedToolWindow
    ControlBox = False
    WindowState = Maximized
    StartPosition = Manual
    Tuber

    "I don't know the rules"

  2. #2
    Frenzied Member HanneSThEGreaT's Avatar
    Join Date
    Nov 2003
    Location
    Vereeniging, South Africa
    Posts
    1,492

    Re: [2005] AppBar Modification

    I'd honestly not recommend setting an AppBar form to maximized, Normal would make more sence.

    Back to your question.

    In order to determine if we are dealing with multiple monitors, you'd need these APIs and constants :
    Code:
        Inherits System.Windows.Forms.Form
        Const CCDEVICENAME As Short = 32
        Const CCFORMNAME As Short = 32
        Const DM_BITSPERPEL = &H40000
        Const DM_PELSWIDTH = &H80000
        Const DM_PELSHEIGHT = &H100000
        Const CDS_UPDATEREGISTRY = &H1
    
        Const DISPLAY_DEVICE_ATTACHED_TO_DESKTOP = &H1 'Device that is part of desktop
        Const DISPLAY_PRIMARY_DEVICE = &H4 'Primary device
    
        'Holds the information of display adpter
        Private Structure DISPLAY_DEVICE
            Public cb As Integer
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
              Public DeviceName As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
              Public DeviceString As String
            Public StateFlags As Short
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
              Public DeviceID As String
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=128)> _
              Public DeviceKey As String
        End Structure
    
        'Holds the setting of display adapter
        Private Structure SetResolution
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCDEVICENAME)> _
            Public dmDeviceName As String
            Public dmSpecVersion As Short
            Public dmDriverVersion As Short
            Public dmSize As Short
            Public dmDriverExtra As Short
            Public dmFields As Integer
            Public dmOrientation As Short
            Public dmPaperSize As Short
            Public dmPaperLength As Short
            Public dmPaperWidth As Short
            Public dmScale As Short
            Public dmCopies As Short
            Public dmDefaultSource As Short
            Public dmPrintQuality As Short
            Public dmColor As Short
            Public dmDuplex As Short
            Public dmYResolution As Short
            Public dmTTOption As Short
            Public dmCollate As Short
    
            <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=CCFORMNAME)> _
            Public dmFormName As String
            Public dmLogPixels As Short
            Public dmBitsPerPel As Short
            Public dmPelsWidth As Integer
            Public dmPelsHeight As Integer
            Public dmDisplayFlags As Integer
            Public dmDisplayFrequency As Integer
            Public dmICMMethod As Integer
            Public dmICMIntent As Integer
            Public dmMediaType As Integer
            Public dmDitherType As Integer
            Public dmReserved1 As Integer
            Public dmReserved2 As Integer
            Public dmPanningWidth As Integer
            Public dmPanningHeight As Integer
        End Structure
    
        'API declaration set or get display adpter information
        <DllImport("user32.dll")> _
        Private Shared Function EnumDisplayDevices(ByVal Unused As Integer, _
        ByVal iDevNum As Short, ByRef lpDisplayDevice As DISPLAY_DEVICE, ByVal dwFlags As Integer) As Integer
        End Function
        <DllImport("user32.dll")> _
            Private Shared Function EnumDisplaySettings(ByVal lpszDeviceName As String, _
            ByVal iModeNum As Integer, ByRef lpDevMode As SetResolution) As Integer
        End Function
        <DllImport("user32.dll")> _
            Private Shared Function ChangeDisplaySettingsEx(ByVal lpszDeviceName As String, _
            ByRef lpDevMode As SetResolution, ByVal hWnd As Integer, ByVal dwFlags As Integer, _
            ByVal lParam As Integer) As Integer
        End Function
    That would give you a good start
    VB.NET MVP 2008 - Present

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width