Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1876to1880
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
Abfrage 32 oder 64 Bit
18.04.2022 16:38:05
Tony
Hallo meine Lieben,
ich stehe grad vor einem Problem. Vor einiger Zeit bin ich hier fündig geworden bei dem Thema Inaktivitätschliessung. Dabei habe ich einen guten Code gefunden und diesen für mich abgeändert. Das funktioniert auch alles bei mir super, aber sobald ich dies auf dem Firmen PC's teste fällt sofort ein Problem auf. Ich selbst habe offensichtlich die 32Bit Office Version und in der Firma haben wir die 64Bit Version. Nun sollte ich eine Abfrage einfliessen lassen die des klärt und das ganze so abändern das es am Ende bei beiden Version reibungslos funktioniert.
Vielleicht hat jemand ja ne einfache Idee wie ich das lösen kann.

Option Explicit
Dim NotClose As Boolean
Dim t1 As Single, t2 As Single
Dim nForeColor As Long
Dim nBackColor As Long
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 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
Private Const GWL_STYLE = -&H10
Private Const WS_SYSMENU = &H80000
Const SWP_NOMOVE = 2
Const SWP_NOSIZE = 1
Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Const HWND_TOPMOST = -1
Const HWND_NOTOPMOST = -2
Const Warten = 15
'von GraFri auf www.herber.de
Sub FensterPosition(ByVal strTitel As String, Modus As Boolean)
Dim lngRet As Long
Dim hwnd As Long
hwnd = FindWindow(vbNullString, strTitel)
If hwnd = 0 Then
MsgBox "Fenster wurde nicht gefunden!"
Exit Sub
End If
If Modus = True Then
lngRet = SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, _
FLAGS)
Else
lngRet = SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, _
FLAGS)
End If
End Sub
Private Sub UserForm_Initialize()
If ThisWorkbook.Saved Then
CommandButton2.Caption = "Jetzt schließen" '& vbLf & "(Datei ist gespeichert)"
Else
CommandButton2.Caption = "Jetzt schließen"
End If
'Standartfabe des Buttons wird genutzt
nForeColor = NichtSchliessen.ForeColor
nBackColor = NichtSchliessen.BackColor
'Standartfabe des Buttons wird genutzt
nForeColor = CommandButton2.ForeColor
nBackColor = CommandButton2.BackColor
End Sub
Private Sub CommandButton2_Click()
NotClose = False
t2 = Timer
End Sub
Private Sub UserForm_Activate()
Dim lHwnd As Long
lHwnd = FindWindow("ThunderDFrame", Me.Caption)
FensterPosition Me.Caption, True
SetWindowLong lHwnd, HWND_TOPMOST, GetWindowLong(lHwnd, GWL_STYLE) And Not WS_SYSMENU
DrawMenuBar lHwnd
End Sub
Function Abbruch() As Boolean
t1 = Timer
t2 = Timer + Warten
On Error Resume Next
Me.Show vbModeless
If ERR.Number = 0 Then
Do
Label1.Caption = "Die Ersatzteile werden in " & Warten - Int(Timer - t1) & " Sekunden" & vbLf & "geschlossen..."
DoEvents
Loop Until Timer > t2
End If
Abbruch = NotClose
Unload Me
End Function
Private Sub NichtSchliessen_Click()
NotClose = True
t2 = Timer
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = 0 Then Cancel = True
End Sub
Private Sub NichtSchliessen_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Farbe des Buttons wird gewechselt
NichtSchliessen.ForeColor = RGB(255, 255, 255)
NichtSchliessen.BackColor = RGB(255, 128, 0)
End Sub
Private Sub Label2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Farbe des Buttons wird gewechselt
NichtSchliessen.ForeColor = nForeColor
NichtSchliessen.BackColor = nBackColor
End Sub
Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Farbe des Buttons wird gewechselt
CommandButton2.ForeColor = RGB(255, 255, 255)
CommandButton2.BackColor = RGB(255, 128, 0)
End Sub
Private Sub Label3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'Farbe des Buttons wird gewechselt
CommandButton2.ForeColor = nForeColor
CommandButton2.BackColor = nBackColor
End Sub

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

