Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
620to624
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
620to624
620to624
Aktuelles Verzeichnis
Verzeichnis Index
Verzeichnis Index
Übersicht Verzeichnisse
Userform Schließen-Schaltfläche u. Fixieren
08.06.2005 21:16:05
Harry
Hallo Exelforum.
Ich hoffe ihr könnt mir weiterhelfen. Ich möchte die Schließen-Schaltfläche (X) einer Userform ausblenden und die Userform fixieren.
Ich habe mir für beides bereits den Code rausgesucht, ich bekomme es auch zum laufen, aber immer nur eins von beiden. Es soll aber beiden gehen.
hier der Code den ich habe:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal _
hwnd As Long) As Long
Private Const GWL_STYLE As Long = -16
Private Const WS_SYSMENU As Long = &H80000
Private hwndForm As Long
Private bCloseBtn As Boolean
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 Const MF_BYCOMMAND = &H0
Private Const SC_MOVE = &HF010
'############### So jetzt kommt das Problem #########################
Dim hwndForm As Long
Dim hwndMenu As Long
hwndForm = FindWindow(vbNullString, Me.Caption)
If hwndForm &lt&gt 0 Then
hwndMenu = GetSystemMenu(hwndForm, 0)
If hwndMenu &lt&gt 0 Then
DeleteMenu hwndMenu, SC_MOVE, MF_BYCOMMAND
End If
End If
---------------------------------------------------------
If Val(Application.Version) &gt= 9 Then
hwndForm = FindWindow("ThunderDFrame", Me.Caption)
Else
hwndForm = FindWindow("ThunderXFrame", Me.Caption)
End If
bCloseBtn = False
SetUserFormStyle
Benutze ich den Code so ist die Userform fixiert, aber das X ist da.
Setzt ich den unteren Block nach oben, dann ist das X weg, aber die Userform läßt sich verschieben.
Wie bekomme ich beiden zu laufen. ?
Harry

7
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Userform Schließen-Schaltfläche u. Fixieren
08.06.2005 21:31:26
Hajo_Zi
Hallo Harry,
shaue mal auf mein HP Seite Fremde Dateien.
Bitte keine Mail, Probleme sollten im Forum gelöst werden.
Microsoft MVP für Excel
Das Forum lebt auch von den Rückmeldungen.
Betriebssystem XP Home SP2 und Excel Version 2003 SP1.


AW: Userform Schließen-geht nicht
08.06.2005 22:06:22
Harry
Hallo Hajo,
Ich habe mir die Dateien von deiner Seite runtergeladen und versucht sie einzubauen.
Aber mit dem selben Ergebnis. (Sie sind auch nur jeweils für eine Funktion)
Ich bekomme immer nur eine Funktion zum laufen, aber nie beide !
Harry
AW: Userform Schließen-geht nicht
09.06.2005 05:59:43
Hajo_Zi
Hallo Harry,
also das glaube ich nicht. Im Beispiel
Beispieldatei
bekommst Du die Userform nicht verschoben.
Gruß Hajo
Das Forum lebt auch von den Rückmeldungen.
Anzeige
AW: Userform Schließen-Schaltfläche u. Fixieren
08.06.2005 21:41:02
Xelleron
Hallo Harry,
Code ist von Hajo´s Seite:
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As Long
Private Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long, ByVal dwNewLong As Long) As Long
Private Declare Function DrawMenuBar Lib "user32" (ByVal _
hwnd As Long) As Long
Private Const GWL_STYLE As Long = -16
Private Const WS_SYSMENU As Long = &H80000
Private hWndForm As Long
Private bCloseBtn As Boolean

Private Sub UserForm_Initialize()
If Val(Application.Version) >= 9 Then
hWndForm = FindWindow("ThunderDFrame", Me.Caption)
Else
hWndForm = FindWindow("ThunderXFrame", Me.Caption)
End If
bCloseBtn = False
SetUserFormStyle
End Sub


Private Sub SetUserFormStyle()
Dim frmStyle As Long
If hWndForm = 0 Then Exit Sub
frmStyle = GetWindowLong(hWndForm, GWL_STYLE)
If bCloseBtn Then
frmStyle = frmStyle Or WS_SYSMENU
Else
frmStyle = frmStyle And Not WS_SYSMENU
End If
SetWindowLong hWndForm, GWL_STYLE, frmStyle
DrawMenuBar hWndForm
End Sub


Private Sub optCloseOn_Click()
bCloseBtn = True
cmdBeenden.Cancel = True
SetUserFormStyle
End Sub


Private Sub optCloseOff_Click()
bCloseBtn = False
cmdBeenden.Cancel = False
SetUserFormStyle
End Sub


Private Sub UserForm_Layout()
Me.Move Application.Width / 2 - Me.Width / 2, Application.Height / 2 - Me.Height / 2
End Sub

Sollte so funzen
Gruß Dennis
Anzeige
AW: Userform Schließen-Schaltfläche u. Fixieren
08.06.2005 22:23:22
Harry
Hallo Dennis,
das funktioniert bei mir nicht ?

Private Sub UserForm_Layout()
Me.Move Application.Width / 2 - Me.Width / 2, Application.Height / 2 - Me.Height / 2
End Sub

Auch das Beispiel von Hajos Seite geht bei mir nicht ?
Harry
AW: Userform Schließen-Schaltfläche u. Fixieren
08.06.2005 23:39:14
Harry
Vielen Dank für eure Tips !
Bis bald.
Harry

300 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige