Live-Forum - Die aktuellen Beiträge
Datum
Titel
28.03.2024 21:12:36
28.03.2024 18:31:49
Anzeige
Archiv - Navigation
1044to1048
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

UF an rechten Bildschirmrand andocken?

UF an rechten Bildschirmrand andocken?
31.01.2009 14:21:44
Michael
Hallo Miteinander!
Hat schon mal jemand derartiges versucht? Ich möchte die UF quasi wie eine TaskPane nutzen. Nur außerhalb von Excel und abwärtskompatibel. Wie könnte ich also die Werte des Randes ermitteln?
Danke für Eure Hilfe.
Gruß
Michael

10
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: UF an rechten Bildschirmrand andocken?
31.01.2009 14:41:00
Nepumuk
Hallo Michael,
so:
Option Explicit

Private Declare Function GetSystemMetrics Lib "user32.dll" ( _
    ByVal nIndex As Long) As Long

Private Const SM_CXSCREEN = 0&

Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    With Me
        .StartUpPosition = 0
        .Top = 0
        .Left = GetSystemMetrics(SM_CXSCREEN) * 0.75 - .Width
    End With
End Sub

Gruß
Nepumuk
Anzeige
oder so...
31.01.2009 15:18:00
Tino
Hallo,
, damit Du diese nicht mehr verschieben kannst.
Option Explicit

Private Declare Function FindWindow Lib "user32" Alias _
      "FindWindowA" (ByVal lpClassName As String, ByVal _
      lpWindowName As String) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal _
      hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function DeleteMenu Lib "user32" (ByVal _
      hMenu As Long, ByVal nPosition As Long, ByVal wFlags _
      As Long) As Long

Private Declare Function GetSystemMetrics Lib "user32.dll" ( _
    ByVal nIndex As Long) As Long

Private Const SM_CXSCREEN = 0&
Private Const MF_BYCOMMAND = &H0
Private Const SC_MOVE = &HF010

Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
  Dim hwndForm As Long
  Dim hwndMenu As Long

    hwndForm = FindWindow(vbNullString, Me.Caption)
    hwndMenu = GetSystemMenu(hwndForm, 0)
    DeleteMenu hwndMenu, SC_MOVE, MF_BYCOMMAND

    With Me
        .StartUpPosition = 0
        .Top = 0
        .Left = GetSystemMetrics(SM_CXSCREEN) * 0.75 - .Width
    End With
End Sub


Gruß Tino

Anzeige
cool!
31.01.2009 19:23:00
Michael
Danke Euch Beiden! Werde ich ausprobieren.
Könnt Ihr mir bitte noch verraten, wo ich derartiges nachlesen kann? Das ist bestimmt nicht in der Excel- bzw. VBA-Literatur zu finden.
Gruß
Michael
Die Länge noch!
31.01.2009 19:27:51
Michael
Ach, habe ich noch vergessen! Die UF sollte je nach Bilschirmauflösung in der Länge angepasst sein. Geht da dann
.top = GetSystemMetrics(SM_CXSCREEN) * 0.75 - .length ?
Gruß
Michael
AW: Die Länge noch!
31.01.2009 20:06:00
Tino
Hallo,
in erster Linie über Google, da gibt es schlauerer Leute wie mich. ;-)
Mit etwas Geduld und einer gewissen Hartnäckigkeit, findet man fasst alles.
Naja mansche Sachen nur für VB5 oder 6, aber dies kann man recht leicht auf Excel umstricken.
Hier noch ein Beispiel für die Höhe, es wird die Größe der Task bar berücksichtigt.
Bei mir hat es funktioniert, kannst ja mal testen.
Option Explicit


Private Declare Function FindWindow Lib "user32" Alias _
      "FindWindowA" (ByVal lpClassName As String, ByVal _
      lpWindowName As String) As Long

Private Declare Function GetSystemMenu Lib "user32" (ByVal _
      hwnd As Long, ByVal bRevert As Long) As Long

Private Declare Function DeleteMenu Lib "user32" (ByVal _
      hMenu As Long, ByVal nPosition As Long, ByVal wFlags _
      As Long) As Long

Private Declare Function GetSystemMetrics Lib "user32.dll" ( _
    ByVal nIndex As Long) As Long
                 
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, _
                                                         lpRect As xRECT) As Long

Private Type xRECT                       ' Datentyp Rechteck (Koordinaten) 
     rX1 As Long                         ' links 
     rY1 As Long                         ' oben 
     rX2 As Long                         ' rechts 
     rY2 As Long                         ' unten 