Betreff
Datum
Anwender
Anzeige
AW: Abfrage 32 oder 64 Bit
18.04.2022 17:54:12
volti
Hallo Tony,
so sollte es funktionieren (ungetestet).
Bitte beachten: Neben den ergänzten und geänderten Declares muss die hWnd-Variable als LongPtr ausgewiesen werden. Deshalb habe ich sie der Einfachheit halber außerhalb der Subs definiert. Die lngRetval wird nicht benötigt.
Code:


Option Explicit Dim NotClose As Boolean Dim t1 As Single, t2 As Single Dim nForeColor As Long Dim nBackColor As Long #If Win64 Then Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" ( _ ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" ( _ ByVal hwnd As LongPtr, ByVal nIndex As Long, _ ByVal dwNewLong As LongPtr) As LongPtr Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias "GetWindowLongPtrA" ( _ ByVal hwnd As LongPtr, ByVal nIndex As Long) As LongPtr Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal hwnd As LongPtr) As Long Private Declare PtrSafe Function SetWindowPos Lib "user32" ( _ ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, _ ByVal x As Long, ByVal y As Long, _ ByVal cx As Long, ByVal cy As Long, _ ByVal wFlags As Long) As Long Dim hwnd As LongPtr #Else 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 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 Dim hwnd As Long #End If Private Const GWL_STYLE = -&H10 Private Const WS_SYSMENU = &H80000 Const SWP_NOMOVE = 2 Const SWP_NOSIZE = 1 Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE Const HWND_TOPMOST = -1 Const HWND_NOTOPMOST = -2 Const Warten = 15 'von GraFri auf www.herber.de Sub FensterPosition(ByVal strTitel As String, Modus As Boolean) hwnd = FindWindow(vbNullString, strTitel) If hwnd = 0 Then MsgBox "Fenster wurde nicht gefunden!" Exit Sub End If If Modus = True Then SetWindowPos hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS Else SetWindowPos hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS End If End Sub Private Sub UserForm_Initialize() If ThisWorkbook.Saved Then CommandButton2.Caption = "Jetzt schließen" '& vbLf & "(Datei ist gespeichert)" Else CommandButton2.Caption = "Jetzt schließen" End If 'Standartfabe des Buttons wird genutzt nForeColor = NichtSchliessen.ForeColor nBackColor = NichtSchliessen.BackColor 'Standartfabe des Buttons wird genutzt nForeColor = CommandButton2.ForeColor nBackColor = CommandButton2.BackColor End Sub Private Sub CommandButton2_Click() NotClose = False t2 = Timer End Sub Private Sub UserForm_Activate() hwnd = FindWindow("ThunderDFrame", Me.Caption) FensterPosition Me.Caption, True SetWindowLong hwnd, HWND_TOPMOST, GetWindowLong(hwnd, GWL_STYLE) And Not WS_SYSMENU DrawMenuBar hwnd End Sub Function Abbruch() As Boolean t1 = Timer t2 = Timer + Warten On Error Resume Next Me.Show vbModeless If Err.Number = 0 Then Do Label1.Caption = "Die Ersatzteile werden in " & Warten - Int(Timer - t1) & " Sekunden" & vbLf & "geschlossen..." DoEvents Loop Until Timer > t2 End If Abbruch = NotClose Unload Me End Function Private Sub NichtSchliessen_Click() NotClose = True t2 = Timer End Sub Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) If CloseMode = 0 Then Cancel = True End Sub Private Sub NichtSchliessen_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) 'Farbe des Buttons wird gewechselt NichtSchliessen.ForeColor = RGB(255, 255, 255) NichtSchliessen.BackColor = RGB(255, 128, 0) End Sub Private Sub Label2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) 'Farbe des Buttons wird gewechselt NichtSchliessen.ForeColor = nForeColor NichtSchliessen.BackColor = nBackColor End Sub Private Sub CommandButton2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) 'Farbe des Buttons wird gewechselt CommandButton2.ForeColor = RGB(255, 255, 255) CommandButton2.BackColor = RGB(255, 128, 0) End Sub Private Sub Label3_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal x As Single, ByVal y As Single) 'Farbe des Buttons wird gewechselt CommandButton2.ForeColor = nForeColor CommandButton2.BackColor = nBackColor End Sub

_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz

Anzeige
AW: Abfrage 32 oder 64 Bit
18.04.2022 18:38:08
Tony
Hallo Karl-Heinz
Merci für die schnelle Antwort. Ein kurzer Test auf beiden System hat super funktioniert.
Nun muss ich schauen was du genau alles gemacht hast und dann sollte ich es auch verstehen, (Hausaufgaben braucht der Mensch) da ich grade gesehen habe das ich dieses Problem schon bald wieder haben werde und dann will ich das ja alleine Lösen :)
LG und einen schönen Abend
Tony
AW: Abfrage 32 oder 64 Bit
18.04.2022 18:50:27
volti
Hallo Tony,
gerne und vielen Dank für die Rückmeldung.
Für häufige Fälle ist (m)ein PI-Viewer hilfreich....
Hier die AddIn-Version. Kannst ja mal reinschauen.
API-Viewer.zip
Gruß
KH
Anzeige
AW: Abfrage 32 oder 64 Bit
18.04.2022 19:17:59
Tony
Merci für die Datei, aber leider ist der VBA Teil mit einem Passwort versehen und dadurch kann ich leider nichts anschauen.
LG Tony
AW: Abfrage 32 oder 64 Bit
18.04.2022 19:23:54
volti
Hallo Tony,
die Datei ist auch nicht zum Code anschauen, sondern zum "Mit arbeiten", gedacht. Hier kannst Du Dir die Declares für mehrere tausend Subs, Funktionen, Konstanten und TYPEs für 32 und 64 Bit anschauen und zusammen stellen. Außerdem habe ich auch gleich eine Google-Suche mit eingebaut.
Ggf. habe ich auch eine XLS-Version, aber eigentlich arbeite ich immer mit dem AddIn.
Gruß
Karl-Heinz
AW: Abfrage 32 oder 64 Bit
18.04.2022 20:20:22
Tony
Merci für die Info.
Jetzt habe ich mich grade mit dem gleichen Problem bei der Ausblendung des X in der Userform versucht. Leider habe ich es nicht hinbekommen. Daher stelle ich hier mal den Code rein der bei mir (32er Version) funktioniert. Vielleicht kannst du mir auch hier helfen.

Option Explicit
'X in Userform ausblenden
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
'X in Userform ausblenden
Private Sub UserForm_Initialize()
'Username Laden
TextBox_User = A_Startseite.Cells(2, 4)
'X in der Userform ausblenden
If Val(Application.Version) >= 9 Then
hWndForm = FindWindow("ThunderDFrame", Me.Caption)
Else
hWndForm = FindWindow("ThunderXFrame", Me.Caption)
End If
bCloseBtn = False
SetUserFormStyle
'Timer starten
Call Timer_Begruessung_Start
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
'Timer Beenden
If CloseMode = vbFormControlMenu Then Call Timer_Begruessung_Ende
End Sub
Private Sub CommandButton1_Click()
' Userform Schliessen
Unload Begruessung
End Sub
'X in Userform ausblenden
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
'X in Userform ausblenden
Merci und LG
Tony
Anzeige
AW: Abfrage 32 oder 64 Bit
18.04.2022 20:46:38
Tony
Hab das ganze nochmal anders probiert und zack es geht :)
Trotzdem Merci
AW: Abfrage 32 oder 64 Bit
18.04.2022 19:13:44
volti
Hi,
es ist noch ein Kopierfehler drin gewesen. (Auch wenn es jetzt schon funktioniert), muss es im 64-Bereich so heißen....

Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongPtrA" ( _
ByVal hwnd As LongPtr, ByVal nIndex As Long, _
ByVal dwNewLong As LongPtr) As LongPtr

Gruß
KH
AW: Abfrage 32 oder 64 Bit
18.04.2022 17:54:59
Sulprobil
Hallo,
Ruf' einfach das Logging unter http://www.sulprobil.com/logging_en/ auf (ohne jegliche Gewährleistung, aber ich verwende einen aktuellen Virenscanner), schau' in die erzeugte Logdatei im Untervezeichnis Logs und kopiere dann den Code, der das erzeugt, was Dir in der Ausgabe gefällt.
Viele Grüße,
Bernd
Anzeige
AW: Abfrage 32 oder 64 Bit
18.04.2022 18:40:27
Tony
Hoi Bernd
Merci für deinen Tipp. Vielleicht ist dieser zu einem späteren Zeitpunkt mal noch nützlich. ;)
LG und einen schönen Abend
Tony

305 Forumthreads zu ähnlichen Themen

Anzeige
Anzeige
Anzeige

Links zu Excel-Dialogen

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige