[.NET] VB .NET 08 AppBar Problem

Dieses Thema im Forum "Programmierung & Entwicklung" wurde erstellt von Upperon, 12. Mai 2009 .

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 12. Mai 2009
    VB .NET 08 AppBar Problem

    Edit: Hab es hinbekommen. Ich musste nur zusätzlich eine kleine Zeitverzögerung einbauen bevor die AppBar in Position verschoben wird ^^ Denn das Erstellen der freien Fläche braucht anscheinend doch ein paar Millisekunden

    Also Closed

    Hi Leute

    Ich versuche gerade eine AppBar (zusätzliche Toolbar) in VB .NET 08 zu programmieren und stehe vor einem kleinen Rätsel.
    Das Programm reserviert den Platz für die neue AppBar, jedoch zeigt er sie dann irgendwo mitten aufm Bildschirm. Die Position ändert sich auch jedesmal ^^

    Hier mal mein Code:
    Code:
    Imports System.Runtime.InteropServices
    Public Class frmMain
     Private Sub frmMain_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
     RegisterBar(Me, ABEdge.ABE_TOP)
     End Sub
     Private Sub frmMain_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
     RegisterBar(Me)
     End Sub
    
    
     <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
    
     Public Sub RegisterBar(ByVal frm As Form, Optional ByVal dockEdge As ABEdge = ABEdge.ABE_TOP)
     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
    
    
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     End
     End Sub
    End Class
    
    Theoretisch dürfte es ja nur ein kleiner Fehler sein, aber ich sehe ihn einfach nicht.
    Wäre schön, wenn mir da ein Profi hier mal helfen könnte ?(*verzweifel*?(
     
  2. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.