End Type


Private Const SM_CXSCREEN = 0&
Private Const MF_BYCOMMAND = &H0
Private Const SC_MOVE = &HF010

Private Sub CommandButton1_Click()
    Unload Me
End Sub

Private Sub UserForm_Initialize()
    Dim hRect As xRECT
    Dim hwnd As Long, hRes As Long, hwndForm As Long, hwndMenu As Long
 
    hwnd = FindWindow("Shell_traywnd", "")                  ' Handle TBarWindow ermitteln 
    hRes = GetWindowRect(hwnd, hRect)

    hwndForm = FindWindow(vbNullString, Me.Caption)
    hwndMenu = GetSystemMenu(hwndForm, 0)
    DeleteMenu hwndMenu, SC_MOVE, MF_BYCOMMAND

    With Me
        .StartUpPosition = 0
        .Top = 0
        .Left = GetSystemMetrics(SM_CXSCREEN) * 0.75 - .Width
        .Height = hRect.rY1 * 0.75
    End With
End Sub


Gruß Tino

Anzeige
AW: Die Länge noch!
31.01.2009 20:36:00
Michael
Funktiniert! Ich danke vielmals! (Hutzieh)
Gruß
Michael
Vereinheitlichen
01.02.2009 11:36:48
Michael
Hallo Ihr Beiden!
Hat super funktioniert!!! Und ich bin echt begeistert!. Jetzt noch ein Frage zur Optik, also um das schön zu machen: Wie kann ich noch das Excel Fenster anpassen? Also es soll sich an der UF orientieren. NormalState, Links angedockt, Top und Bottom wie UF, rechter Rand 2 Pixel neben UF. Das gibt ein schönes einheitliches Erscheinungsbild. Habt Ihr da noch eine Idee?
Danke vielmals.
Michael
vielleicht so
01.02.2009 11:53:11
Tino
Hallo,
teste mal.
Dialog UserForm1
Option Explicit 
 
Private Declare Function FindWindow Lib "user32" Alias _
      "FindWindowA" (ByVal lpClassName As String, ByVal _
      lpWindowName As String) As Long 
 
Private Declare Function GetSystemMenu Lib "user32" (ByVal _
      hwnd As Long, ByVal bRevert As Long) As Long 
 
Private Declare Function DeleteMenu Lib "user32" (ByVal _
      hMenu As Long, ByVal nPosition As Long, ByVal wFlags _
      As Long) As Long 
 
Private Declare Function GetSystemMetrics Lib "user32.dll" ( _
    ByVal nIndex As Long) As Long 
                  
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, _
                                                         lpRect As xRECT) As Long 
 
Private Type xRECT                       ' Datentyp Rechteck (Koordinaten) 
     rX1 As Long                         ' links 
     rY1 As Long                         ' oben 
     rX2 As Long                         ' rechts 
     rY2 As Long                         ' unten 
End Type 
 
 
Private Const SM_CXSCREEN = 0& 
Private Const MF_BYCOMMAND = &H0 
Private Const SC_MOVE = &HF010 
 
Private Sub CommandButton1_Click() 
    Unload Me 
End Sub 
 
Private Sub UserForm_Initialize() 
    Dim hRect As xRECT 
    Dim hwnd As Long, hwndForm As Long, hwndMenu As Long 
  
    hwnd = FindWindow("Shell_traywnd", "")                  ' Handle TBarWindow ermitteln 
    GetWindowRect hwnd, hRect 
 
    hwndForm = FindWindow(vbNullString, Me.Caption) 
    hwndMenu = GetSystemMenu(hwndForm, 0) 
    DeleteMenu hwndMenu, SC_MOVE, MF_BYCOMMAND 
 
    With Me 
        .StartUpPosition = 0 
        .Top = 0 
        .Left = GetSystemMetrics(SM_CXSCREEN) * 0.75 - .Width 
        .Height = hRect.rY1 * 0.75 
        Application.WindowState = xlNormal 
        Application.Left = 0: Application.Top = 0: Application.Height = hRect.rY1 * 0.75 
        Application.Width = GetSystemMetrics(SM_CXSCREEN) * 0.75 - .Width 
    End With 
 
 
End Sub 
 
Private Sub UserForm_Terminate() 
 Application.WindowState = xlMaximized 
End Sub 


Gruß Tino

Anzeige
AW: vielleicht so
01.02.2009 20:03:09
Michael
Das ist richtig super!
Danke nochmal
Michael
danke für die Rückmeldung oT.
01.02.2009 20:39:48
Tino

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige