vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Schützen Sie Ihre Software vor Software-Piraterie - mit sevLock 1.0 DLL!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Suche Visual-Basic Code
MS kann das, und wir können das schon längst! 
Autor: Tolwyn
Datum: 29.08.01 18:09

.... Naja seit etwa 10 Minuten

Das geht mit der netten API Funktion "SHAppBarMessage" der Shell32Lib.
Damit kann eine Application Bar erstellt werden, die alles hat was man braucht.

Vorbereitung:

1. Den unten aufgeführten Code in ein Neues Modul kopieren.
2. Ein Form anlegen mit dem Namen „frmAppBar“.
3. Auf diesem Form in der linken oberen Ecke ein Steuerelement plazieren, welches die Mindesthöhe bzw. –breite der AppBar vorgibt.
4. Einen Button in der linken oberen Ecke des Forms plazieren, welcher die Funktion „UnloadAppBar“ aufruft. (WICHTIG!!!)
5. Das Startobjekt des Projektes auf "Sub Main" stellen.
6. Mit F5 starten und schauen was passiert...

Option Explicit
 
' API Deklarationen
Private Declare Function SHAppBarMessage Lib "Shell32.dll" (ByVal _
        dwMessage As Long, pData As APPBARDATA) As Long
 
Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd _
        As Long, ByVal hwndInsertAfter As Long, ByVal X As Long, _
        ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, _
        ByVal wFlags As Long) As Long
 
' Types für die API
Private Type RECT
  Left      As Long
  Top       As Long
  Right     As Long
  Bottom    As Long
End Type
 
Private Type APPBARDATA
  cbSize            As Long
  hwnd              As Long
  uCallbackMessage  As Long
  uEdge             As Long
  rc                As RECT
  lParam            As Long
End Type
' Konstanten für die API
Private Const HWND_TOPMOST = -1
 
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOMOVE = &H2
Private Const SWP_SHOWWINDOW = &H40
 
Private Const ABM_NEW = &H0
Private Const ABM_REMOVE = &H1
Private Const ABM_SETPOS = &H3
Private Const ABM_GETTASKBARPOS = &H5
 
Public Const ABE_LEFT = &H0
Public Const ABE_TOP = &H1
Public Const ABE_RIGHT = &H2
Public Const ABE_BOTTOM = &H3
 
' Enum der Docking Positionen
Public Enum AppBarPos
  BarLeft = 0
  BarTop = 1
  BarRight = 2
  BarBottom = 3
End Enum
 
' Anwendungsvariablen
Public frmAppForm           As Form
Public bDocked              As Boolean
Private lBorder             As Long
' AppBar Informationen
Private APD                 As APPBARDATA
 
Private lDockMode           As Long
Private lXTwips             As Long
Private lYTwips             As Long
 
Sub Main()
  lXTwips = Screen.TwipsPerPixelX
  lYTwips = Screen.TwipsPerPixelY
  lBorder = 0
  LoadAppBar frmAppBar, BarRight
End Sub
 
Public Sub LoadAppBar(AppForm As Form, Position As AppBarPos)
  Dim lTop, lBottom     As Long
  Dim lLeft, lRight     As Long
  Dim lWidth, lHeight   As Long
  Dim lMinSize          As Long ' minimale Höhe oder Breite der Bar in Pixel
  Dim WTBPos            As APPBARDATA
 
  lDockMode = Position
  Set frmAppForm = AppForm
  bDocked = True
 
  ' Neue AppBar anlegen
  Call SHAppBarMessage(ABM_NEW, APD)
  ' Je nach Position die Variablen füllen
  Select Case lDockMode
    Case ABE_LEFT
      lMinSize = frmAppForm.fraBack.Width / lYTwips
      lLeft = 0
      lTop = 0
      lRight = lMinSize + lBorder
      lBottom = Screen.Height
      lWidth = lMinSize * lXTwips
      lHeight = Screen.Height
 
    Case ABE_TOP
      lMinSize = frmAppForm.fraBack.Height / lXTwips
      lLeft = 0
      lTop = 0
      lRight = Screen.Width / lXTwips
      lBottom = lMinSize + lBorder
      lWidth = Screen.Width
      lHeight = lMinSize * lYTwips
 
    Case ABE_RIGHT
      lMinSize = frmAppForm.fraBack.Width / lYTwips
      lLeft = Screen.Width / lXTwips - lMinSize - lBorder
      lTop = 0
      lRight = Screen.Width / lXTwips
      lBottom = lMinSize + lBorder
      lWidth = lMinSize * lXTwips
      lHeight = Screen.Height
 
    Case ABE_BOTTOM
      lMinSize = frmAppForm.fraBack.Height / lXTwips
      lLeft = 0
      lTop = Screen.Height / lXTwips - lMinSize - lBorder
      lRight = Screen.Width / lXTwips
      lBottom = Screen.Height / lXTwips
      lWidth = Screen.Width
      lHeight = (lBottom - lTop) * lYTwips
    End Select
    '--------------------------------------------------
    'Nun noch die Windows Taskbar berücksichtigen
    Call SHAppBarMessage(ABM_GETTASKBARPOS, WTBPos)
    '--------------------------------------------------
    ' Taskbar unten
    If WTBPos.uEdge = ABE_BOTTOM And lDockMode = ABE_BOTTOM Then
      lTop = WTBPos.rc.Top - lMinSize - lBorder
      lBottom = WTBPos.rc.Bottom
    ElseIf WTBPos.uEdge = ABE_BOTTOM And _
           (lDockMode = ABE_LEFT Or lDockMode = ABE_RIGHT) Then
      lHeight = WTBPos.rc.Top * lYTwips
    '--------------------------------------------------
    ' Taskbar oben
    ElseIf WTBPos.uEdge = ABE_TOP And lDockMode = ABE_TOP Then
      lTop = WTBPos.rc.Bottom
      lBottom = lTop + lMinSize
    ElseIf WTBPos.uEdge = ABE_TOP And _
           (lDockMode = ABE_LEFT Or lDockMode = ABE_RIGHT) Then
      lTop = WTBPos.rc.Bottom
      lHeight = Screen.Height - WTBPos.rc.Bottom * lYTwips
    '--------------------------------------------------
    ' Taskbar links
    ElseIf WTBPos.uEdge = ABE_LEFT And lDockMode = ABE_LEFT Then
      lLeft = WTBPos.rc.Right
    ElseIf WTBPos.uEdge = ABE_LEFT And _
           (lDockMode = ABE_TOP Or lDockMode = ABE_BOTTOM) Then
      lLeft = WTBPos.rc.Right
      lWidth = Screen.Width - WTBPos.rc.Right * lYTwips
    '--------------------------------------------------
    ' Taskbar rechts
    ElseIf WTBPos.uEdge = ABE_RIGHT And lDockMode = ABE_RIGHT Then
      lLeft = WTBPos.rc.Left - lMinSize
    ElseIf WTBPos.uEdge = ABE_RIGHT And _
           (lDockMode = ABE_TOP Or lDockMode = ABE_BOTTOM) Then
      lWidth = WTBPos.rc.Left * lYTwips
    End If
 
    ' AppData Objekt für die ApplicationBar füllen
    With APD
      .uEdge = lDockMode
      .rc.Top = lTop
      .rc.Left = lLeft
      .rc.Right = lRight
      .rc.Bottom = lBottom
    End With
 
    ' AppBar mit den neuen Werten füllen
    Call SHAppBarMessage(ABM_SETPOS, APD)
 
    ' Nun das Form an die Position der AppBar bringen
    DoEvents
    With frmAppForm
      .Show
      Call SetWindowPos(.hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_SHOWWINDOW)
      .Top = lTop * lXTwips
      .Left = lLeft * lYTwips
      .Width = lWidth
      .Height = lHeight
    End With
End Sub
 
Public Sub UnloadAppBar()
  If bDocked Then Call SHAppBarMessage(ABM_REMOVE, APD)
  bDocked = False
End Sub
LoadAppBar erwartet als Übergabe ein Form, welches als AppBar fungieren soll und die Position (BarLeft, BarTop, BarRight oder BarBottom)

Gruß
Tolwyn
PS Kann ich den Kopf aus der MSDN nun wieder rausnehmen ?
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Was für Profis...122MoD28.08.01 23:25
Re: Was für Profis...313unbekannt29.08.01 02:32
Re: Was für Profis...78MoD29.08.01 10:37
MS kann das, und wir können das schon längst!104Tolwyn29.08.01 18:09
Super Thomas ein kleiner Hinweis:271unbekannt29.08.01 19:59
Re: Super Thomas ein kleiner Hinweis:77MoD29.08.01 22:02
Fein Und da sag noch mal wer MSDN würde nix bringen (ot)69Tolwyn30.08.01 01:20

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel